这些是所有单元格的核心选项和 API 属性。更多选项和 API 属性可用于其他表格特性

单元格 API

所有单元格对象都具有以下属性:

id

tsx
id: string
id: string

整个表格中单元格的唯一 ID。

getValue

tsx
getValue: () => any
getValue: () => any

返回单元格的值,通过关联列的访问器键或访问器函数访问。

renderValue

tsx
renderValue: () => any
renderValue: () => any

getValue 一样渲染单元格的值,但如果未找到值,则返回 renderFallbackValue

row

tsx
row: Row<TData>
row: Row<TData>

单元格关联的行对象。

column

tsx
column: Column<TData>
column: Column<TData>

单元格关联的列对象。

getContext

tsx
getContext: () => {
  table: Table<TData>
  column: Column<TData, TValue>
  row: Row<TData>
  cell: Cell<TData, TValue>
  getValue: <TTValue = TValue,>() => TTValue
  renderValue: <TTValue = TValue,>() => TTValue | null
}
getContext: () => {
  table: Table<TData>
  column: Column<TData, TValue>
  row: Row<TData>
  cell: Cell<TData, TValue>
  getValue: <TTValue = TValue,>() => TTValue
  renderValue: <TTValue = TValue,>() => TTValue | null
}

返回基于单元格的组件(如单元格和聚合单元格)的渲染上下文(或 props)。将这些 props 与你框架的 flexRender 实用程序一起使用,以使用你选择的模板渲染它们:

tsx
flexRender(cell.column.columnDef.cell, cell.getContext())
flexRender(cell.column.columnDef.cell, cell.getContext())