Loading...
Loading...
Compare original and translation side by side
import { 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'
};
}import { 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 |
| 方法 | 用途 |
|---|---|
| 在目标位置添加节点集合 |
| 通过ID移除节点 |
| 替换节点文本(需启用allowEditing) |
| 将节点移动到新的父节点和位置 |
| 获取所有树形数据或特定节点数据 |
| 获取所有选中的节点ID,包括已加载和未加载的子节点 |
| 选中所有或特定节点 |
| 取消选中所有或特定节点 |
| 开始编辑节点 |
| 展开所有或特定节点,可按层级展开 |
| 折叠所有或特定节点,可按层级折叠 |
| 滚动到节点使其可见 |
| 禁用特定节点 |
| 启用特定节点 |
| 获取节点的HTML元素 |
| 销毁TreeView组件 |
| 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 |
| 事件 | 触发时机 |
|---|---|
| TreeView组件创建完成时 |
| 数据源绑定完成时 |
| 树形数据被修改(添加/删除/更新)时 |
| 用户点击节点时 |
| 节点被选中时 |
| 节点选中前触发(可阻止选中) |
| 复选框状态改变时 |
| 复选框状态改变前触发(可阻止改变) |
| 节点展开前触发 |
| 节点展开后触发 |
| 节点折叠前触发 |
| 节点折叠后触发 |
| 节点文本编辑前触发 |
| 节点文本编辑完成后触发 |
| 拖动操作开始时 |
| 节点正在被拖动时 |
| 拖动结束但未放置时 |
| 节点成功放置时 |
| 每个节点渲染前触发(可自定义外观) |
| 用户按下键盘按键时 |
| TreeView组件被销毁时 |
treeFields = {
dataSource: this.treeData,
id: 'id',
text: 'name',
child: 'subChild',
hasChildren: 'hasChild'
};
showCheckBox = true; // Enable checkboxes
autoCheck = true; // Parent/child auto-checktreeFields = {
dataSource: this.treeData,
id: 'id',
text: 'name',
child: 'subChild',
hasChildren: 'hasChild'
};
showCheckBox = true; // 启用复选框
autoCheck = true; // 父/子节点自动联动选中<ejs-treeview
[fields]="treeFields"
[allowDragAndDrop]="true"
[allowMultiSelection]="true"
(nodeDragging)="onNodeDragging($event)"
(nodeDropped)="onNodeDropped($event)">
</ejs-treeview><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><input
type="text"
(keyup)="filterTree($event.target.value)"
placeholder="搜索节点...">
<ejs-treeview
#treeView
[fields]="filteredFields">
</ejs-treeview><ejs-treeview
[fields]="treeFields"
[allowEditing]="true"
(nodeEditing)="onNodeEditing($event)"
(nodeEdited)="onNodeEdited($event)">
</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) |
| 属性 | 类型 | 用途 |
|---|---|---|
| 对象 | 配置数据源映射(id、text、child、parentID、hasChildren、expanded、isChecked等) |
| 数组 | 层级或扁平数据数组 |
| 布尔值 | 启用多节点选择 |
| 布尔值 | 在节点前显示复选框 |
| 布尔值 | 选中父节点时自动选中子节点(默认:true) |
| 布尔值 | 启用拖放功能 |
| 布尔值 | 启用节点就地编辑 |
| 布尔值 | 仅在父节点展开时加载子节点(默认:true) |
| 字符串 | 排序顺序:'Ascending'、'Descending'或'None' |
| 字符串 | 应用自定义CSS类进行样式设置 |
| 布尔值 | 启用从右到左布局支持 |
| 布尔值 | 保存和恢复TreeView状态(展开节点、选中状态) |
| 数组 | 应被选中的节点ID数组 |
| 数组 | 应被选中的节点ID数组 |
| 模板 | 用于渲染节点的自定义模板 |
| 对象 | 配置展开/折叠动画 |
| 布尔值 | 启用键盘导航(默认:true) |
getting-started.mddata-binding.mdnode-selection.mdnode-editing.mddrag-and-drop.mdtemplating.mdfiltering-sorting.mdcontext-menu.mdaccessibility-advanced.mdgetting-started.mddata-binding.mdnode-selection.mdnode-editing.mddrag-and-drop.mdtemplating.mdfiltering-sorting.mdcontext-menu.mdaccessibility-advanced.md