User Interaction
With the TreeList UI component, a user can sort by single and multiple columns. Use the sorting.mode property to specify the current sorting mode.
- import React from 'react';
- import 'devextreme/dist/css/dx.fluent.blue.light.css';
- import { TreeList, Sorting } from 'devextreme-react/tree-list';
- export default function App() {
- return (
- <TreeList>
- <Sorting mode="single"/> {/* or "multiple" | "none" */}
- </TreeList>
- );
- }
In single mode, the user can click a column header to sort by the column. Subsequent clicks on the same header reverse the sort order. When the user sorts by a column, the sorting settings of other columns are canceled.
In multiple mode, the user clicks a column header while pressing the Shift key to sort by the column. Sorting settings of other columns remain intact.
In both modes, the user can use the column header's context menu to apply sorting. Note that no matter how user applies sorting, rows are sorted within their hierarchical level.

To cancel a column's sorting settings, the user clicks the column's header while pressing Ctrl or uses the context menu:

To disable sorting in the whole UI component, set the sorting.mode property to "none"; to disable sorting only in a specific column, use its allowSorting property.
- import React from 'react';
- import 'devextreme/dist/css/dx.fluent.blue.light.css';
- import { TreeList, Column } from 'devextreme-react/tree-list';
- export default function App() {
- return (
- <TreeList>
- <Column allowSorting={false}/>
- </TreeList>
- );
- }
See Also
Initial and Runtime Sorting
Rows are sorted according to the data source by default. Set the sortOrder property to sort rows in the required order. Specify the sortIndex property as well to sort by multiple columns. Otherwise, each sorted column gets a sort index according to its position in the columns array. For example, the following code sorts rows first by the "Surname", then by the "Name" column:
- import React from 'react';
- import 'devextreme/dist/css/dx.fluent.blue.light.css';
- import { TreeList, Column } from 'devextreme-react/tree-list';
- export default function App() {
- return (
- <TreeList>
- <Column
- dataField="City"
- defaultSortIndex={1}
- defaultSortOrder="asc" />
- <Column
- dataField="Country"
- defaultSortIndex={0}
- defaultSortOrder="asc" />
- </TreeList>
- );
- }
Change the sortOrder and sortIndex properties using the columnOption method to sort at runtime.
- import type { TreeListTypes } from 'devextreme-react/tree-list';
- import React, { useCallback, useState } from 'react';
- import 'devextreme/dist/css/dx.fluent.blue.light.css';
- import { TreeList, Column } from 'devextreme-react/tree-list';
- function App() {
- const [countrySortOrder, setCountrySortOrder] = useState<'asc' | 'desc' | undefined>('asc');
- const sortByCountries = useCallback((order: 'asc' | 'desc') => {
- setCountrySortOrder(order);
- }, []);
- const onOptionChanged = useCallback(
- (e: TreeListTypes.OptionChangedEvent) => {
- if (e.fullName === 'columns[0].sortOrder') {
- sortByCountries(e.value);
- }
- },
- [sortByCountries]
- );
- return (
- <TreeList ... onOptionChanged={onOptionChanged}>
- <Column dataField="Country" sortOrder={countrySortOrder} />
- </TreeList>
- );
- }
- export default App;
Custom Sorting
Implement a custom sorting routine using the calculateSortValue property if standard sorting does not meet your requirements. It accepts the name of the data source field that provides values to be used in sorting...
- import React from 'react';
- import 'devextreme/dist/css/dx.fluent.blue.light.css';
- import { TreeList, Column } from 'devextreme-react/tree-list';
- export default function App() {
- return (
- <TreeList>
- {/* dataField provides values for the column */}
- {/* calculateSortValue provides values to be used in sorting */}
- <Column
- dataField="Position"
- calculateSortValue="isOnVacation" />
- </TreeList>
- );
- }
...or a function that returns such a value.
- import type { TreeListTypes } from 'devextreme-react/tree-list';
- import React, { useCallback } from 'react';
- import 'devextreme/dist/css/dx.fluent.blue.light.css';
- import { TreeList, Column } from 'devextreme-react/tree-list';
- function App() {
- const calculateSortValue = useCallback(function (
- this: TreeListTypes.Column,
- rowData: {
- Position: string;
- }
- ) {
- if (rowData.Position === 'CEO') return this.sortOrder === 'asc' ? 'aaa' : 'zzz';
- return rowData.Position;
- }, []);
- return (
- <TreeList ...>
- <Column
- dataField="Position"
- defaultSortOrder="asc"
- calculateSortValue={calculateSortValue}
- />
- </TreeList>
- );
- }
- export default App;
Clear Sorting Settings
You can clear sorting settings for all columns by calling the clearSorting() method, or for a specific column - by setting its sortIndex property to undefined using the columnOption method.
- import type { TreeListRef } from 'devextreme-react/tree-list';
- import React, { useCallback, useRef } from 'react';
- import 'devextreme/dist/css/dx.fluent.blue.light.css';
- import { TreeList, Column } from 'devextreme-react/tree-list';
- function App() {
- const treeListRef = useRef<TreeListRef>(null);
- const clearNameColumnSorting = useCallback(() => {
- const treeListRefInstance = treeListRef.current?.instance();
- if (!treeListRefInstance) return;
- treeListRefInstance.columnOption('Name', 'sortIndex', undefined);
- }, []);
- const clearAllSorting = useCallback(() => {
- const treeListRefInstance = treeListRef.current?.instance();
- if (!treeListRefInstance) return;
- treeListRefInstance.clearSorting();
- }, []);
- return (
- <TreeList ref={treeListRef} ...>
- <Column dataField="Name" defaultSortIndex={0} />
- </TreeList>
- );
- }
- export default App;