If you see jqGrid demo :
http://www.trirand.com/blog/jqgrid/jqgrid.html
Section : Advanced --> Multiselect
You'll see that the checked checkbox is not persist when i move to the next page, and back to the previouse page again ..
How to make it persist ?
It's my scenario, in my applications there is a group functionality where i can add several customer, i'm using jqgrid to display thousands of customers.
I want to check every customer i want, and then submit this selected customer and add it to the specified group ..
How can i do this ? (make jqgrid, multiselect persist ?)
Thanks.
This is fairly simple to do using the gridComplete and onPaging events plus the jquery .data() method. This is much simpler than a lot of the stuff I've seen floating around the net, so I thought I'd share it. The selector for my grid is '#employeerolegrid'.
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) {
$('#employeerolegrid').setSelection(value, false);
});
}
},
onPaging: function () {
var saveSelectedRows = $(this).getGridParam('selarrrow');
var page = $(this).getGridParam('page') - 1;
//Store any selected rows
$(this).data(page.toString(), saveSelectedRows);
}
Look at the event list here http://www.trirand.com/jqgridwiki/doku.php?id=wiki:events
The logic is: everytime the "onPaging" event is fired, you should iterate through each row and store the unique id of each row to an array, also iterate through your array of id and check all of the select box everytime the "onPaging" is fired.
My solution: (define variable current_page and set in Event loadBeforeSend) because
var page = $(this).getGridParam('page') - 1; not work.
var current_page=0;
...
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) {
$('#employeerolegrid').setSelection(value, false);
});
}
},
onPaging: function () {
var saveSelectedRows = $(this).getGridParam('selarrrow');
//Store any selected rows
$(this).data(current_page, saveSelectedRows);
},
loadBeforeSend:function(){
//set current page
current_page = $(this).getGridParam('page').toString();
}
Function get multi select Values array
function getSelectedValues(){
var saveSelectedRows = $("#YourGrid").getGridParam('selarrrow');
$("#YourGrid").data(current_page, saveSelectedRows);
var retrieveSelectedRows = $("#YourGrid").data();
var arr_values = new Array();
if (retrieveSelectedRows) {
$.each(retrieveSelectedRows, function (index, value) {
$.each(value, function (index, sub_value) {
if(typeof(sub_value)=='string')
arr_values.push(sub_value);
});
});
}
return arr_values;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With