import type { GridOptions } from 'ag-grid-community' import { themeQuartz } from 'ag-grid-community' const borderConfig = { style: 'solid', width: 0.3, color: '#d3d3d3' } export const myTheme = themeQuartz.withParams({ wrapperBorder: false, wrapperBorderRadius: 0, headerBackgroundColor: '#f0f2f3', headerTextColor: '#374151', headerFontSize: 15, headerFontWeight: 'normal', rowBorder: borderConfig, columnBorder: borderConfig, headerRowBorder: borderConfig, dataBackgroundColor: '#fefefe' }) // AG Grid 容器通用 class(占满父容器,配合父元素为 flex/grid 且有明确高度使用) export const agGridWrapClass = 'ag-theme-quartz h-full min-h-0 w-full flex-1' // AG Grid 组件通用 style(撑满容器 div) export const agGridStyle = { height: '100%' } export const gridOptions: GridOptions = { treeData: true, animateRows: true, tooltipShowMode: 'whenTruncated', suppressAggFuncInHeader: true, singleClickEdit: true, stopEditingWhenCellsLoseFocus: true, suppressClickEdit: false, suppressContextMenu: false, groupDefaultExpanded: -1, suppressFieldDotNotation: true, // rowData 更新后通过稳定 ID 维持展开状态和编辑上下文。 getRowId: params => { const id = params.data?.id if (id != null && String(id).trim()) return String(id) const path = Array.isArray(params.data?.path) ? params.data.path.map((segment: unknown) => String(segment ?? '').trim()).filter(Boolean) : [] if (path.length > 0) return path.join('/') return '__row__' }, // 兜底避免 AG Grid #185:treeData 模式下 path 不能为空数组。 getDataPath: data => { const path = Array.isArray(data?.path) ? data.path.map((segment: unknown) => String(segment ?? '').trim()).filter(Boolean) : [] if (path.length > 0) return path const fallback = String(data?.id ?? '').trim() return [fallback || '__row__'] }, getContextMenuItems: () => ['copy', 'paste', 'separator', 'export'], defaultColDef: { resizable: true, sortable: false, filter: false, wrapHeaderText: true, autoHeaderHeight: true }, defaultColGroupDef: { wrapHeaderText: true, autoHeaderHeight: true } }