What is the best way to programmatically select all rows in a jqGrid that is set to multiselect?
The code could loop through all of the rows one-at-a-time and select each one, but then the checkbox in the grid header is not checked. I was thinking about just triggering the header row checkbox's clicked event, but that would make assumptions about the underlying jqGrid implementation. There must be a better way...
Thanks in advance!
Rows can be selected in ParamQuery Grid either by user action or programmatically. All rows can be selected using Ctrl - A or Cmd - A (Mac).
You can select or highlight rows based on data using the queryCellInfo event or can also select a row using an external button click event. The queryCellInfo is triggered every time a request is made to access particular cell information, element and data.
jqGrid exposes a property rowNum where you can set the number of rows to display for each page.
If you select all of the rows in a multiselect jqGrid by clicking on each one manually, the checkbox in the header doesn't get checked, so I wouldn't necessarily expect it to happen when you do it programmatically (if you use setSelected(rowid, true) for each row, it's the equivalent of clicking on each, as the "true" parameter indicates that the clicked event should be fired for each one).
So in fact, if you want all of them to get checked AND want the checkbox in the header to be checked, triggering the clicked event may be your best bet. If you dig into the source code and look at what happens when you click the checkbox, it is in fact just looping through all of the rows and setting each as selected, so I don't think you're going to do a lot better.
I think nothing is impossible,This is alternative solution. You can loop through all of the rows one-at-a-time and select each one, then the checkbox in the grid header is checked by manually. But checkbox in the grid header is unselected when at-least one check box is unselected.
colNames : [ ,'<input type="checkbox" id="cbox" onclick="UI_PaxCheckin.checkBox(this,event)" />',..]
UI_PaxCheckin.checkBox = function(obj,e) {
e = e||event;
e.stopPropagation? e.stopPropagation() : e.cancelBubble = true;
var grid = $('#jqGridPax');
if(obj.checked == true){
UI_PaxCheckin.multiSelectedFlightRowID = [];
}
for ( var p = 0; p < grid[0].rows.length -1 ; p++) {
$('#chkIsSelected_' + p).prop('checked', obj.checked);
//manual checkbox click event function call
}
$('#cbox').prop('checked', obj.checked);}
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