Forum
21:38
20/01/2009
Hi,
I wanted to be able to remember the selected rows (multiselect: true) when navigating the grid, I coded the following, which work fine when paginating (first, prev, next, last) and sorting, but doesn't work when changing the "number of requested rows" (select box):
//-----[2 global variables]
/**
* @var array - currently selected rowids
*/
var selectedRowIds = new Array();
/**
* @var bool - set to false in method gridComplete
* to "disable" method onSelectRow
* while it "setSelection" the currently
* selected rowids.
*/
var enableOnSelectRow = true;
//-----[2 jqgrid methods]
/**
* If selected rowid, push it onto "selectedRowIds",
* If deselected rowid, remove it from "selectedRowIds"
*/
onSelectRow: function(rowid, selected) {
if ( ! enableOnSelectRow ) {
return;
}
if ( selected ) {
selectedRowIds.push(rowid);
return;
}
for( var i in selectedRowIds ) {
if ( rowid === selectedRowIds[i] ) {
selectedRowIds.splice(i, 1);
break;
}
}
},
/**
* Iterate over "selectedRowIds" calling
* "setSelection"
*/
gridComplete: function() {
enableOnSelectRow = false;
for ( var i in selectedRowIds ) {
$('#list').setSelection(selectedRowIds[i]);
}
enableOnSelectRow = true;
},
If you select some rows and paginate or sort, everything is fine, the selected rows are preserved. If you change the "number of requested rows" (select box), you lose the selected rows until another pagination or sorting is done. Somehow, the "gridComplete" method seams to behave differently when invoked after a "number of requested rows" change, as opposed to a pagination/sorting invocation.
Thank you very much for your help.
Steph
09:07
Moderators
30/10/2007
Hello,
You can use getGridParam('selarrrow') to get selected rows when in multiselect mode and use onPaging event (which is raised before populate) to store the selected rows
Regards
Tony
For professional UI suites for Java Script and PHP visit us at our commercial products site - guriddo.net - by the very same guys that created jqGrid.
21:00
20/01/2009
Hi Tony,
Thanks for your reply, using onPaging and getGridParam('selarrrow') is the way to go for remembering selected rows, but it doesn't solve the transient problem when changing the number of rows displayed (e.g. say passing from 10 to 20 rows). The following is a workaround solving the problem (Do a “setSelection”, make sure it's selected, if not, do a “setSelection” again:
onPaging: function() {
var rows = $('#list').getGridParam('selarrrow');
for ( var i in rows ) {
if ( ! array_search(rows[i], selectedRowIds) ) {
selectedRowIds.push(rows[i]);
}
}
},
gridComplete: function() {
for ( var i in selectedRowIds ) {
$('#list').setSelection(selectedRowIds[i]);
/**
* Workaround: Make sure it's selected, if not, select the row again.
*/
if ( ! array_search(selectedRowIds[i], $('#list').getGridParam('selarrrow')) ) {
$('#list').setSelection(selectedRowIds[i]);
}
}
},
array_search (equivalent of PHP one, c.f. http://kevin.vanzonneveld.net).
Anyway, it's working with this workaround, but as I wrote in my first message, gridComplete seams to behave differently right after a change in the number of rows displayed (as long as the setSelection function is concerned).
Thanks again Tony for you reply and for this great plugin.
Regards,
Steph
Most Users Ever Online: 715
Currently Online:
69 Guest(s)
Currently Browsing this Page:
1 Guest(s)
Top Posters:
OlegK: 1255
markw65: 179
kobruleht: 144
phicarre: 132
YamilBracho: 124
Renso: 118
Member Stats:
Guest Posters: 447
Members: 11373
Moderators: 2
Admins: 1
Forum Stats:
Groups: 1
Forums: 8
Topics: 10592
Posts: 31289
Newest Members:
, razia, Prankie, psky, praveen neelam, greg.valainis@pa-tech.comModerators: tony: 7721, Rumen[Trirand]: 81
Administrators: admin: 66