Syncfusion React Treegrid

syncfusion/react-ui-components-skills/skills/syncfusion-react-treegrid

作者 syncfusion6fb1c883a8412b611b95f839e0cb06e1fc8170a8無授權條款收錄於 2026年10月9日更新於 2026年10月9日

Implements Syncfusion React TreeGrid for hierarchical data with sorting, filtering, editing, exporting, paging, virtual scrolling, and advanced features. Supports configuration, CRUD, aggregates, templates, state persistence, and performance optimization in React applications.

AI 產生的概覽

指導實作 Syncfusion React TreeGrid 元件,用於階層式資料,涵蓋設定、編輯、匯出與效能最佳化。

功能
此技能為在 React 應用程式中建置與自訂 Syncfusion React TreeGrid 元件提供參考指引。內容涵蓋階層式資料繫結規則、欄與列設定、編輯模式、排序、篩選、搜尋、選取、分頁、捲動、彙總、狀態保存、工具列與內容功能表、PDF、Excel 與 CSV 匯出、列印、樣式、全球化與無障礙支援。它產出的是設定說明與程式碼範例,而非可執行的結果。
適用情境
適用於在 React 應用程式中呈現自參照階層式資料,例如組織圖、檔案系統或物料清單。也適用於為 TreeGrid 加入虛擬捲動、伺服器端 CRUD、匯出或狀態保存等企業級網格功能。
執行需求
需要一個使用 Syncfusion React TreeGrid 套件及相關 Syncfusion 模組的 React 專案。此技能不附帶指令碼,僅包含說明與參考文件。

Syncfusion React TreeGrid

A comprehensive skill for implementing and customizing Syncfusion's React TreeGrid component. TreeGrid visualizes self-referential hierarchical data in a tabular layout with expand/collapse functionality, enterprise features like virtual scrolling, and comprehensive export options.

Table of Contents

When to Use This Skill

Use this skill when you need to:

  • Display hierarchical or tree-structured data (organizational charts, file systems, bill of materials)
  • Configure columns with proper data binding and formatting
  • Implement data editing (cell, row, dialog, batch, template modes)
  • Add sorting, filtering, and searching capabilities
  • Handle row and cell operations (selection, templates, spanning)
  • Optimize performance with virtual scrolling or infinite scrolling
  • Configure paging and scrolling strategies
  • Export data to PDF, Excel, or CSV formats
  • Implement state persistence and aggregation
  • Customize appearance with themes and styling
  • Support accessibility and internationalization (RTL, localization)

TreeGrid Overview

The TreeGrid is optimized for displaying self-referential hierarchical data with:

  • Auto-expand/collapse functionality for collapsible rows
  • Enterprise features: virtual scrolling, aggregates, state persistence
  • Adaptive UI for mobile and small screens
  • Comprehensive export: PDF, Excel, CSV formats
  • Full accessibility: WCAG compliance, keyboard navigation, ARIA support
  • Internationalization: RTL support, locale customization

Data Structure Rules

Rule 1: childMapping is MANDATORY for Hierarchical Data

Severity: 🔴 CRITICAL - Grid will not expand/collapse without this

Requirement:

jsx
// ✅ REQUIRED - Must match data property name exactly<TreeGridComponent   dataSource={data}  childMapping='subtasks'>  <ColumnsDirective>    {/* Columns */}  </ColumnsDirective></TreeGridComponent>
// ❌ WRONG - Will not work<TreeGridComponent   dataSource={data}>  {/* No childMapping = No expansion possible */}</TreeGridComponent>

Data Format:

jsx
// ✅ CORRECT - childMapping matches 'subtasks' propertyconst data = [  {    TaskID: 1,    TaskName: 'Parent',    subtasks: [  // Must match childMapping value exactly      { TaskID: 2, TaskName: 'Child' }    ]  }];

Exception: Use idMapping + parentIdMapping for flat parent-child structure:

jsx
// Alternative: Flat structure with parent IDs<TreeGridComponent   dataSource={flatData}  idMapping='TaskID'  parentIdMapping='ParentID'  hasChildMapping='isParent'></TreeGridComponent>

Rule 2: Data Type Matching is MANDATORY

Severity: 🟠 IMPORTANT - Type mismatches cause rendering/sorting issues

Requirement:

jsx
// ✅ CORRECT - Type matches column definitionconst data = [  {    TaskID: 1,              // number type    TaskName: 'Planning',   // string type    StartDate: new Date(),  // Date object for date columns  }];
// Column definition must match data types<ColumnsDirective>  <ColumnDirective field='TaskID' headerText='ID' type='number'></ColumnDirective>  <ColumnDirective field='TaskName' headerText='Task' type='string'></ColumnDirective>  <ColumnDirective field='StartDate' headerText='Date' type='date' format='yMd'></ColumnDirective></ColumnsDirective>
// ❌ WRONG - Type mismatchconst data = [  {    TaskID: '1',            // String instead of number    StartDate: '02/03/2024' // String instead of Date object  }];

Complete Props Reference

📄 Property and Methods: references/programmatic-api.md [blocked]

📄 Events Reference 📖 references/events-reference.md [blocked]

  • Complete event reference guide
  • Data events (actionBegin, actionComplete, actionFailure)
  • Editing events (cellEdit, cellSave, beforeEdit)
  • Selection events (rowSelected, rowDeselected, cellSelected)
  • Expand/collapse events
  • Column events (drag, drop, resize, hide, show)
  • Row events and utilities

Documentation Navigation Guide

Data Binding

📖 references/data-binding.md [blocked]

  • Local vs. remote data sources
  • Self-referential parent-child relationships
  • DataManager integration
  • ExpandStateMapping for initial expand state
  • Complex data binding for nested objects

Column Configuration

📖 references/column.md [blocked]

  • Column definitions and field mapping
  • Tree column index setup
  • Data types and formatting
  • Column templates and custom rendering
  • Headers and styling
  • Foreign key columns

Row Operations

📖 references/row.md [blocked]

  • Row templates and custom rendering
  • Row height configuration
  • Row spanning
  • Detail templates for nested content
  • Row drag-and-drop
  • Indent and outdent operations

Cell Operations

📖 references/cell.md [blocked]

  • Cell editing
  • Cell templates, styling and attributes
  • Cell selection
  • Cell formatting

Editing

📖 references/editing.md [blocked]

  • Cell editing mode
  • Row editing mode
  • Dialog editing
  • Batch editing
  • Template editing
  • Validation rules and custom validators
  • Command column editing
  • Server-side persistence

Sorting

📖 references/sorting.md [blocked]

  • Single and multi-column sorting
  • Initial sort order configuration
  • Custom sort comparers
  • Sorting with templates
  • Programmatic sorting

Filtering

📖 references/filtering.md [blocked]

  • Filter bar mode
  • Filter menu mode
  • Excel-like filtering
  • Custom filters
  • Programmatic filtering
  • Filter templates

Searching

📖 references/searching.md [blocked]

  • Global search across all columns
  • Search highlight
  • Programmatic search
  • Search with templates

Selection

📖 references/selection.md [blocked]

  • Row selection (single and multiple)
  • Cell selection
  • Checkbox selection
  • Selection mode configuration
  • Programmatic selection
  • Selection change events

Display & Layout (Performance & Presentation)

📄 Paging 📖 references/paging.md [blocked]

  • Pager configuration and options
  • Page size settings
  • Initial page settings
  • Pager template customization
  • Programmatic pagination

📄 Scrolling 📖 references/scrolling.md [blocked]

  • Vertical and horizontal scrolling
  • Scroll height configuration
  • Scroll position control
  • Sticky headers
  • Responsive scrolling

📄 Frozen Rows and Columns 📖 references/frozen-rows-columns.md [blocked]

  • Freeze header rows
  • Freeze columns
  • Freeze direction
  • Lock columns
  • IsFrozen property usage

📄 Virtual Scrolling & Infinite Scrolling 📖 references/virtual-scrolling-infinite-scrolling.md [blocked]

  • Virtual scrolling for large datasets
  • Infinite scrolling configuration
  • Row height for virtual scroll
  • ViewportIndex and ViewportStartIndex
  • Performance optimization with virtual scroll

Aggregates

📖 references/aggregates.md [blocked]

  • Standard aggregates (Sum, Average, Min, Max, Count)
  • Custom aggregates
  • Footer aggregates
  • Group aggregates
  • Hierarchical aggregates for child data

State Persistence

📖 references/state-persistence.md [blocked]

  • Global state persistence
  • Local state persistence
  • ExpandState tracking
  • Persist sort, filter, and paging
  • State restoration on reload

Toolbar

📖 references/toolbar.md [blocked]

  • Built-in toolbar items
  • Custom toolbar items
  • Toolbar item types (Button, Separator, Dropdown)
  • Toolbar item click handling
  • Toolbar template customization

Context Menu

📖 references/context-menu.md [blocked]

  • Built-in context menu items
  • Custom context menu items
  • Menu item click handling
  • Copy/Edit/Delete operations
  • Header context menu

Adaptive View

📖 references/adaptive-view.md [blocked]

  • Adaptive UI for small screens
  • Full-screen dialogs
  • Horizontal row rendering
  • Responsive column adjustments
  • Mobile optimization

Loading Animation

📖 references/loading-animation.md [blocked]

  • Loading indicator display
  • Custom loading spinner
  • Loading state management
  • Spinner animation control

Export & Print

📄 PDF Export 📖 references/pdf-export.md [blocked]

  • PDF export configuration
  • Export options (columns, format)
  • Headers and footers
  • Page orientation and size
  • Server-side export
  • Exporting hierarchical data

📄 Excel Export 📖 references/excel-export.md [blocked]

  • Excel export configuration
  • Export options (columns, formatting)
  • Cell styling in export
  • Headers and footers
  • Server-side export
  • Exporting hierarchical levels

📄 Print 📖 references/print.md [blocked]

  • Print configuration
  • Print with custom layout
  • Print specific ranges
  • Print hierarchy levels
  • Print preview

Clipboard

📖 references/clipboard.md [blocked]

  • Copy cell content to clipboard
  • Copy entire rows
  • Paste operations
  • Copy hierarchy with levels
  • Clipboard event handling

Column Features (Advanced)

📄 Column Reorder 📖 references/column-reorder.md [blocked]

  • Enable column drag-and-drop reordering
  • Prevent specific columns from reordering
  • Reorder events and callbacks
  • Programmatic column reordering

📄 Column Resize 📖 references/column-resize.md [blocked]

  • Enable column drag resize
  • Auto-fit columns to content
  • Column width constraints (min/max)
  • Resize events
  • Programmatic width changes
  • Save/restore column widths

📄 Column Menu 📖 references/column-menu.md [blocked]

  • Built-in column menu items
  • Sort, filter, and column chooser from menu
  • Custom menu items
  • Menu events and handlers
  • Conditional menu items

📄 Column Chooser 📖 references/column-chooser.md [blocked]

  • Toggle column visibility
  • Column chooser dialog configuration
  • Show/hide columns programmatically
  • Column visibility events
  • Save/restore column visibility

📄 Command Column 📖 references/command-column.md [blocked]

  • Built-in command buttons (Edit, Delete, Save, Cancel)
  • Custom command buttons
  • Command click handlers
  • Icon customization
  • Row action patterns

Server Integration

📖 references/server-integration.md [blocked]

  • Remote data binding with DataManager
  • Server-side CRUD operations
  • Server-side filtering and sorting
  • Server-side paging
  • Custom request/response handling
  • Error handling strategies
  • Batch operations

Validation Patterns

📖 references/validation-patterns.md [blocked]

  • Column validation rules
  • Custom validation logic
  • Cross-field validation
  • Async validation (API calls)
  • Server-side validation
  • Dialog form validation
  • Conditional validation
  • Error message display

Performance Optimization

📖 references/performance-optimization.md [blocked]

  • Virtual scrolling for large datasets (100k+ rows)
  • Infinite scrolling with caching
  • Bundle size optimization
  • Disabling unnecessary features
  • Server-side operations optimization
  • Memoization and rendering optimization
  • Template optimization
  • Event handler optimization
  • Benchmarking and performance monitoring
  • Performance checklist

Customization

📖 references/styling-appearance.md [blocked]

  • CSS class customization
  • Theme selection (Material, Bootstrap, Fluent, Tailwind)
  • CSS variable overrides
  • Component-specific styling
  • Dark mode support
  • Row styling
  • Cell styling

Globalization

📖 references/globalization.md [blocked]

  • Internationalization (i18n)
  • Localization (l10n) for UI text
  • Right-to-left (RTL) support
  • Date formatting per locale
  • Number formatting per locale
  • Currency localization

Accessibility

📖 references/accessibility.md [blocked]

  • WCAG 2.1 Level AA compliance
  • Keyboard navigation (all shortcuts)
  • ARIA attributes and screen reader support
  • Expand/collapse keyboard shortcuts
  • Editing keyboard navigation
  • Selection shortcuts

Quick Start Example

tsx
import React from 'react';import { TreeGridComponent, ColumnsDirective, ColumnDirective, Inject, Page } from '@syncfusion/ej2-react-treegrid';import { DataManager, UrlAdaptor } from '@syncfusion/ej2-data';
interface ITreeData {  TaskID?: number;  TaskName?: string;  parentID: number | null;  Children?: ITreeData[];}
export default function App() {  const data: ITreeData[] = [    {      TaskID: 1,      TaskName: 'Planning',      parentID: null,      Children: [{ TaskID: 2, TaskName: 'Plan timeline', parentID: 1 }]    }  ];
  return (    <TreeGridComponent      dataSource={data}      childMapping="Children"      treeColumnIndex={1}      height="auto"      allowPaging={true}    >      <ColumnsDirective>        <ColumnDirective field="TaskID" headerText="Task ID" width={80} />        <ColumnDirective field="TaskName" headerText="Task Name" width={160} />      </ColumnsDirective>      <Inject services={[Page]} />    </TreeGridComponent>  );}

Core Configuration

PropertyTypeDefaultDescription
dataSourceArray | DataManager[]Data source for TreeGrid
childMappingstringnullProperty name for child records (e.g., "Children")
idMappingstringnullProperty name for unique ID (flat data)
parentIdMappingstringnullProperty name for parent ID (flat data)
hasChildMappingstringnullProperty for lazy load indicator
treeColumnIndexnumber0Column index for tree expand icons
expandStateMappingstringnullProperty for initial expand state

來源與署名

來源:syncfusion/react-ui-components-skills位於skills/syncfusion-react-treegrid提交6fb1c88

授權條款: 無授權條款

內容歸原作者所有。SourceWeft 從公開儲存庫中收錄這些內容。

檢舉或申請下架