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

2

8

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?

Brussels answered 17/1, 2011 at 7:6 Comment(0)
A
3

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.

Alexandro answered 30/7, 2012 at 15:38 Comment(0)
F
0

I'm assuming you would like to do select some rows in one page, then go to another page, maybe select some more rows, and have all of those selection persisted.

You will have to handle the selection events on each check box. Attach an event handler to each $("#cb_my_grid") and persist an array of selected items. Then when you need the data (maybe when the page is submitted) you can submit the values in the array.

Fiddle answered 4/3, 2011 at 18:0 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.