-
Data Grid
- Overview
-
Data Binding
-
Paging and Scrolling
-
Editing
-
Grouping
-
Filtering and Sorting
- Focused Row
-
Row Drag & Drop
-
Selection
-
Columns
- State Persistence
-
Appearance
-
Templates
-
Data Summaries
-
Master-Detail
-
Export to PDF
-
Export to Excel
-
Adaptability
- Keyboard Navigation
-
Pivot Grid
- Overview
-
Data Binding
-
Field Chooser
-
Features
-
Export to Excel
-
Tree List
- Overview
-
Data Binding
- Sorting
- Paging
-
Editing
- Node Drag & Drop
- Focused Row
-
Selection
-
Filtering
-
Column Customization
- State Persistence
- Adaptability
- Keyboard Navigation
-
Scheduler
- Overview
-
Data Binding
-
Views
-
Features
- Virtual Scrolling
-
Grouping
-
Customization
- Adaptability
-
Html Editor
-
Chat
-
Diagram
- Overview
-
Data Binding
-
Featured Shapes
-
Custom Shapes
-
Document Capabilities
-
User Interaction
- UI Customization
- Adaptability
-
Charts
- Overview
-
Data Binding
-
Area Charts
-
Bar Charts
- Bullet Charts
-
Doughnut Charts
-
Financial Charts
-
Line Charts
-
Pie Charts
-
Point Charts
-
Polar and Radar Charts
-
Range Charts
-
Sparkline Charts
-
Tree Map
-
Funnel and Pyramid Charts
- Sankey Chart
-
Combinations
-
More Features
-
Export
-
Selection
-
Tooltips
-
Zooming
-
-
Gantt
- Overview
-
Data
-
UI Customization
- Strip Lines
- Export to PDF
- Sorting
-
Filtering
-
Gauges
- Overview
-
Data Binding
-
Bar Gauge
-
Circular Gauge
-
Linear Gauge
-
Navigation
- Overview
- Accordion
-
Menu
- Multi View
-
Drawer
-
Tab Panel
-
Tabs
-
Toolbar
- Pagination
-
Tree View
- Right-to-Left Support
-
Layout
-
Tile View
- Splitter
-
Gallery
- Scroll View
- Resizable
-
-
Editors
- Overview
- Autocomplete
-
Calendar
- Check Box
- Color Box
- Date Box
-
Date Range Box
-
Drop Down Box
-
Number Box
-
Select Box
- Switch
-
Tag Box
- Text Area
- Text Box
- Validation
- Custom Text Editor Buttons
- Right-to-Left Support
- Editor Appearance Variants
-
Forms and Multi-Purpose
- Overview
- Button Group
- Field Set
-
Filter Builder
-
Form
- Radio Group
-
Range Selector
- Numeric Scale (Lightweight)
- Numeric Scale
- Date-Time Scale (Lightweight)
- Date-Time Scale
- Logarithmic Scale
- Discrete scale
- Custom Formatting
- Use Range Selection for Calculation
- Use Range Selection for Filtering
- Image on Background
- Chart on Background
- Customized Chart on Background
- Chart on Background with Series Template
- Range Slider
- Slider
-
Sortable
-
File Management
-
File Manager
- Overview
-
File System Types
-
Customization
-
File Uploader
-
-
Actions and Lists
-
Maps
- Overview
-
Map
-
Vector Map
-
Dialogs and Notifications
-
Localization
Tree List - Node Drag & Drop
The TreeList allows users to drag and drop nodes. Use the icons in the leftmost column as the drag handles.
If you have technical questions, please create a support ticket in the DevExpress Support Center.
<div id="treeListDemo">
@(Html.DevExtreme().TreeList()
.ID("treeList")
.DataSource(new JS("employees"))
.KeyExpr("ID")
.ParentIdExpr("Head_ID")
.ExpandedRowKeys(new JS("[1]"))
.ShowRowLines(true)
.ShowBorders(true)
.ColumnAutoWidth(true)
.RowDragging(rd => rd
.AllowDropInsideItem(true)
.AllowReordering(true)
.OnDragChange("onDragChange")
.OnReorder("onReorder")
.ShowDragIcons(true)
)
.Columns(columns => {
columns.Add().DataField("Title")
.Caption("Position");
columns.Add().DataField("Full_Name");
columns.Add().DataField("City");
columns.Add().DataField("State");
columns.Add().DataField("Mobile_Phone");
columns.Add().DataField("Hire_Date")
.DataType(GridColumnDataType.Date);
})
)
<div class="options">
<div class="caption">Options</div>
<div class="options-container">
<div class="option">
@(Html.DevExtreme().CheckBox()
.ID("allowDropInside")
.Text("Allow Drop Inside Item")
.Value(true)
.OnValueChanged(@<text>
function(e) {
getTreeList().option("rowDragging.allowDropInsideItem", e.value);
}
</text>)
)
</div>
<div class="option">
@(Html.DevExtreme().CheckBox()
.ID("allowReordering")
.Text("Allow Reordering")
.Value(true)
.OnValueChanged(@<text>
function(e) {
getTreeList().option("rowDragging.allowReordering", e.value);
}
</text>)
)
</div>
<div class="option">
@(Html.DevExtreme().CheckBox()
.ID("showDragIcons")
.Text("Show Drag Icons")
.Value(true)
.OnValueChanged(@<text>
function(e) {
getTreeList().option("rowDragging.showDragIcons", e.value);
}
</text>)
)
</div>
</div>
</div>
</div>
<script>
function onDragChange(e) {
var treeList = e.component,
visibleRows = treeList.getVisibleRows(),
sourceNode = treeList.getNodeByKey(e.itemData.ID),
targetNode = visibleRows[e.toIndex].node;
while(targetNode && targetNode.data) {
if(targetNode.data.ID === sourceNode.data.ID) {
e.cancel = true;
break;
}
targetNode = targetNode.parent;
}
}
function onReorder(e) {
var visibleRows = e.component.getVisibleRows();
if (e.dropInsideItem) {
e.itemData.Head_ID = visibleRows[e.toIndex].key;
} else {
var sourceData = e.itemData,
toIndex = e.fromIndex > e.toIndex ? e.toIndex - 1 : e.toIndex,
targetData = toIndex >= 0 ? visibleRows[toIndex].node.data : null;
if (targetData && e.component.isRowExpanded(targetData.ID)) {
sourceData.Head_ID = targetData.ID;
targetData = null;
} else {
sourceData.Head_ID = targetData ? targetData.Head_ID : e.component.option('rootValue');
}
var sourceIndex = employees.indexOf(sourceData);
employees.splice(sourceIndex, 1);
var targetIndex = employees.indexOf(targetData) + 1;
employees.splice(targetIndex, 0, sourceData);
}
e.component.refresh();
}
function getTreeList() {
return $("#treeList").dxTreeList("instance");
}
</script>
<script src="~/Scripts/data/employees.js"></script>
xxxxxxxxxx
xxxxxxxxxx
xxxxxxxxxx
To configure node drag and drop, follow these steps:
-
Allow users to reorder nodes
In the rowDragging object, set the allowReordering property to true. You can use the "Allow Reordering" checkbox under the TreeList to try this property. -
Allow users to change the node hierarchy
Enable the allowDropInsideItem property to allow users to drop one node onto another, thus adding it as the target node's child. If the property is disabled, users can only drop nodes in between others. You can use the "Allow Drop Inside Item" checkbox under the TreeList to try this property. -
Reorder nodes in code
In the onReorder function, change the parent ID of the reordered node and the node's index in the data array. If the node was dropped onto another node, changing the parent ID is sufficient. Refresh() the TreeList after these manipulations. -
Prevent a node from being moved inside its child node
Moving a parent node inside its own child node breaks the hierarchy. Prevent this situation in the onDragChange function. Cycle through the target node's parents. If the parent's and source node's IDs are equal,cancel
the ability to drop the node. -
Show or hide drag icons (optional)
Users use the icons as drag handles. To hide them, set the showDragIcons property to false. In this case, the drag handles are the rows themselves. Use the "Show Drag Icons" checkbox under the TreeList to try this property.