Javascript jqgrid中有多个复选框列。句柄onchange事件

Javascript jqgrid中有多个复选框列。句柄onchange事件,javascript,jquery,checkbox,jqgrid,Javascript,Jquery,Checkbox,Jqgrid,我正在创建一个带有可编辑字段的jqgrid。我在jqgrid中有两个复选框列,一个来自multiselect:true(以获得唯一的rowId),另一个列是在列模型中创建的 我想处理我的列模型中复选框的onchange(checked/unchecked)事件,独立于其他复选框列(multiselect:true)。谢谢你的帮助。下面是代码片段 [{name : "userRole", label: 'OV', width: 40, editable:true, edittype:'checkb

我正在创建一个带有可编辑字段的jqgrid。我在jqgrid中有两个复选框列,一个来自multiselect:true(以获得唯一的rowId),另一个列是在列模型中创建的

我想处理我的列模型中复选框的onchange(checked/unchecked)事件,独立于其他复选框列(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);
            }

在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();'>";
}
函数checkboxFormatter(单元格值、选项、行对象){
返回“”;
}

希望这对您有所帮助。

在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();'>";
}
函数checkboxFormatter(单元格值、选项、行对象){
返回“”;
}

希望这对您有所帮助。

您可以在选择Row回调之前使用
。演示该方法。它使用以下代码

在选择行之前:函数(rowid,e){
var$target=$(e.target),$td=$target.closest(“td”),
iCol=$.jgrid.getCellIndex($td[0]),
colModel=$(this.jqGrid(“getGridParam”,“colModel”);
如果(iCol>=0&&$target.is(“:复选框”)){
警报(“复选框为”+
($target.is(“:checked”)?“checked”:“unchecked”)+
“在\”“+colModel[iCol]列中”。名称+
行中的“\”,rowid=\“”+rowid+“\”);
}
返回true;
}

您可以在选择Row
回调之前使用
。演示该方法。它使用以下代码

在选择行之前:函数(rowid,e){
var$target=$(e.target),$td=$target.closest(“td”),
iCol=$.jgrid.getCellIndex($td[0]),
colModel=$(this.jqGrid(“getGridParam”,“colModel”);
如果(iCol>=0&&$target.is(“:复选框”)){
警报(“复选框为”+
($target.is(“:checked”)?“checked”:“unchecked”)+
“在\”“+colModel[iCol]列中”。名称+
行中的“\”,rowid=\“”+rowid+“\”);
}
返回true;
}

我遇到了一个问题,不仅我有多个复选框,而且我还必须根据复选框的选择更新相同的列复选框值,以及修改相同的行和列

关于其他复选框的修改,当jqgrid通过“setCell”或“setRowData”操作修改数据时,它会删除click事件。还有一个问题是,对于复选框,没有一个是有用的

我设法从其他人的解决方案中获得一些信息,并开始使用委托jquery函数,该函数允许在每次创建与选择器匹配的对象时绑定单击。在这种情况下,一次只能选中一列中的一个复选框

$(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的所有复选框


我希望这个答案对一些人有用。我发现该代表非常有用!:)

我遇到了一个问题,不仅我有多个复选框,而且我还必须根据复选框的选择更新同一列复选框的值,以及修改同一行和列

关于其他复选框的修改,当jqgrid通过“setCell”或“setRowData”操作修改数据时,它会删除click事件。还有一个问题是,对于复选框,没有一个是有用的

我设法从其他人的解决方案中获得一些信息,并开始使用委托jquery函数,该函数允许在每次创建与选择器匹配的对象时绑定单击。在这种情况下,一次只能选中一列中的一个复选框

$(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的所有复选框


我希望这个答案对一些人有用。我发现该代表非常有用!:)

不要在colmodel中使用
格式化程序:“checkbox”
,而是为checkbox定义自己的
格式化程序
函数。因此,您可以将
onchange
函数包括在内。而不是在colmodel中使用
格式化程序:“checkbox”
,为checkbox定义自己的
格式化程序
函数。因此,您可以包含
onchange
函数。