how to know JqGrid multiselect 'select all' checkbox is checked
Asked Answered
H

1

5

Im trying to display the selected row in JQgrid. Now, i have this code:

onSelectRow:function(rowid){
    var selectedRow = $('#mygrid').jqGrid('getGridParam', 'selarrrow');
    $("#totalSelected").val(selectedRow .length); 
}

Its work fine, but then when the 'select all' checkbox is checked, it didn't trigger this code, eventhough in visual we can see that all row has been selected.

so i'm thinking that if i know that the 'select all' checkbox is checked, i can set the total selected value like this:

  if(//selectall checkbox is checked) 
      $("#totalSelected").val($("#mygrid tr").length-1);

I've tried this code by refering to this answer, but im pretty sure .checked() is not recognized:

  if($("#cb_mygrid"[0].id).checked()) 
      $("#totalSelected").val($("#mygrid tr").length-1);

Any idea is much appreciated

Hg answered 30/11, 2013 at 2:33 Comment(0)
W
8

onSelectRow does not fire when the header checkbox is used to select all items. There is a separate event handler to capture the Select All event. From the documentation:

onSelectAll

Sends you the following parameters: aRowids, status

This event fires when multiselect option is true and you click on the header checkbox. aRowids is an array of the selected rows (rowid's). status is a boolean variable determining the status of the header check box - true if checked, false if not checked. Note that the aRowids array will always contain the ids whether the header checkbox is checked or unchecked.

When this event fires, in your case you'll want to do the following to show the correct count of selected rows:

onSelectAll: function(aRowids, status) {
    //Use a ternary operator to choose zero if the header has just been unchecked, or the total items if it has just been checked.
    $("#totalSelected").val(status === false ? 0 : aRowids.length);
}
Wool answered 30/11, 2013 at 2:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.