且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

jqgrid复选框更改事件

更新时间:2023-10-06 20:35:52

使用自定义格式化程序是其中一种可能性。也可以使用不引人注目的 onclick 绑定

The usage of the custom formatter is one of the possibilities. One can also use unobtrusive style of onclick binding

第一个定义

var grid = $("#list"),
    getColumnIndexByName = function(columnName) {
        var cm = grid.jqGrid('getGridParam','colModel'),i=0,l=cm.length;
        for (; i<l; i++) {
            if (cm[i].name===columnName) {
                return i; // return the index
            }
        }
        return -1;
    },
    disableIfChecked = function(elem){
        if ($(elem).is(':checked')) {
            $(elem).attr('disabled',true);
        }
    };

然后可以使用 loadComplete 代码如

loadComplete: function() {
    var i=getColumnIndexByName('closed');
    // nth-child need 1-based index so we use (i+1) below
    $("tbody > tr.jqgrow > td:nth-child("+(i+1)+") > input",
      this).click(function(e) {
        disableIfChecked(this);
    }).each(function(e) {
        disableIfChecked(this);
    });
}

查看相应的演示这里