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
给定的位置。
类型:(field: string, targetIndexPosition: number) => void
设置编辑单元格的值。
通常在编辑单元格组件内部使用。
类型:(params: GridEditCellValueParams, event?: MuiBaseEvent) => Promise<boolean> | void
将过滤器模型设置为由 model
给定的模型。
类型:(model: GridFilterModel, reason?: GridControlledStateReasonLookup['filter']) => void
设置分组条件的分组索引。
类型:(groupingCriteriaField: string, groupingIndex: number) => void
设置新的行选择模型。
⚠️ 注意:setRowSelectionModel
不会自动应用选择传播。
传递由 API 方法 getPropagatedRowSelectionModel
返回的模型,以应用选择传播。
类型:(rowSelectionModel: GridRowSelectionModel) => void
显示过滤器面板。如果给定 targetColumnField
,则还会为此字段添加过滤器。
类型:(targetColumnField?: string, panelId?: string, labelId?: string) => void
显示偏好设置面板。newValue
参数控制面板的内容。
类型:(newValue: GridPreferencePanelsValue, panelId?: string, labelId?: string) => void
对列进行排序。
类型:(field: GridColDef['field'], direction?: GridSortDirection, allowMultipleSorting?: boolean) => void
将与给定行 id 和字段对应的单元格置于查看模式,并使用存储的新值更新原始行。
如果 params.ignoreModifications
为 true
,则会丢弃所做的修改。
类型:(params: GridStopCellEditModeParams) => void
将与给定 id 对应的行置于查看模式,并使用存储的新值更新原始行。
如果 params.ignoreModifications
为 true
,则会丢弃所做的修改。
类型:(params: GridStopRowEditModeParams) => void
为事件注册处理程序。
类型:<E extends GridEvents>(event: E, handler: GridEventListener<E>, options?: EventListenerOptions) => () => void