jqGrid: How to use multiselect on different pages
Asked Answered
C

2

8

Simple question, hard to find an answer:

If I try to select a row programmatically, I use this:

$('#grid').jqGrid('setSelection', rowId);

The problem is that it only selects rows on current visible page. If rowId is on another page, it will not be selected.

More info: My goal is to select multiple rows (spread on multiple pages) when page loads for the first time.

Thanks, Rafael

PS: This guy has the same problem. No answer yet: jqgrid multiselect only selects rows on the current page, if paging is enabled. How to make it select rows across pages?

Callas answered 19/7, 2012 at 19:27 Comment(0)
P
9

Right, jqGrid will only select rows on the current page. In order to select other rows you need to maintain a list of selected ID's and manually select them.

To do this you need to add code to your loadComplete event to search the current page and select any of these rows:

var ids = grid.jqGrid('getDataIDs');
for (var i = 0; i < ids.length; i++){
    if (selected[ids[i]] === true ){
        grid.setSelection(ids[i], false);
    }
}

You also need to add code to your onSelectRow and onSelectAll events to adjust the contents of selected when the user selects/unselects rows:

onSelectRow: function(rowid, status){
    selected[rowid] = status;
    setSelectedDeviceCount();
},

onSelectAll: function(rowids, status){
    for (var i = 0; i < rowids.length; i++){
        selected[rowids[i]] = status;
    }
}

Does that help?

Phytology answered 19/7, 2012 at 19:51 Comment(1)
Thanks a lot! Unfortunately the code can't be used this way (my fault, not yours!), but the overall idea made me fix this! Thanks!Callas
P
0

Please see this: https://mcmap.net/q/1468398/-selecting-all-the-rows-of-all-the-pages-of-a-jqgrid-programmatically

For a way to achieve what you are looking for.

Pelayo answered 23/5, 2016 at 6:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.