Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jqGrid: How to use multiselect on different pages

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?

like image 580
Rafa Borges Avatar asked Jul 19 '12 19:07

Rafa Borges


People also ask

How to use jQuery Select2 for multiselect?

Select2 gives a highly customizable jQuery Multiselect control with support for searching, tagging, remote data sets, infinite scrolling, and many other highly used options. a. First you have to add Select2 CSS on the page head. b. Next add the html select control on your page:

How to create HTML select control using jQuery&Select2 JS?

First you have to add Select2 CSS on the page head. b. Next add the html select control on your page: c. Then add reference to jQuery & Select2 JS file. d. Finally initialize the select control using the .select2 () method as shown below. Related – Learn how to create jQuery Treeview in your website in minimum time.

How to use jQuery Select2 plugin with jQuery dropdownlist?

First, the jQuery and the JS and CSS files of the jQuery Select2 plugin are inherited. Then inside the jQuery document.ready event handler, the jQuery Select2 plugin is applied to the DropDownList.

How to populate dropdownlist in pagemodel using Entity Framework?

The PageModel consists of two Action Handler methods. Inside this Handler method, the records are fetched from the Customers table using Entity Framework and are copied to SelectList class object and assigned to the public property Customers, which is used for populating DropDownList in ASP.Net Core Razor Pages.


1 Answers

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?

like image 106
Justin Ethier Avatar answered Sep 30 '22 18:09

Justin Ethier