sort. Sorting table data

^table.sort{function_sorting_by_string}
^table.sort{function_sorting_by_string}[sorting_direction]
^table.sort(function_sorting_by_number)
^table.sort(function_sorting_by_number)[sorting_direction]

The given method sorts the table according to the specified function.

Sorting_function is the function, whose current value determines the position of the row in the final (sorted) variant of the table. This value may be a string (values are compared in alphabetical order) or a number (values are compared as real numbers).

Sorting_direction determines sorting direction. The parameter may have two values:
desc-descending
asc-ascending
Ascending value is used by default.

Example
$men[^table::create{name   age
Sergey   26
Alex   20
Mishk
a   29
}]
^men.sort{$men.
name}
^men.
menu{
    
$men.name: $men.age
}[
<br />]

As the result of this code, the rows of table
$men will be sorted according to the values given in column name:
Alex: 20
Mishka: 29 
Serge
y: 26 

You may sort the table rows by the values given in column
age in descending order (desc) if you substitute the line of the code which is calling method sort for this one:

^men.sort($men.age)[desc]

The code will result in:
Mishka: 29
Sergey: 26
Alex: 20



Copyright © 1997–2021 Art. Lebedev Studio | http://www.artlebedev.com Last updated: 02.03.2011