Sorting at Runtime

  • 2 minutes to read

Sorting at Runtime

To sort data against a Tree List's column, or to change the column's sort order, an end-user can click its column header. The column's current sort order is indicated by the sort glyph (a small arrow displayed on the right edge of the column header). If the data is sorted in ascending order, the sort glyph represents an up-arrow. When sorting in descending order the sort glyph is displayed as a down-arrow. If the column isn't sorted, the sort glyph is hidden.

In the following image, data is sorted against the Department column in ascending order and against the Budget column in descending order.

Implementing Sorting_1

If sorting isn't applied, clicking the column header sorts the data in ascending order by the column's contents. If sorting is already applied to the column, subsequent clicks reverse the current sort order. Note that a regular click on a column header clears the sort settings of any other columns. To preserve the existing sort settings of other columns, hold the SHIFT key down while clicking. This can be useful when you need to apply sorting to multiple columns at the same time. You can clear a column's sorting by clicking its header while holding the CTRL key down.

You can also apply sorting to columns via the column header context menu:

Implementing Sorting_ContextMenu

This availability of this menu is controlled by the Tree List's TreeListOptionsMenu.EnableColumnMenu property. You can also customize the menu's content as described in the Context Menus section.

Each column has an TreeListOptionsColumn.AllowSort property, which specifies whether an end-user can sort data against this column. The sort order, however, can always be changed in code.