While using the components that operate on data, such as grid, list or chart, you often need to implement sorting.
The parameter, which answers for built-in component sorting, is 'sort'.
It has the following attributes:
sort{ by:"#sales#", dir:"asc", as:"int" }
There are three defined sorting methods: int, string and string_strict. If neither of these methods is appropriate, you may set a new one. A sorting method is defined by a function. This function is called for each pair of values and returns 1,-1 or 0:
For example, if we need to sort by time property that consists of minutes and seconds divided by ”:” than the following custom sorting can be used:
dhx.ui({ ... sort({ by:"#time#", dir:"asc", as: "sortTime" }), ... }) function sortTime(a,b){ a = a.split(":"); b = b.split(":"); if(a[0] > b[0]) return 1; else if(a[0] < b[0]) return -1; else{ if(a[1] > b[1]) return 1; else if(a[1] < b[1]) return -1; return 0; } }