Forum


16:33

24/07/2012

I'm trying to create a grid with sortable columns using jqGrid 4.4.0. The code is below
var selectedRowId = null;
$('#grid2').jqGrid({
localReader: { id: '_id' },
datatype: 'local',
height: 'auto',
colNames: ['id', 'Full Name', 'Short Name'],
autowidth: true,
shrinkToFit: true,
multiselect: false,
deselectAfterSort: false,
colModel: [
{ name: '_id', index: '_id', hidden: true, key: true },
{ name: 'name', index: 'name', width: 600, sortable: true },
{ name: 'shortName', index: 'shortName', width: 600, sortable: false }
],
data: [
{ _id: 1, name: 'Institution', shortName: 'I.1' },
{ _id: 2, name: 'Institution 1.1', shortName: 'I.1.1' },
{ _id: 3, name: 'One more institution 1.2', shortName: 'I.1.2' },
{ _id: 4, name: 'Institution 1.2.1', shortName: 'I.1.2.1' },
{ _id: 6, name: 'Institution deep down', shortName: 'I.1.2.1' },
{ _id: 5, name: 'A long long institution name', shortName: 'I.2' }
],
onSelectRow: function(rowid, status) {
selectedRowId = rowid;
},
onSortCol: function(index, iCol, sortorder) {
if (selectedRowId) {
setTimeout(function() {
$('#grid2').jqGrid('resetSelection');
$('#grid2').jqGrid('setSelection', selectedRowId, false);
}, 300);
}
}
});
});
The problem is that when the grid is sorted, the selected row is not highlighted any more. At the same time the grid itself still thinks the row is still selected (onSelectRow fires with status 'false' if I click on it), and this is very conufusing for the user.
I've implemented a workaround to remember the selection and restore it programmatically after sort, however it relies on setTimeout (without it setSelection has no effect) which makes it pretty much ugly. Is there a better way to support both sorting and selection?
Most Users Ever Online: 715
Currently Online:
24 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