0

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]');
},
user1140237
  • 5,015
  • 1
  • 28
  • 56
user2992704
  • 1
  • 1
  • 3

1 Answers1

0

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).

Community
  • 1
  • 1
Oleg
  • 220,925
  • 34
  • 403
  • 798
  • The block in beforeSelectRow for disabling checkbox select is working as expected but the rowattr event is not working as per requirement. The entire row is disable while returning"class": "ui-state-disabled ui-jqgrid-disablePointerEvents". The checkbox need be be checked only while clicking on over the checkbox area. – user2992704 Jan 26 '16 at 06:11
  • @user2992704: Yes, it's what is expected for me. Setting of rows disables makes two things at once: shows the user which rows can't be selected 2) fix the problem with selection of all rows. One can us some other predefined classes instead: `ui-subgrid`, `jqgroup` or `jqfoot`. See https://jsfiddle.net/OlegKi/4ga1ekh3/5/- One have to combine **both** `rowattr` and `beforeSelectRow`. – Oleg Jan 26 '16 at 06:22