Loading...
Loading...
Implement hierarchical tree structures with Syncfusion Angular TreeView component. Use this when building tree-based UIs with features like checkboxes, drag-and-drop, node editing, filtering, and templating. This skill covers dynamic data binding, nested hierarchies, folder structures, and interactive tree-based interfaces.
npx skill4agent add syncfusion/angular-ui-components-skills syncfusion-angular-treeviewimport { Component } from '@angular/core';
import { TreeViewModule } from '@syncfusion/ej2-angular-navigations';
import { FormsModule } from '@angular/forms';
@Component({
selector: 'app-tree-view',
standalone: true,
imports: [FormsModule, TreeViewModule],
template: `
<ejs-treeview
id="treeView"
[fields]="treeFields"
[allowMultiSelection]="true">
</ejs-treeview>
`
})
export class TreeViewComponent {
// Hierarchical data structure
treeData = [
{
id: '01',
name: 'Documents',
hasChild: true,
expanded: true,
subChild: [
{ id: '01-01', name: 'Work Files' },
{ id: '01-02', name: 'Personal' }
]
},
{
id: '02',
name: 'Downloads',
hasChild: true,
subChild: [
{ id: '02-01', name: 'Images' },
{ id: '02-02', name: 'Videos' }
]
}
];
// Field mapping configuration
treeFields = {
dataSource: this.treeData,
id: 'id',
text: 'name',
child: 'subChild',
hasChildren: 'hasChild',
expanded: 'expanded'
};
}| Method | Purpose |
|---|---|
| Add collection of nodes at target position |
| Remove nodes by ID |
| Replace node text (requires allowEditing enabled) |
| Move nodes to new parent and index position |
| Get all tree data or specific node data |
| Get all checked node IDs including child nodes whether loaded or not |
| Check all or specific nodes |
| Uncheck all or specific nodes |
| Start editing a node |
| Expand all or specific nodes, optionally by level |
| Collapse all or specific nodes, optionally by level |
| Scroll to make node visible |
| Disable specific nodes |
| Enable specific nodes |
| Get HTML element of node |
| Destroy TreeView component |
| Event | Triggered When |
|---|---|
| TreeView component is created |
| Data source binding is complete |
| Tree data is modified (add/remove/update) |
| User clicks on a node |
| Node is selected |
| Before node selection (can prevent) |
| Checkbox state changes |
| Before checkbox changes (can prevent) |
| Before node expansion |
| Node is expanded |
| Before node collapse |
| Node is collapsed |
| Before node text editing |
| After node text is edited |
| Drag operation begins |
| Node is being dragged |
| Drag ends before drop |
| Node is dropped successfully |
| Before rendering each node (customize appearance) |
| User presses keyboard key |
| TreeView component is destroyed |
treeFields = {
dataSource: this.treeData,
id: 'id',
text: 'name',
child: 'subChild',
hasChildren: 'hasChild'
};
showCheckBox = true; // Enable checkboxes
autoCheck = true; // Parent/child auto-check<ejs-treeview
[fields]="treeFields"
[allowDragAndDrop]="true"
[allowMultiSelection]="true"
(nodeDragging)="onNodeDragging($event)"
(nodeDropped)="onNodeDropped($event)">
</ejs-treeview><input
type="text"
(keyup)="filterTree($event.target.value)"
placeholder="Search nodes...">
<ejs-treeview
#treeView
[fields]="filteredFields">
</ejs-treeview><ejs-treeview
[fields]="treeFields"
[allowEditing]="true"
(nodeEditing)="onNodeEditing($event)"
(nodeEdited)="onNodeEdited($event)">
</ejs-treeview>| Property | Type | Purpose |
|---|---|---|
| Object | Configures data source mapping (id, text, child, parentID, hasChildren, expanded, isChecked, etc.) |
| Array | Hierarchical or flat data array |
| Boolean | Enable multiple node selection |
| Boolean | Display checkboxes before nodes |
| Boolean | Auto-check children when parent is checked (default: true) |
| Boolean | Enable drag-and-drop functionality |
| Boolean | Enable in-place node editing |
| Boolean | Load child nodes only when parent expands (default: true) |
| String | Sort order: 'Ascending', 'Descending', or 'None' |
| String | Apply custom CSS class for styling |
| Boolean | Enable right-to-left layout support |
| Boolean | Save and restore TreeView state (expanded nodes, selections) |
| Array | Array of node IDs that should be checked |
| Array | Array of node IDs that should be selected |
| Template | Custom template for rendering nodes |
| Object | Configure expand/collapse animations |
| Boolean | Enable keyboard navigation (default: true) |
getting-started.mddata-binding.mdnode-selection.mdnode-editing.mddrag-and-drop.mdtemplating.mdfiltering-sorting.mdcontext-menu.mdaccessibility-advanced.md