I noticed in the jqgrid demo (http://www.trirand.com/blog/jqgrid/jqgrid.html > Advanced > Multiselect) that only rows (visible) on the current page are selected if paging is enabled.
Any tips on getting it to work across multiple pages. Or any other alternative solutions?
I know this question is kind of dusty, but I recently had a need for this functionality and found what I consider a much more clean way to do it.
Instead of attaching an event to each checkbox, why not use the onSelectRow
and onSelectAll
events of the jqGrid? When a row is selected, check if our list of selected rows includes this row (based on id). Add it to the list if it was not there and has been selected, remove it if it was there and is no longer selected. If all rows are selected, iterate through them.
var $grid = jQuery("#myGrid");
var updateIdsOfSelectedRows = function (id, isSelected) {
var contains = idsOfSelectedRows.contains(id);
if (!isSelected && contains) {
for(var i=0; i<idsOfSelectedRows.length; i++) {
if(idsOfSelectedRows[i] == id) {
idsOfSelectedRows.splice(i, 1);
break;
}
}
}
else if (!contains) {
idsOfSelectedRows.push(id);
}
};
$grid.jqGrid({
....
onSelectRow: function(rowid, status){
updateIdsOfSelectedRows(rowid, status);
},
onSelectAll: function (aRowids, status) {
var i, count, id;
for (i = 0, count = aRowids.length; i < count; i++) {
id = aRowids[i];
updateIdsOfSelectedRows(id, status);
}
},
....
)};
Hope this helps others looking for a solution.