Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
337 views
in Technique[技术] by (71.8m points)

javascript - JQGRID - maintain check box selection state - page refresh / redirect / reload

How to maintain the checkbox selection after the page refresh / reload / redirected from some other page in JQGRID.

I am working in aspx pages.

I am able to maintain the checkbox selection state in paging using following code:

    gridComplete: function () {
     var currentPage = $(this).getGridParam('page').toString(); //retrieve any previously stored rows for this page and re-select them
     var retrieveSelectedRows = $(this).data(currentPage);
     if (retrieveSelectedRows) {
        $.each(retrieveSelectedRows, function (index, value) {
        $('#list').setSelection(value, false);
     });
    }
   },
   onPaging: function (a) {
     var pagerId = this.p.pager.substr(1); // ger paper id like "pager" 
     var pageValue = $('input.ui-pg-input', "#pg_" +           $.jgrid.jqID(pagerId)).val();
     var saveSelectedRows = $(this).getGridParam('selarrrow'); //Store any selected rows 
     $(this).data(pageValue.toString(), saveSelectedRows);
  }

But, how to maintain the checkbox selection state in page refresh / redirect / reload in JQGrid ?

Also, I tried the following code on Window.OnLoad, but it is not working

$("#list").trigger("reloadGrid", [{page: 1, current: true}]);
Question&Answers:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The implementation of selection over multiple pages of the grid is very tricky in old versions of jqGrid. I posted the answer, the answer (try the demo) with the corresponding implementations.

On the other side the scenario of selection of multiple rows over multiple pages is very common. Thus I implemented new feature in free jqGrid. Now one can just use new multiPageSelection: true option in combination with multiselect: true. It changes the behavior of selection in the following way:

  • one can use selarrrow array to pre-select some rows directly during creating the grid.
  • the array selarrrow can hold the ids of rows from other pages. The array selarrrow will be not cleared on changing the page. jqGrid just select rows if it's rowid is in the array selarrrow.
  • click on "Select All" checkbox in the header of checkbox columns fills selarrrow with all rowids of local data (from all pages)

The demo demonstrates the new feature.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...