React TreeList - Column Reordering

User Interaction

Set the allowColumnReordering property to true to allow a user to reorder columns. If a specific column should not be moved, set its allowReordering property to false.

App.js
  • import React from 'react';
  •  
  • import 'devextreme/dist/css/dx.light.css';
  •  
  • import TreeList, {
  • Column
  • } from 'devextreme-react/tree-list';
  •  
  • export default function App() {
  • return (
  • <TreeList ...
  • allowColumnReordering={true}>
  • <Column dataField="CompanyName" allowReordering={false} />
  • </TreeList>
  • );
  • }

View Demo

API

The columns array determines columns' order. You can reorder columns by moving their objects within the array or by changing the column's visibleIndex if you prefer to configure columns using the customizeColumns function.

App.js
  • import React from 'react';
  • import 'devextreme/dist/css/dx.light.css';
  • import TreeList from 'devextreme-react/tree-list';
  •  
  • const customizeColumns = (columns) => {
  • columns[2].visibleIndex = 1;
  • };
  •  
  • export default function App() {
  • return (
  • <TreeList ...
  • customizeColumns={customizeColumns}>
  • </TreeList>
  • );
  • }

The visibleIndex property can also be changed at runtime to reorder columns regardless of the way you configured them. For this, call the columnOption(id, optionName, optionValue) method. The following code swaps the second and first column:

App.js
  • import React, { useRef } from 'react';
  • import 'devextreme/dist/css/dx.light.css';
  • import TreeList from 'devextreme-react/tree-list';
  •  
  • export default function App() {
  • const treeList = useRef(null);
  • const swapColumns = () => {
  • treeList.current.instance().columnOption(1, 'visibleIndex', 0);
  • };
  •  
  • return (
  • <TreeList ref={treeList}>
  • {/* ... */ }
  • </TreeList>
  • );
  • }
See Also