Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jqgrid multiselect only selects rows on the current page, if paging is enabled. How to make it select rows across pages?

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?

like image 483
giorgio79 Avatar asked Jan 17 '11 07:01

giorgio79


1 Answers

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.

like image 83
Weezle Avatar answered Jan 02 '23 09:01

Weezle