LyteNyte Grid logo for light mode. Links back to the documentation home page.
Tree Data

Tree Sorting

Sort tree rows in ascending or descending order by providing a single sort function or an array of sort dimensions to the hook.

Note

Tree data sorting provides the same capabilities as client row sorting. Review the Client Row Sorting guide before proceeding.

Sort Function

In the tree data source, the sort function compares two row nodes. Each node is a group row node unless it’s pinned.

The demo below shows basic sorting. Click Sort: Size to sort rows by Size in descending order.

Tree Sort Function

Fork code on stack blitzFork code on code sandbox

Sort Dimensions

You can set the sort property to an array of DimensionSort objects. Each dimension sort uses the field property of a column to compare rows. A dimension can be applied to sort rows in ascending or descending order.

Since the hook receives an array of DimensionSort objects, LyteNyte Grid can perform a multi-way sort. The tree data source applies the comparators in the order they appear in the provided array, stopping when a comparator result is not 0.

The demo below shows dimension sorting. Click a column header to sort. To sort by multiple columns, hold Control or Command and click additional headers.

Tree Sort Dimensions

Fork code on stack blitzFork code on code sandbox

Next Steps

  • Tree Filtering: Remove tree data rows by providing a custom filter function.
  • Tree Data: Generate hierarchical rows from nested object data.
  • Client Row Sorting: Sort rows in ascending or descending order with the client row source.