GridApiAPI
GridApi 介面的擴充文件,其中包含關於模組屬性和可用 API 的詳細資訊。
示範
匯入
import { GridApi } from '@mui/x-data-grid-premium'
// or
import { GridApi } from '@mui/x-data-grid-pro'
// or
import { GridApi } from '@mui/x-data-grid'
完整的網格 API。
將欄位新增至列分組模型。
類型:(groupingCriteriaField: string, groupingIndex?: number) => void
產生包含 DataGrid 狀態中可匯出部分的序列化物件。
這些值隨後可以傳遞至 initialState
屬性,或使用 restoreState
方法注入。
類型:(params?: GridExportStateParams) => InitialState
取得在事件中作為引數傳遞的 GridCellParams 物件。
類型:(id: GridRowId, field: string) => HTMLDivElement | null
取得在事件中作為引數傳遞的 GridCellParams 物件。
類型:<R extends GridValidRowModel = any, V = unknown, F = V, N extends GridTreeNode = GridTreeNode>(id: GridRowId, field: string) => GridCellParams<R, V, F, N>
傳回包含儲存格選取狀態的物件。
物件的鍵對應於列 ID。
每個鍵的值也是一個物件,該物件具有作為鍵的欄位,以及作為其選取狀態的布林值。
類型:() => GridCellSelectionModel
傳回導向至請求欄的群組 ID。
陣列依深度遞增排序(最後一個元素是欄的直接父項)。
類型:(field: string) => GridColumnGroup['groupId'][]
取得在事件中作為引數傳遞的 GridColumnHeaderParams 物件。
類型:(field: string) => GridColumnHeaderParams
傳回欄的索引位置。預設情況下,僅考慮可見欄。
傳遞 false
給 useVisibleColumns
以考慮所有欄。
類型:(field: string, useVisibleColumns?: boolean) => number
以 CSV 字串形式傳回網格資料。
此方法由 exportDataAsCsv
內部使用。
類型:(options?: GridCsvExportOptions) => string
以 exceljs 工作簿形式傳回網格資料。
此方法由 exportDataAsExcel
內部使用。
類型:(options?: GridExcelExportOptions) => Promise<Excel.Workbook> | null
傳回給定篩選模型的篩選狀態,而不會將其套用至資料網格。
類型:(filterModel: GridFilterModel) => GridStateCommunity['filter']
在套用列選取傳播後,傳回修改後的選取模型。
當使用 setRowSelectionModel
設定選取模型時,使用此選項可實現正確的 rowSelectionPropagation
行為。
類型:(inputSelectionModel: GridRowSelectionModel) => GridRowSelectionModel
取得分組條件的列。
僅包含提供給網格的列,而不包含網格自動產生的列。
類型:(params: GridRowGroupChildrenGetterParams) => GridRowId[]
傳回具有透過編輯儲存格設定的值的列。
在列編輯中,field
會被忽略,且會考慮所有欄位。
類型:(id: GridRowId, field: string) => GridRowModel
觸發視口滾動到 params
給定索引的儲存格。
如果網格必須滾動才能到達目標,則傳回 true
。
類型:(params: Partial<GridCellIndexCoordinates>) => boolean
選取 start
和 end
座標給定範圍內的所有儲存格。
類型:(start: GridCellCoordinates, end: GridCellCoordinates, keepOtherSelected?: boolean) => void
變更範圍內所有可選取列的選取狀態。
類型:(range: { startId: GridRowId; endId: GridRowId }, isSelected?: boolean, resetSelection?: boolean) => void
根據傳遞至 newModel
引數的值更新儲存格選取模型。
任何已選取的儲存格都將取消選取。
類型:(newModel: GridCellSelectionModel) => void
將欄從其原始位置移動到 targetIndexPosition
給定的位置。
Type:(field: string, targetIndexPosition: number) => void
設定編輯儲存格的值。
常用於編輯儲存格元件內部。
Type:(params: GridEditCellValueParams, event?: MuiBaseEvent) => Promise<boolean> | void
將篩選器模型設定為 model
所給定的模型。
Type:(model: GridFilterModel, reason?: GridControlledStateReasonLookup['filter']) => void
設定分組條件的分組索引。
Type:(groupingCriteriaField: string, groupingIndex: number) => void
設定新的列選取模型。
⚠️ 注意:setRowSelectionModel
不會自動套用選取傳播。
請改為傳遞 API 方法 getPropagatedRowSelectionModel
傳回的模型,以套用選取傳播。
Type:(rowSelectionModel: GridRowSelectionModel) => void
顯示篩選器面板。如果給定 targetColumnField
,也會為此欄位新增篩選器。
Type:(targetColumnField?: string, panelId?: string, labelId?: string) => void
顯示偏好設定面板。newValue
引數控制面板的內容。
Type:(newValue: GridPreferencePanelsValue, panelId?: string, labelId?: string) => void
排序欄位。
Type:(field: GridColDef['field'], direction?: GridSortDirection, allowMultipleSorting?: boolean) => void
將與給定的列 ID 和欄位對應的儲存格設為檢視模式,並使用儲存的新值更新原始列。
如果 params.ignoreModifications
為 true
,則會捨棄所做的修改。
Type:(params: GridStopCellEditModeParams) => void
將與給定的 ID 對應的列設為檢視模式,並使用儲存的新值更新原始列。
如果 params.ignoreModifications
為 true
,則會捨棄所做的修改。
Type:(params: GridStopRowEditModeParams) => void
為事件註冊處理常式。
Type:<E extends GridEvents>(event: E, handler: GridEventListener<E>, options?: EventListenerOptions) => () => void