我有一個jqGrid,有六列,每列都有一個'複選框'格式。我需要根據列名稱獲取所有複選框的選定值和未選定值。可能嗎?jqGrid與所有列中的複選框
第一列是提供一個選項,用於一起選擇所有剩餘的列。 定義colModel
時,我無法添加事件偵聽器,如onclick
或onselect
。
$("#Grid").jqGrid({
url: '@Url.Action("Access", "Authorization")' + '?role=' + encodeURIComponent($('input#hIDRole').val()),
datatype: 'json',
colNames: ["IDAccess","Permission", "ALL", "Read", "Add", "Edit", "Copy", "Delete"],
colModel: [
{ name: 'IDAccess', index: 'IDAccess', width: 10, resizable: false, editable: false, hidden: true },
{ name: 'Permission', index: 'Permission', width: 100, resizable: false, editable: false, hidden: false },
{ name: 'ALL', index: 'ALL', editable: true, edittype: 'checkbox', editoptions: { value: "True:False" }, formatter: "checkbox", width: 50, resizable: false, formatoptions: { disabled: false }, onselect: "checkBox(this.value())" },
{ name: 'IsRead_Allowed', index: 'IsRead_Allowed', editable: true, edittype: 'checkbox', formatter: "checkbox", editoptions: { value: "True:False" }, width: 50, resizable: false, formatoptions: { disabled: false }, onclick: "checkBox(checked,this.value)" },
{ name: 'IsCreate_Allowed', index: 'IsCreate_Allowed', editable: true, edittype: 'checkbox', editoptions: { value: "True:False" }, formatter: "checkbox", width: 50, resizable: false, editable: true, formatoptions: { disabled: false }, onclick:"checkBox(event)" },
{ name: 'IsUpdateAllowed', index: 'IsUpdateAllowed', editable: true, edittype: 'checkbox', editoptions: { value: "True:False" }, formatter: "checkbox", width: 50, resizable: false, editable: true, formatoptions: { disabled: false }, },
{ name: 'IsCopy_Allowed', index: 'IsCopy_Allowed', editable: true, edittype: 'checkbox', editoptions: { value: "True:False" }, formatter: "checkbox", width: 50, resizable: false, editable: true, formatoptions: { disabled: false } },
{ name: 'IsDeleteAllowed', index: 'IsDeleteAllowed', editable: true, edittype: 'checkbox', editoptions: { value: "True:False" }, formatter: "checkbox", width: 50, resizable: false, editable: true, formatoptions: { disabled: false } },
],
//rowNum: 10,
//rowList: [10],
pager: "#pager-json",
autowidth: true,
loadComplete: function() {
var rowIDs = $("#Grid").jqGrid('getDataIDs');
for (var i = 0; i < rowIDs.length ; i++) {
var rowId = rowIDs[i];
var rowData = jQuery('#Grid').jqGrid('getRowData', rowId);
//below code to check the All column if the other columns have true in the db. But once checked attribute is added i am not able to uncheck
if ((rowData['IsRead_Allowed'] == "True") && (rowData['IsCreate_Allowed'] == "True") && (rowData['IsUpdateAllowed'] == "True")
&& (rowData['IsCopy_Allowed'] == "True") && (rowData['IsDeleteAllowed'] == "True")) {
var check = $("#" + rowId).find('input[type="checkbox"]');
check.attr('checked', 'checked');
}
}
for (var i = 0; i < rowIDs.length; i++) {
var rowData = rowIDs[i];
if (rowData['IsCopy_Allowed'] == null) {
//alert("1");
var checkbox = $("#Grid" + rowData.i);
//checkbox.css("visibility", "hidden");
checkbox.attr("disabled", true);
}
}
}
});
當您嘗試添加onclick偵聽器時會發生什麼?當你期望它,或者什麼時,它不會開火嗎? –
它不會觸發收聽者。 – Vigneshwaran