JQGrid Custom Sorting

In your grid you have 5 column which are visible and sortable: ‘RoleLookupName’, ‘FullName’, ‘Entity’, ‘ContactInformation’, ‘DNumber’. After the loading of grid data from the server the datatype will be changed from 'json' to 'local' corresponds the behavior of the parameter loadonce: true. From now the sorting will be work locally. Because you don’t define sorttype property in any column the default sorttype: 'text' will be used.

How I understand the data in columns ‘RoleLookupName’, ‘Entity’ and so on can contain duplicates, so you would like to sort the grid by combination of the main sorting column (like ‘RoleLookupName’ for example) and the second column (‘FullName’ for example). In the case of duplicates in the main sorting column the grid will be still sorted by the second criteria from the second column. To implement the behavior you should use custom sorting. You can implement it by the usage of sorttype as function (see the answer).

The idea of sorttype as function is easy. The sorttype should return string or integer which should be used instead of the main cell contain. For example you can define ‘RoleLookupName’ as following

{ name: 'RoleLookupName', index: 'RoleLookupName',
    sorttype: function (cell, obj) {
        return cell + '_' + obj.FullName;
    }}

Another answer which includes the demo could you find probably also interesting for understanding. It demonstrates even more advanced technique where it is implemented not only custom sorting, but also custom searching.

Leave a Comment