Sort - method of the PmArray object
Description:
Allows alphabetical or numeric sorting of 1-dimensional array or 2-dimensional array. The column order can be defined for sorting of 2-dimensional arrays.
Syntax:
Empty Sort(String sType)
Parameters:
sType | (String) - 1-dimensional array: "tn" - numeric ascending "tn+r" - numeric descending "ts" - alphabetic ascending (case sensitive text) "ts+r" - alphabetic descending (case sensitive text) "tsi" - alphabetic ascending (i = case insensitive text) "tsi+r" - alphabetic descending (i = case insensitive text) - 2-dimensional array: "c0+tn" - sorting by 1st (zero) column, numeric, ascending "c0+ts" - sorting by 1st (zero) column, alphabetic, ascending (case sensitive text) "c0+tsi" - sorting by 1st (zero) column, alphabetic, ascending (i = case insensitive text) The order and sorting method can be easily combined, for example: "c1+ts,c0+tn+r". The resulting array will then be sorted by the second column alphabeticaly ascending and identical items will then be sorted by numeric values of the first column descending. |
---|
Note:
This method is also functional in
Web panels.
If some sorted values are identical then their order in the array cannot be guaranteed.
Example1:
Sorting the 1-dimensional array numericaly, ascending
JavaScriptSelect and copy to clipboard
var arr = Pm.CreatePmArray().Array1(0.5, 0.1, 123, -3, -1, 0, 0.8, 0.2);
arr.Sort("tn");
//the array will be sorted as follows: -3, -1, 0, 0.1, 0.2, 0.5, 0.8, 123
Example2:
Sorting the 1-dimensional array alphabeticaly, ascending
JavaScriptSelect and copy to clipboard
var arr = Pm.CreatePmArray().Array1("Madrid", "Berlin", "Atheny", "Praha", "Warszava", "Paris", "Vien", "Roma");
arr.Sort("ts");
//the array will be sorted as follows: "Atheny, Berlin, Madrid, Paris, Praha, Roma, Vien, Warszava"