By kleung - Tue Nov 02, 2021 8:43 pm
- Tue Nov 02, 2021 8:43 pm
#829595
Hi,
I need to
1) disable some of the cells in a row of the grid when the <trash> button of the row is clicked, and
2) hide the <trash> button
in a dynaform.
The enclosed javascript program is written for such purpose.
My problem is when the <trash> button is clicked, not only the cells to be disabled CANNOT be disabled, but also ALL the disabled cells in the dynaform are enabled!
I have tested with disabling either the hide <trash> button statement or the for loop on disabling cells, the same problem presist disregard of which statement I disabled.
Grateful if I can have your advice in fixing the bug.
Thousand Thanks.
cheers,
Karl
// -------- javascript to disable some grid cells instead of delete row on <trash> button is clicked --------
function onDelRow(e) {
var rowNo = $(this).attr("data-row");
var gdIdThisNm = e.data.param1;
var ColNoLst = e.data.param2;
var jgd = $('#'+gdIdThisNm);
// // --- hide <del>
$(jgd.find("div.pmdynaform-grid-row")[rowNo-1]).find("button").hide();
// // disable fields
for (i in ColNoLst){
jgd.getControl(rowNo, ColNoLst).attr("disabled", true);
}; // end for
}; // end onDelRow(e)
// ---- gdOnLoad ------
function gdOnLoad(gdId, ColNoDisableLst){
var jgd = $('#' + gdId);
var gdLen = jgd.getNumberRows();
ColNoLst = ColNoDisableLst;
if (gdLen > 0){
//turn off the click event handler for "Delete" button in all existing grid rows when Dynaform loads
//subtract because eq() starts counting from 0, not 1 like rowIndex:
jgd.find("button.glyphicon-trash").off("click");
//add custom click event handler for delete buttons in grid when Dynaform loads:
jgd.find("button.glyphicon-trash").click({param1: gdId, param2: ColNoLst}, onDelRow);
}; // end if not zero row
}; // end gdOnLoad
// --- gdOnAddRow ------
function gdOnAddRow(gdId, rowIndex, ColNoDisableLst){
var jgd = $('#' + gdId);
ColNoLst = ColNoDisableLst;
//subtract because eq() starts counting from 0, not 1 like rowIndex:
jgd.find("button.glyphicon-trash").eq(rowIndex-1).off("click");
jgd.find("button.glyphicon-trash").eq(rowIndex-1).click({param1: gdId, param2: ColNoLst}, onDelRow);
// jgd.find("button.glyphicon-trash").click(onDelRow2(gdId, ColNoLst, rowIndex));
}; // end gdOnAddRow
// --- grid parameters initialization
var formId = $("form").prop("id");
// --- grid gdCltLst ---
var gdCltLstId = "clientsList" ;
var jgdCltLst = $("#"+gdCltLstId);
var gdCltDisableColNoLst = [1,3]; // columns to be disabled
// // -- gdCltLst onLoad ----
gdOnLoad(gdCltLstId, gdCltDisableColNoLst);
// // --- gdCltLst onAddRow ----
jgdCltLst.onAddRow(function(aNewRow, oGrid, rowIndex){
gdOnAddRow(gdCltLstId, rowIndex, gdCltDisableColNoLst);
});
// --- grid gdT1 ---
var gdT1Id = "gdT1" ;
var jgdT1 = $("#"+gdT1Id);
var gdT1DisableColNoLst = [2,4]; // columns to be disabled
// // -- gdT1 onLoad ----
gdOnLoad(gdT1Id, gdT1DisableColNoLst);
// // --- gdT1 onAddRow ----
jgdT1.onAddRow(function(aNewRow, oGrid, rowIndex){
gdOnAddRow(gdT1Id, rowIndex, gdT1DisableColNoLst);
});
I need to
1) disable some of the cells in a row of the grid when the <trash> button of the row is clicked, and
2) hide the <trash> button
in a dynaform.
The enclosed javascript program is written for such purpose.
My problem is when the <trash> button is clicked, not only the cells to be disabled CANNOT be disabled, but also ALL the disabled cells in the dynaform are enabled!
I have tested with disabling either the hide <trash> button statement or the for loop on disabling cells, the same problem presist disregard of which statement I disabled.
Grateful if I can have your advice in fixing the bug.
Thousand Thanks.
cheers,
Karl
// -------- javascript to disable some grid cells instead of delete row on <trash> button is clicked --------
function onDelRow(e) {
var rowNo = $(this).attr("data-row");
var gdIdThisNm = e.data.param1;
var ColNoLst = e.data.param2;
var jgd = $('#'+gdIdThisNm);
// // --- hide <del>
$(jgd.find("div.pmdynaform-grid-row")[rowNo-1]).find("button").hide();
// // disable fields
for (i in ColNoLst){
jgd.getControl(rowNo, ColNoLst).attr("disabled", true);
}; // end for
}; // end onDelRow(e)
// ---- gdOnLoad ------
function gdOnLoad(gdId, ColNoDisableLst){
var jgd = $('#' + gdId);
var gdLen = jgd.getNumberRows();
ColNoLst = ColNoDisableLst;
if (gdLen > 0){
//turn off the click event handler for "Delete" button in all existing grid rows when Dynaform loads
//subtract because eq() starts counting from 0, not 1 like rowIndex:
jgd.find("button.glyphicon-trash").off("click");
//add custom click event handler for delete buttons in grid when Dynaform loads:
jgd.find("button.glyphicon-trash").click({param1: gdId, param2: ColNoLst}, onDelRow);
}; // end if not zero row
}; // end gdOnLoad
// --- gdOnAddRow ------
function gdOnAddRow(gdId, rowIndex, ColNoDisableLst){
var jgd = $('#' + gdId);
ColNoLst = ColNoDisableLst;
//subtract because eq() starts counting from 0, not 1 like rowIndex:
jgd.find("button.glyphicon-trash").eq(rowIndex-1).off("click");
jgd.find("button.glyphicon-trash").eq(rowIndex-1).click({param1: gdId, param2: ColNoLst}, onDelRow);
// jgd.find("button.glyphicon-trash").click(onDelRow2(gdId, ColNoLst, rowIndex));
}; // end gdOnAddRow
// --- grid parameters initialization
var formId = $("form").prop("id");
// --- grid gdCltLst ---
var gdCltLstId = "clientsList" ;
var jgdCltLst = $("#"+gdCltLstId);
var gdCltDisableColNoLst = [1,3]; // columns to be disabled
// // -- gdCltLst onLoad ----
gdOnLoad(gdCltLstId, gdCltDisableColNoLst);
// // --- gdCltLst onAddRow ----
jgdCltLst.onAddRow(function(aNewRow, oGrid, rowIndex){
gdOnAddRow(gdCltLstId, rowIndex, gdCltDisableColNoLst);
});
// --- grid gdT1 ---
var gdT1Id = "gdT1" ;
var jgdT1 = $("#"+gdT1Id);
var gdT1DisableColNoLst = [2,4]; // columns to be disabled
// // -- gdT1 onLoad ----
gdOnLoad(gdT1Id, gdT1DisableColNoLst);
// // --- gdT1 onAddRow ----
jgdT1.onAddRow(function(aNewRow, oGrid, rowIndex){
gdOnAddRow(gdT1Id, rowIndex, gdT1DisableColNoLst);
});