开发者

JQGrid select row checkboxclick

开发者 https://www.devze.com 2023-03-14 13:44 出处:网络
I try to receive row id of JQGrid on checkbox click like: loadComplete : function() { jQuery(\".jqgrow td input\").each(function() {

I try to receive row id of JQGrid on checkbox click like:

loadComplete : function() {
    jQuery(".jqgrow td input").each(function() {
        jQuery(this).click(function() {
            var grid = $("#list");
            var rowid = grid.jqGrid('getGridParam', 'selrow');
            alert(rowid);
        });
    });
}

But row is not selected - so I always receive a null开发者_如何学运维. What can be the reason? Thanks.


The reason is var rowid = grid.jqGrid('getGridParam', 'selrow'); will only contain rowid if you have already selected a row by clicking on the row before.

If you want an alternative, then you can select the checkbox on onSelectRow instead

onSelectRow: function(id,status){
    var rowData = jQuery(this).getRowData(id); 
    var ch = jQuery(this).find('#'+id+' input[type=checkbox]').attr('checked');
    if(ch) {
        jQuery(this).find('#'+id+' input[type=checkbox]').attr('checked',false);
    } else {
        jQuery(this).find('#'+id+' input[type=checkbox]').attr('checked',true);                       
    }

    rowChecked=1;
    currentrow=id;
}


Why not use the onSelectRow event built in jqGrid?

You can read more about jqGrid events here

0

精彩评论

暂无评论...
验证码 换一张
取 消