jqgrid复选框更改事件 [英] jqgrid checkbox change event

查看:1095
本文介绍了jqgrid复选框更改事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的数据库中有true / false值。我想用jqgrid中的复选框更新它们。
一旦将值设置为true,它将保持为true且不应更改。请看一下我的专栏模型:

I have true/false values in my database. I want to update them with checkbox in jqgrid. Once the value is set to true, it will remain true and should not change. Please take a look at my column model :

{
    name : 'available',
    width : 12,
    resizable: true,
    editable: true,
    align: 'center',
    edittype:'checkbox',
    formatter: "checkbox", formatoptions: {disabled : false},
    classes:'check',
    editrules:{required:false}, editoptions:{size:39,value:"True:False"}
}

我正试图在选中复选框时捕获事件,目前它们都未经检查,到目前为止我'尝试过:

I'm trying to capture the event when checkbox is checked, currently they are all unchecked, so far I've tried:

jq(".check input").each(function(){
    jq(this).click(function(){
        aler("works");
    });
});

jq("input[type='checkbox']").change(function(){
    alert("works");
}); 

jq(":checkbox").parent().click(function(evt) {
    if (evt.target.type !== 'checkbox') {
        var $checkbox = jq(":checkbox", this);
        $checkbox.attr('checked', !$checkbox.attr('checked'));
        $checkbox.change();
        alert("");
    }
});

这些都不起作用,我被困住了,不知道还有什么可以尝试。

None of these work, I'm stuck don't know what else to try.

当用firebug检查复选框代码时,它看起来像这样:

When inspect checkbox code with firebug it looks like this :

<input type="checkbox" offval="no" value="false">


推荐答案

使用自定义格式化程序是其中一种可能性。也可以使用不引人注目的 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);
    });
}

查看相应的演示这里

这篇关于jqgrid复选框更改事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆