Reputation: 11
Non case-sensitive sorting in dojo dgrid
answer posted by @https://stackoverflow.com/users/237950/ken-franqueiro
grid.on('dgrid-sort', function (event) {
// Cancel the event to prevent dgrid's default behavior which simply
// passes the sort criterion through to the store and updates the UI
event.preventDefault();
// sort is an array as expected by the store API, but dgrid's UI only sorts one field at a time
var sort = event.sort[0];
grid.set('sort', function (a, b) {
var aValue = a[sort.attribute].toLowerCase();
var bValue = b[sort.attribute].toLowerCase();
if (aValue === bValue) {
return 0;
}
var result = aValue > bValue ? 1 : -1;
return result * (sort.descending ? -1 : 1);
});
// Since we're canceling the event, we need to update the UI ourselves;
// the `true` tells it to also update dgrid's internal representation
// of the sort setting, so that toggling between asc/desc will still work
grid.updateSortArrow(event.sort, true);
});
What are the values of a and b variables? In my case I don't want to touch the library file, my event argument has the complete details of the grid, so I wanted to sort the data present in event argument and update the grid, how should I modify the above code?
Upvotes: 1
Views: 39