package.src.core.cell.ts Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of table-core Show documentation
Show all versions of table-core Show documentation
Headless UI for building powerful tables & datagrids for TS/JS.
The newest version!
import { RowData, Cell, Column, Row, Table } from '../types'
import { Getter, memo } from '../utils'
export interface CellContext {
table: Table
column: Column
row: Row
cell: Cell
getValue: Getter
renderValue: Getter
}
export interface CoreCell {
id: string
getValue: CellContext['getValue']
renderValue: CellContext['renderValue']
row: Row
column: Column
getContext: () => CellContext
}
export function createCell(
table: Table,
row: Row,
column: Column,
columnId: string
): Cell {
const getRenderValue = () =>
cell.getValue() ?? table.options.renderFallbackValue
const cell: CoreCell = {
id: `${row.id}_${column.id}`,
row,
column,
getValue: () => row.getValue(columnId),
renderValue: getRenderValue,
getContext: memo(
() => [table, column, row, cell],
(table, column, row, cell) => ({
table,
column,
row,
cell: cell as Cell,
getValue: cell.getValue,
renderValue: cell.renderValue,
}),
{
key: process.env.NODE_ENV === 'development' && 'cell.getContext',
debug: () => table.options.debugAll,
}
),
}
table._features.forEach(feature => {
Object.assign(
cell,
feature.createCell?.(
cell as Cell,
column,
row as Row,
table
)
)
}, {})
return cell as Cell
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy