jqGrid: How to use multiselect on different pages

谁说胖子不能爱 提交于 2019-11-30 13:24:24

问题


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?


回答1:


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?




回答2:


Please see this: https://stackoverflow.com/a/24941828/136219

For a way to achieve what you are looking for.



来源:https://stackoverflow.com/questions/11567915/jqgrid-how-to-use-multiselect-on-different-pages

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!