Table
The table layer (@blocknote/block-view/table) provides a framework-agnostic abstraction over the data model. It converts collections and views into rows, columns, and cells suitable for rendering.
createCollectionTable
Section titled “createCollectionTable”Factory function that creates a CollectionTable instance.
import { createCollectionTable } from "@blocknote/block-view/table";
const table = createCollectionTable({ collectionManager: manager, viewId: "view-1", getCellRenderer: (property) => renderers[property.type], propertyDefinitions: defaultPropertyDefinitions,});CreateCollectionTableParams
Section titled “CreateCollectionTableParams”type CreateCollectionTableParams = { collectionManager: CollectionManager; viewId: string; getCellRenderer: (property: Property) => CellRenderer; propertyDefinitions: PropertyDefinition<any>[]; getEditable?: (document: Document, property: Property) => boolean;};| Param | Description |
|---|---|
collectionManager | The initialized collection manager |
viewId | Which view to render |
getCellRenderer | Returns a cell renderer component for a given property |
propertyDefinitions | All property definitions (built-in + custom) |
getEditable | Optional per-cell editability check |
In practice, you’ll use useCollectionTableView (React) instead of calling this directly. The hook handles renderer resolution and subscription setup for you.
CollectionTable
Section titled “CollectionTable”The core table instance. Provides rows, columns, selection, and subscription APIs.
import type { CollectionTable } from "@blocknote/block-view/table";table.rows: TableRow[]table.columns: TableColumn[]Row Selection
Section titled “Row Selection”table.getIsAllRowsSelected(): booleantable.getIsSomeRowsSelected(): booleantable.getToggleAllRowsSelectedHandler(): () => voidtable.getSelectedRowsById(): Record<string, TableRow>table.resetRowSelection(): voidSubscriptions
Section titled “Subscriptions”The table uses useSyncExternalStore-compatible subscription APIs. Three separate channels minimize unnecessary re-renders:
// Subscribe to row data changestable.subscribe(listener: () => void): () => voidtable.getSnapshot(): number
// Subscribe to column changes (resize, reorder, add, remove)table.subscribeToColumns(listener: () => void): () => voidtable.getColumnsRevision(): number
// Subscribe to selection changestable.subscribeToSelection(listener: () => void): () => voidtable.getSelectionSnapshot(): RowSelectionStateLifecycle
Section titled “Lifecycle”table.refresh(): void // Rebuild rows/columns from current model statetable.setEditable(value: boolean): voidtable.connect(): () => void // Start listening to model changes; returns disconnect functionCollection Access
Section titled “Collection Access”table.transaction: Transactiontable.view: CollectionViewtable.collectionManager: CollectionManagertable.undoRedoManager: UndoRedoManagertable.propertyDefinitions: PropertyDefinition<any>[]Auto-Focus
Section titled “Auto-Focus”table.getPendingAutoFocus(): { documentId: string; propertyId: string } | nulltable.setPendingAutoFocus(target: { documentId: string; propertyId: string } | null): voidUsed internally to focus a cell after creating a new document.
TableRow
Section titled “TableRow”interface TableRow { id: string; // document ID index: number; // row index original: Document; // the underlying Document entity cells: TableCell[]; // cells in this row getIsSelected(): boolean; toggleSelected(): void;}Example
Section titled “Example”for (const row of table.rows) { console.log(row.id, row.original.getProp("name")?.value); console.log("Selected:", row.getIsSelected());}TableColumn
Section titled “TableColumn”interface TableColumn { id: string; // property ID or special column ID size: number; // width in pixels property?: Property; // the underlying Property (undefined for utility columns like selection) cell?: (context: CellContext) => ReactNode; // cell renderer}TableCell
Section titled “TableCell”interface TableCell { id: string; // unique cell ID column: TableColumn; row: TableRow; render(): ReactNode; // renders the cell content}CellContext
Section titled “CellContext”Passed to column cell renderers:
interface CellContext { getValue(): PropertyValue | undefined; row: TableRow; column: TableColumn; table: CollectionTable;}CellRenderer / CellRendererParams
Section titled “CellRenderer / CellRendererParams”The interface for cell renderer components:
interface CellRendererParams { value: PropertyValue | undefined; property: Property; document: Document; table: CollectionTable; editable?: boolean; onChange: (changes: { value: string; ref?: { type: string; id: string } }) => void; autoFocus?: boolean;}
type CellRenderer = FC<CellRendererParams>;Writing a Cell Renderer
Section titled “Writing a Cell Renderer”const MyCellRenderer: CellRenderer = ({ value, editable, onChange, autoFocus }) => { const displayValue = value?.value ?? "";
if (!editable) { return <span>{displayValue}</span>; }
return ( <input value={displayValue} autoFocus={autoFocus} onChange={(e) => onChange({ value: e.target.value })} /> );};RowSelectionState
Section titled “RowSelectionState”type RowSelectionState = Record<string, boolean>;// Keys are document IDs, values are selection stateColumn Adapters
Section titled “Column Adapters”Utility functions for creating columns from view configuration:
import { createColumn, getColumnsFromView, COLUMN_DRAG_DATA_KEY, getColumnDragData,} from "@blocknote/block-view/table";createColumn
Section titled “createColumn”function createColumn(options: CreateColumnOptions): TableColumn;getColumnsFromView
Section titled “getColumnsFromView”function getColumnsFromView(options: GetColumnsFromViewOptions): TableColumn[];Converts a view’s column configuration into TableColumn[] objects, resolving property definitions and cell renderers.
Drag and Drop
Section titled “Drag and Drop”const COLUMN_DRAG_DATA_KEY: string;type ColumnDragData = { /* column drag metadata */};function getColumnDragData(data: Record<string, unknown>): ColumnDragData | undefined;Used by the built-in column reordering feature with @atlaskit/pragmatic-drag-and-drop.