Rich Tree View - Ordering
Let users drag and drop items in the Tree View to reorder them.
Enable drag-and-drop reordering
You can enable the drag-and-drop reordering of items by setting the itemsReordering prop to true:
- @mui/x-data-grid
- @mui/x-data-grid-pro
- @mui/x-date-pickers
- @mui/x-date-pickers-pro
- Charts
- Tree View
Limit reordering
By default, all items are reorderable.
You can prevent reordering of specifc items using the isItemReorderable prop.
The following example shows how to only let users reorder the leaves using the getItemOrderedChildrenIds() API method.
- @mui/x-data-grid
- @mui/x-data-grid-pro
- @mui/x-date-pickers
- @mui/x-date-pickers-pro
- Charts
- Tree View
You can also limit the items in which an item can be dropped using the canMoveItemToNewPosition prop.
The following example shows how to only let users reorder inside the same parent:
- @mui/x-data-grid
- @mui/x-data-grid-pro
- @mui/x-date-pickers
- @mui/x-date-pickers-pro
- Charts
- Tree View
React to an item reordering
You can use the onItemPositionChange to send the new position of an item to your backend:
- @mui/x-data-grid
- @mui/x-data-grid-pro
- @mui/x-date-pickers
- @mui/x-date-pickers-pro
- Charts
- Tree View
No reorder registered yet
If you want to send the entire dataset to your backend, you can use the getItemTree() API method.
The following demo demonstrates it by synchronizing the first RichTreeView with the second one whenever you perform a reordering:
- @mui/x-data-grid
- @mui/x-data-grid-pro
- @mui/x-date-pickers
- @mui/x-date-pickers-pro
- Charts
- Tree View
- @mui/x-data-grid
- @mui/x-data-grid-pro
- @mui/x-date-pickers
- @mui/x-date-pickers-pro
- @mui/x-charts
- @mui/x-tree-view
Customization
Only trigger reordering from a drag handle
You can create a custom TreeItem component to render a drag handle icon and only trigger reordering when dragging from it:
- Data Grid
- @mui/x-data-grid
- @mui/x-data-grid-pro
- Date and Time Pickers
- @mui/x-date-pickers
- @mui/x-date-pickers-pro
- Charts
- Tree View
Common examples
File explorer
The example below is a simplified version of the file explorer example with drag-and-drop reordering. You can reorder items but only inside folders (or inside the trash).
Documents
Company
Invoice
Meeting notes
Tasks list
Equipment
Video conference
Personal
Group photo
Bookmarked
History
Trash
API
See the documentation below for a complete reference to all of the props and classes available to the components mentioned here.