Skip to content

DataGrid

DataGrid 是 Doggy 的資料表格元件,透過 DataGrid 實體設定 + DataGridService 伺服器端驅動,支援分頁、排序、篩選、匯出等進階特性。

概述

DataGrid 系統由以下部分組成(src/Component/Database/):

Component/Database/
├── Bridge/
│   ├── DataSetInterface.php   # 数据集接口
│   ├── DataSource.php         # 数据源抽象
│   ├── DoctrineDataSet.php    # Doctrine 数据集实现
│   ├── FilterCondition.php    # 筛选条件
│   └── FilterGroup.php        # 筛选条件组
└── View/
    └── DataGrid.php           # DataGrid 视图组件

設定

DataGrid 透過 App\Entity\Platform\DataGrid 實體持久化設定,DataGridService 提供伺服器端支援:

php
use App\Service\Platform\DataGridService;

class DataGridController
{
    public function index(DataGridService $service): Response
    {
        $dataGrid = $service->findDataGridByEntityClass(Department::class);
        $config = $dataGrid->getDefaultConfigData();

        return $this->render('admin/index.html.twig', [
            'gridConfig' => $config,
        ]);
    }
}

篩選器

DataGrid 使用 FilterConditionFilterGroup 建置篩選條件,與 AI 自然語言查詢 Agent 深度整合:

  • 文字篩選(模糊/精確)
  • 數字範圍篩選
  • 日期範圍篩選
  • 下拉選擇篩選
  • 關聯實體篩選(支援 dot notation)

資料來源

透過 DataSetInterface 抽象資料來源,目前支援:

  • DoctrineDataSet:基於 Doctrine QueryBuilder
  • DataSource:資料來源基底類別
  • 支援自訂資料集實作

前端元件

前端透過 sunui_datagrid Twig 巨集渲染:

twig
{% include 'components/datagrid.html.twig' with {
    columns: columns,
    data: paginator,
    config: gridConfig
} %}

特性

  • 伺服器端分頁與排序
  • 多欄篩選(AND/OR 組合)
  • 資料匯出
  • 與 AI Agent 自然語言查詢整合
  • 設定持久化至資料庫

基於 MIT 協議開源 | Copyright © 2026 Doggy