Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to know JqGrid multiselect 'select all' checkbox is checked

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

like image 649
Baby Avatar asked Nov 30 '13 02:11

Baby


1 Answers

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);
}
like image 104
Brian Swift Avatar answered Sep 23 '22 05:09

Brian Swift