简体   繁体   中英

jQgrid: Disable checkbox click and select checkbox only when checkbox is clicked

I am using jqgrid using multiselect option. There are two different functionality that I have to implement.

Functionality 1: I have to disable check checkbox depends upon some condition. For that I am using below block of code in beforrowselect event.

beforeSelectRow: function(rowid, e) {
    if( $("#jqg_TableId_"+rowid).attr("disabled") ){
        return false;
    }
    return true; 
}

The functionality is working fine with this block of code.

Functionality 2: But issue is when I click on anywhere in the row, the checkbox get selected but the checkbox value is not coming out correct. The value of checkbox is accurate when I click inside the area of checkbox. For that I want to restrict the user to click exactly on checkbox area to get checkbox clicked. For that I am using below mentioned block of code.

beforeSelectRow: function(rowid, e) { 
   return $(e.target).is('input[type=checkbox]');
},

If I am using any one block alone then its working fine for that functionality. I need to implement both the functionality but both the block returning value. It is not possible to return value for both the condition. Please help me out How can I implement both the functionality.

Below is the complete code that I have to implement.

beforeSelectRow: function(rowid, e) { 
    if( $("#jqg_TableId_"+rowid).attr("disabled") ){
        return false;
    }
    return true; 
}
 return $(e.target).is('input[type=checkbox]');
},

It's important to include in every question which version of jqGrid and from which fork ( free jqGrid , Guriddo jqGrid JS or an old jqGrid in version <=4.7) you use. I suppose that the problem which you describe exist because you use some old version of jqGrid.

The demo https://jsfiddle.net/OlegKi/4ga1ekh3/3/ uses free jqGrid 4.12.1 (it's the fork of jqGrid which I develop more as one year) and the following code

beforeSelectRow: function (rowid, e) {
    var item = $(this).jqGrid("getLocalRow", rowid);
    if (item.closed) {
        return false;
    }
    return true; 
}

to deny selection of rows which have closed: true property. The click on any place on the row works in the same way like clicking on the checkbox.

I sill would recommend you to consider to use another way, which I described in the answer . It sets just

rowattr: function (rd) {
    if (rd.closed) {
        return {
            "class": "ui-state-disabled ui-jqgrid-disablePointerEvents"
        };
    }
}

See another demo https://jsfiddle.net/OlegKi/4ga1ekh3/4/ . It set disabled class on "closed" rows, which prevent selection of the row in case clicking on the column header of select column (Select All functionality).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM