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
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);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With