Sorting rows / columns
FastGrid documentation
If sorting is permitted, &
1 - sorting rows, &
2 - sorting columns.
Comma separated string or array of column ids to sort rows by values in these columns. Or row ids to group columns by values in these rows.
Default direction is ascent sorting. For
descent sorting pass the column/row id with prefix "-". Like Sort:"A,-B,-C,D".
Row or column id to sort by it as the last one, to preset sort order even if no sort or not enough is set.
Or it can be set to
1 to set default sort to original order on data load.
Or it can be set to
2 to set default sort to original order on data load and update it also on add / move row / column.
By default it is set to
2 in Body part and null in all other parts.
If set, show sort icon also for the
DefaultSort column / row as the last one.
If set, restricts sorting rows by values in this column or sort columns by values in this row.
Set to column / row that's cells are used for sorting.
Row, Col string
SortPart
["DefRowPart" / "DefColPart" / ""] GetAttr SetAttr
Comma separated string or array of part ids that's sorting is affected by this row or column.
The item can be set also to
"DefRowPart" as
DefRowPart or
"DefColPart" as
DefColPart.
By default it is
"DefRowPart" in Header rows,
"DefColPart" in Header columns and empty in all other rows and columns.
Set to header row / column that is used to change sorting.
If and how the row shows icons for sorting rows or the column shows icons for sorting columns.
0 - does not show any sort icon and does not sort on click to this row / column.
1 - shows only active sort icons on the right side,
2 - next to the text,
3 - on the left side.
4 - does not show any sort icon, but sorts the rows / columns on click.
5 - shows all sort icons on the right,
6 - next to the text,
7 - on the left side.
8 -
reserved
9 - shows only active sort icons on the right side and updates the column width after show / hide the icon,
10 - next to the text,
11 - on the left side.
By default it is
10 in Header rows,
11 in Header columns and
0 in all other rows and columns.
Set to header row / column that is used to change sorting.
How the sorting icons are shown / active globally:
0 | Simple, hidden icons | Icons are not shown, click to the whole cell changes sorting to ascending or descending. |
1 | Simple | Click to the whole cell changes sorting to ascending or descending. |
2 | Simple, icons only | Only click to the icon changes sorting to ascending or descending. Forces showing sort icons in the headers. |
3 | Directional | Click to the whole cell changes sorting, click to cell top (or left) half changes sorting ascending, click to cell bottom (or right) half changes sorting descending. |
4 | Directional, icons only | Only click to the icon changes sorting, click to icon top (or left) half changes sorting ascending, click to icon bottom (or right) half changes sorting descending. Forces showing sort icons in the headers. |
How many pixels can be sort icon overflown from both sides to not cut the cell text too much. It is subtracted from PaddingLeft/Right and IconPaddingLeft/Right.
It can be set to cell in row with
SortIcons (usually Header row cell) to sort by different column than this one. Set it to empty string to not sort by this cell at all.
It can be set to cell in column with
SortIcons (usually Header column cell) to sort by different row than this one. Set it to empty string to not sort by this cell at all.
If set, reverses the sort icons arrows and shows arrow up (or left) for descending order and arrow down (or right) for ascending order.
How the sort changes when clicked cell in header row / column.
The clicked cell (column / row) is set to sorting as:
0 - as the only one - permits sorting only by one column / row, should be used in combination with other types.
1 - as the first one.
2 - as the last one - cannot remove the already chosen column / rows, should be used in combination with other types.
3 - as the last one if clicked within 2 second, otherwise as the only one.
The sort type can set also in
SortClick action as the fourth parameter to combine more types on different clicks.
By default on normal click uses the
SortType (default
1), on ctrl+click uses sort type
3 and on shift+click uses sort type
2.
Maximal count of columns / rows to sort by.
There are defined only
9 sorting icons, so for setting MaxSort > 9 is required to define the rest icons in
Icons array.
Set it to 1 to permit the only sorted column.
Comma separated string or array of items shown in Sort menu. Set it to "" to not show the menu. It can contain "-" item as separator. Case sensitive. It can contain these keywords:
Locale (
SortLocaleCompare, ignore diacritics, switches only between 0 / 2 values),
White (
SortWhiteChars, ignore white space),
Case (
SortCaseSensitive, turn on case sensitive search),
Icons (
SortIcons, if and how sort icons in header behave),
Reversed (
ReversedSortIcons, shows the arrows up for descending sort),
Type (
SortType, how processes clicks to the next sort columns),
Max (
MaxSort, maximum sorting columns 1 - 9).
Tool string
D
= "ClearSort"
Default toolbar cell to show ClearSort icon to clear actual sorting
Click to the icon clears actual sorting and optionally sorts the parts by
DefaultSort, if defined.
Click to the popup icon shows sorting options defined by
SortMenu.
Actions
SortClick
(int target = 0, bool direction = 0, bool cols = 0, int sorttype = SortType)
many OnClickSort... actions
Adds actual / focused column to sorting assigned to actual / focused row (for
cols =
0).
Or adds actual / focused row to sorting assigned to actual / focused column (for
cols =
1).
direction is
0 for ascending sort,
1 for descending.
For null it changes direction if the column/row is already in sorting, otherwise uses ascending sort.
It can be run asynchrounsly when applied SyncRows.
Grid method void
SortClick
(Row / Col row, Col / Row col, bool direction = 0, int sorttype = SortType)
Adds column
col to sorting assigned to row
row or adds row
col to sorting assigned to column
row
direction is
0 for ascending sort,
1 for descending.
For null it changes direction if the column/row is already in sorting, otherwise uses ascending sort.
It can be run asynchrounsly when applied SyncRows.
Grid method object
GetSort
(string part = null, int object = 0, bool nodefault = 0)
Returns actual sorting for given
part.
part can be comma separated string or array of part ids.
If
part is not set, returns the first not null value of
Sort value in any part.
For
object =
0 returns comma separated string.
For
object =
1 returns array as [col1,desc1,col2,desc2,...].
For
object =
2 returns object as {col1:1/-1,col2:2/-2,col3:3/-3,...}.
For
object =
3 returns object like
2 and for no sort returns empty object instead of null.
For
nodefault = 1 does add
DefaultSort.
Grid method void
SetSort
(string sort = null, string part = null)
Sets or clears the sorting for given
part.
part can be comma separated string or array of part ids.
If
part is not set, sets Sort value of parts that's are referred by some
SortPart and are applicable for given
sort.
sort can be comma separated string or array of column / row ids to sort by.
If
sort is empty string or null, clears the sorting for given
part.
Resorts the part(s) even if
sort is the same as actual sort.
It can be run asynchrounsly when applied SyncRows.
Grid method void
ReSort
(string part = null)
Sorts given
part again without changing the settings.
part can be comma separated string or array of part ids.
If
part is not set, re-sorts all parts with
Sort or
DefaultSort set.
Actions
ClearSort
(int target = 0, string part = null)
OnClickClearSort
Clears
Sort in the parts
part (comma separated string or array of part ids) and resorts them by
DefaultSort if set.
For
part = null / 3 clears all parts, for
1 clears all row parts, for
2 clears all column parts.
API event bool
OnSort
(Grid grid, string part, string sort)
Called before the grid part is sorted.
part is the part id
id,
sort is comma separated string with new sorting, it can be empty string for sort by
DefaultSort.
Return true to not sort the part.
If called the OnGroup, the OnSort is not called when sorting after the grouping is done.
API event void
OnSorted
(Grid grid, string part, string group, string oldgroup, Row first, Row last)
Called after the grid part is grouped and sorted.
part is the part id
id,
sort is comma separated string with new sorting, it can be empty string for sort by
DefaultSort.
If called the OnGrouped, the OnSorted is not called when sorting after the grouping is done.
Sorting settings
If the row or column children are removed from sorting - the immediate children are not sorted, but their children can be sorted.
Set to row / column being sorted.
Fixes the row or column on the part edge, regardless on sorting.
Positive value fixes the row on part top or the column on part left, the higher value the closer the edge.
Negative value fixed the row on part bottom or the column on part right, the smaller value the closer the edge.
Set to row / column being sorted.
Value used instead of cell value for grouping and sorting.
Set to row / column cell being sorted.
How to sort numbers:
0 - string sort: 1, 15, 16xx, 2, 200, 23xx, 3, 30,...
1 - number sort: 1, 2, 3, 15, 30, 200, 16xx, 23xx..., the strings that cannot be converted to number are sorted at the end.
2 - date sort: converts dates set as date strings to number of milliseconds and sorts these numbers.
3 - number range sort: if value is range of numbers, sorts according to the first number in the range like in
1.
4 - date range sort: if value is range of dates, sorts according to the first date in the range like in
2.
null - uses
0 string sort for column / row Type = "String", "Html" and "Auto",
1 number sort for Type = "Bool", "Number" and
2 date sort for Type = "Date".
Set to column / row that's cells are used for sorting.
If set to
1, uses for sorting the values from
List, if defined.
Slows down the sorting.
If set to
2, uses for sorting and grouping the values from
List, if defined.
Slows down the sorting and grouping.
If not set, ignores the list and uses always the raw cell value for sorting and grouping.
Specifies sorting algorithm. Try to change it if native sort is too slow for some large data.
0 - Native sort,
1 - Merge sort recursive,
2 - Quick insertion sort non recursive,
3 - Quick sort recursive,
4 - Heap sort recursive.
Comparing strings
If the strings in sorting are compared as case sensitive.
Used only if the row, column has not set the CaseSensitive attribute.
If the strings are compared as case sensitive.
The case sensitive sorting differs according to the
LocaleCompare, if set, sorts aAbBcC, if not set, sorts as Unicode ABCabc.
For sorting and grouping it can be set only to row or column, for filtering it can be set also to filter cell and for generated List by *Rows / *Cols also to the cell with the List.
If set, compares strings in sorting according to locale meaning.
Used only if the row, column has not set the LocaleCompare attribute.
0 | a<b<á | according to unicode |
1 | a<á<b | according to default locale |
2 | a==á<b | according to default locale |
"locale" | a<á<b | according to specified locale (e.g. "en-US" or "cs-CZ") |
"=locale" | a==á<b | according to specified locale (e.g. "=en-US" or "=cs-CZ") |
If set, compares strings according to locale meaning.
0 | a<b<á | according to unicode |
1 | a<á<b | according to default locale |
2 | a==á<b | according to default locale |
"locale" | a<á<b | according to specified locale (e.g. "en-US" or "cs-CZ") |
"=locale" | a==á<b | according to specified locale (e.g. "=en-US" or "=cs-CZ") |
For sorting and grouping it can be set only to row or column, for filtering it can be set also to filter cell and for generated List by *Rows / *Cols also to the cell with the List.
List of characters to ignore when comparing strings for sorting.
Used only if the row, column has not set the WhiteChars attribute.
It can be set for example to " " (space) to ignore spaces (it means that for example "a b c" and "abc" strings are the same.
If starts by "-", it is ignored, but can be turned on in
SortMenu.
List of characters to ignore when comparing strings.
It can be set for example to " " (space) to ignore spaces (it means that for example "a b c" and "abc" strings are the same.
For sorting and grouping it can be set only to row or column, for filtering it can be set also to filter cell and for generated List by *Rows / *Cols also to the cell with the List.
It changes characters in comparing strings.
It is first character separated array of pair of characters to replace the first character by the second one when comparing strings.
For example "|y|i|Y|I|.|," - replaces 'y' by 'i', 'Y' by 'I' and '.' by ','
- it means that when comparing strings does not differ between letter 'y' and 'i', both cases and also does not differ between comma and point.
The first character must be one letter, but the second in fact can be any letter or string or even empty string, like "|a|xxx|b||c|ff".
For sorting and grouping it can be set only to row or column, for filtering it can be set also to filter cell and for generated List by *Rows / *Cols also to the cell with the List.
If set, removes all HTML code when comparing strings during sorting, grouping and filtering.
For sorting and grouping it can be set only to row or column, for filtering it can be set also to filter cell and for generated List by *Rows / *Cols also to the cell with the List.