|
27- پنهان سازی دکمه حذف در گرید
منتشر شده توسط , ویرایش شده توسط: در تاریخ 1398/11/5 شنبه 15:16
|
|
|
//set to the ID of the grid:
var gridId = "g2";
//set to the column number of field to check whether to show/hide the delete button:
var fieldColNo = 4;
//regular expression to get grid row number in form.setOnchange():
var gridRE = new RegExp('^\\['+gridId+'\\]\\[(\\d+)\\]');
//function that hides the "Delete" button in the grid's rowNumber
//if the "cost" field is over 100. Otherwise, it shows the button.
//If the rowNumber is set to 0, then all the rows in the grid will be checked
function showHideDeleteButtonsInGrid(rowNumber) {
var oGrid = $("#"+gridId);
if (rowNumber < 1) {
var nRows = oGrid.getNumberRows();
for (var i = 1; i <= nRows; i++) {
var cost = parseFloat( oGrid.getValue(i, fieldColNo) );
if (!isNaN(cost) && cost >= 100) {
$("div.pmdynaform-grid-removerow-responsive").eq(i-1).find("button").hide();
}
else {
$("div.pmdynaform-grid-removerow-responsive").eq(i-1).find("button").show();
}
}
}
else {
var cost = parseFloat( oGrid.getValue(rowNumber, fieldColNo) );
if (!isNaN(cost) && cost >= 100) {
$("div.pmdynaform-grid-removerow-responsive").eq(rowNumber-1).find("button").hide();
}
else {
$("div.pmdynaform-grid-removerow-responsive").eq(rowNumber-1).find("button").show();
}
}
}
//execute when dynaform loads to hide/show Delete buttons in
//every row in the grid:
showHideDeleteButtonsInGrid(0);
//change event handler for all fields in Dynaform, which only looks
//for changes in the grid:
$( "#"+$("form").prop("id") ).setOnchange( function(fieldName, newVal, oldVal) {
var oGrid = $("#"+gridId);
var aMatch = fieldName.match(gridRE);
if (aMatch !== null) {
var rowNo = parseInt(aMatch[1]);
showHideDeleteButtonsInGrid(rowNo);
}
})
در مثال فوق قرار است کالاهایی که مقدار ستون هزینه آنها از 100 بیشتر باشد کاربر مجاز به حذفشان نباشد و دکمه سطل آشغال انتهای گرید مخفی شود
| |
|
|
