Forum

November 2nd, 2014
A A A
Avatar

Lost password?
Advanced Search

— Forum Scope —




— Match —





— Forum Options —





Minimum search word length is 3 characters - maximum search word length is 84 characters

The forums are currently locked and only available for read only access
sp_Feed Topic RSS sp_TopicIcon
Sorting vs row selection
24/07/2012
16:33
Avatar
MaaKut
New Member
Members
Forum Posts: 1
Member Since:
24/07/2012
sp_UserOfflineSmall Offline

I'm trying to create a grid with sortable columns using jqGrid 4.4.0. The code is below

$(function() {
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?

Forum Timezone: Europe/Sofia

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.com

Moderators: tony: 7721, Rumen[Trirand]: 81

Administrators: admin: 66

Comments are closed.
Privacy Policy   Terms and Conditions   Contact Information