sort

sorts data items in a component

void sort(object rule);

Parameters

ruleobjectan object with parameters for sorting

Example

grid.data.sort({
    by:"a",
    dir:"desc",
    as: function(item){
        item.toUpperCase(); 
    }
});
 
// cancels applied sorting rules
grid.data.sort();

Details

The rule object has the following attributes:

  • by - (string) the id of a data field (a column of Grid)
  • dir - (string) the direction of sorting "asc" or "desc"
  • as - (function) a function that specifies the type to sort data as

Calling the method without parameters will discard all applied sorting rules.

Custom sorting

You can also specify the rule attribute in a passed object instead of the default ones and set a custom function for sorting. For example:

grid.data.sort({
    rule: (a, b) => a.id > b.id ? 1 : (a.id < b.id ? -1 : 0) 
});
Back to top