Skip to main content

sort()

sorts controls according to some criteria

sort(rule?: object, config?: object): void;

Parameters:

  • rule?: object - optional, an object with parameters for sorting. The object has the following attributes:
    • by?: string | number - optional, the id of a data field
    • dir?: string - optional, the direction of sorting: "asc" or "desc"
    • as?: function - optional, 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)
  • config?: object - optional, defines the parameter of sorting. It may contain one property:
    • smartSorting?: boolean - optional, specifies whether a sorting rule should be applied each time after changing the data set

Example

component.data.sort(
{
by: "price",
dir: "asc",
as: value => (value || "")
},
{ smartSorting: true }
);

// cancels the applied sorting rules
component.data.sort();
note

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

Custom sorting

To set a custom function for sorting, you need to specify the rule attribute in a passed object. For example:

component.data.sort({
rule: (a,b) => (a.type < b.type) ? -1 : ( (a.type > b.type) ? 1 : 0 )
});

Change log:

The config parameter is added in v9.0.