我正在创建一个带有可编辑字段的jqgrid。我在jqgrid中有两个复选框列,一个来自multiselect:true(获取唯一的rowId),其他列在列模型中创建。
我想处理列模型中复选框的onchange(选中/未选中)事件,与其他复选框列无关(multiselect:true)。任何帮助赞赏。以下是代码段。
[{name : "userRole", label: 'OV', width: 40, editable:true, edittype:'checkbox',formatter: 'checkbox', editoptions: {value:"True:False"},
formatoptions: { disabled: false},frozen:true}]
multiselect: true,
onSelectRow: function(rowid){
jQuery(this).editRow(rowid, true);
}
答案 0 :(得分:6)
您可以使用beforeSelectRow
回调。 The demo展示了这种方法。它使用以下代码
beforeSelectRow: function (rowid, e) {
var $target = $(e.target), $td = $target.closest("td"),
iCol = $.jgrid.getCellIndex($td[0]),
colModel = $(this).jqGrid("getGridParam", "colModel");
if (iCol >= 0 && $target.is(":checkbox")) {
alert("checkbox is " +
($target.is(":checked")? "checked" : "unchecked") +
" in the column \"" + colModel[iCol].name +
"\" in the row with rowid=\"" + rowid + "\"");
}
return true;
}
答案 1 :(得分:3)
在colmodel中定义自己的格式化程序函数,
[{name : "userRole", label: 'OV', width: 40,
editable:true, edittype:'checkbox',formatter: checkboxFormatter,
editoptions: {value:"True:False"},
您的格式化复选框,如
function checkboxFormatter(cellvalue, options, rowObject) {
return "<input type='checkbox' name='checkboxIsCC'
onchange='your_own_function();'>";
}
希望这会对你有所帮助。
答案 2 :(得分:0)
我有一个问题,不仅我有超过1个复选框,而且我还必须根据复选框的选择更新相同的列复选框值以及修改相同的行列。
关于其他复选框的修改,当jqgrid通过&#39; setCell&#39;修改数据时或者&#39; setRowData&#39;操作,它删除click事件。还有一个问题是,对于复选框,edit functions都没有用。
我设法从其他人的解决方案中获取位,并开始使用委托jquery函数,它允许在每次创建与选择器匹配的对象时完成点击的绑定。同样在这种情况下,一次只能检查1个列中的1个复选框。
$(document).delegate("#alarmDownloadListView td[aria-describedby*='stopArm'] input", 'click', function () {
// Function that modifies all the other checkboxes of the same column
deselectOthersStopArmAlarms(this, j);
// Set the Pre and Pos Alarm values to default
var fileIndex = $(this).closest('tr').index();
// Modification of the same row cells
if($(this).is(':checked')){
alarmsGrid.jqGrid('setCell',fileIndex,'preAlarm', defaultPrePosStopArmAlarmValue);
}else{
alarmsGrid.jqGrid('setCell',fileIndex,'preAlarm', null);
}
});
不介意代码的确切操作,重要的是绑定函数的操作。 CSS选择器将此函数绑定到我的colmodel中名称为stopArm的所有复选框。
我希望这个答案对某些人有用。我发现代表非常有用! :)