sorts data items in a component
rule | object | an object with parameters for sorting |
config | object | defines the parameter of sorting |
grid.data.sort({
by:"a",
dir:"desc",
as: function(item){
return item.toUpperCase();
}
});
// cancels applied sorting rules
grid.data.sort();
The rule object has the following attributes:
by | (string) the id of a data field (a column of Grid) |
dir | (function) the direction of sorting "asc" or "desc" |
as | (function) a function that specifies the type to sort data as |
rule | (function) optional, a sorting rule; the function must have two parameters and return a number (-1,0,1) |
Calling the method without parameters will discard all applied sorting rules.
The config parameter may contain one property:
smartSorting | (boolean) specifies whether a sorting rule should be applied each time after changing the data set |
grid.data.sort({
by:"a",
dir:"desc",
as: function(item){
return item.toUpperCase();
},
{
smartSorting: true }
});
To set a custom function for sorting you need to specify the rule attribute in a passed object. For example:
grid.data.sort({
rule: (a, b) => a.id > b.id ? 1 : (a.id < b.id ? -1 : 0)
});
The config parameter is added in v7.0.
Back to top