Sorting

Problem

While using the components that operate on data, such as grid, list or chart, you often need to implement sorting.

Solution

Dataset sorting consists in the method sort() (see details in the corresponding chapter of the manual).

And can be implemented in two ways:

  1. By using built-in means.
  2. By using custom functions.

Using built-in sorting means

There are three predefined sorting expressions:

  • int.
  • string.
  • string_strict (case-sensitive 'string').
$$('mylist').sort({
		    by:"#year#",
		    dir:"asc",
		    as: "int"
});

Using custom sorting functions

A sorting method is defined by a function. This function is called for each pair of values and returns 1,-1 or 0:

  • 1 - an object with the first value in pair must go before the second one.
  • -1 - the second object goes before the first.
  • 0 - the order of both objects doesn't change.
$$('mylist').sort({
                    by:"#time#",
                    dir:"asc",
                    as: sortTime
})
function sortTime(a,b){ ... }

Related sample: 04_list/13_sorting.html