Table API

The main table component and column definition types.

Grid and Table

Two entry points are supported:

  • Grid — Renders a <canvas> and drives the full pipeline (adapter, WASM, canvas renderer). Use this for the standard canvas-based table.
  • Table — Headless table: no canvas, only structure (e.g. for SSR or custom rendering). Accepts the same data / columns-style props.

All examples below use Grid with object-based columns and data.

Basic usage

import { 
import Grid
Grid
,
import createColumnHelper
createColumnHelper
} from "@ohah/react-wasm-table";
type
type Row = {
    name: string;
    age: number;
}
Row
= {
name: string
name
: string;
age: number
age
: number };
const
const helper: any
helper
=
import createColumnHelper
createColumnHelper
<
type Row = {
    name: string;
    age: number;
}
Row
>();
const
const columns: any[]
columns
= [
const helper: any
helper
.accessor("name", {
header: string
header
: "Name",
size: number
size
: 200 }),
const helper: any
helper
.accessor("age", {
header: string
header
: "Age",
size: number
size
: 100 }),
]; const
const data: Row[]
data
:
type Row = {
    name: string;
    age: number;
}
Row
[] = [
{
name: string
name
: "Alice",
age: number
age
: 30 },
{
name: string
name
: "Bob",
age: number
age
: 25 },
]; function
function App(): JSX.Element
App
() {
return <
import Grid
Grid
data: Row[]
data
={
const data: Row[]
data
}
columns: any[]
columns
={
const columns: any[]
columns
}
width: number
width
={600}
height: number
height
={400} />;
}

Grid props

PropTypeDefaultDescription
dataRecord<string, unknown>[]requiredRow data (array of objects)
columnsColumnDef[]requiredColumn definitions
widthnumberrequiredCanvas width (px)
heightnumberrequiredCanvas height (px)
rowHeightnumber36Row height (px)
headerHeightnumber40Header row height (px)
themePartial<Theme>-Theme overrides
childrenReactNode-Ignored when columns is provided

ColumnDef (object-based columns)

PropTypeDescription
idstringColumn key
widthnumberWidth (px)
minWidthnumberMinimum width
maxWidthnumberMaximum width
flexGrownumberFlex grow
flexShrinknumberFlex shrink
headerstringHeader label
align"left" | "center" | "right"Cell alignment
sortablebooleanEnable header sort
editor"text" | "number" | "select"In-cell editor type
render(value: unknown) => RenderInstructionCustom cell instruction

Custom cell rendering (render prop)

Return a RenderInstruction (e.g. text, badge, flex) from the column render (or JSX children). The canvas renderer draws accordingly.

import { 
import Grid
Grid
, type
import ColumnDef
ColumnDef
} from "@ohah/react-wasm-table";
const
const columns: ColumnDef[]
columns
:
import ColumnDef
ColumnDef
[] = [
{
id: string
id
: "name",
accessorKey: string
accessorKey
: "name",
size: number
size
: 200,
header: string
header
: "Name" },
{
id: string
id
: "status",
accessorKey: string
accessorKey
: "status",
size: number
size
: 120,
header: string
header
: "Status",
cell: (info: any) => {
    type: string;
    value: string;
    style: {
        color: string;
        backgroundColor: string;
    };
}
cell
: (
info: any
info
) => {
const
const value: any
value
=
info: any
info
.getValue();
return {
type: string
type
: "badge",
value: string
value
:
var String: StringConstructor
(value?: any) => string

Allows manipulation and formatting of text strings and determination and location of substrings within strings.

String
(
const value: any
value
),
style: {
    color: string;
    backgroundColor: string;
}
style
: {
color: string
color
:
const value: any
value
=== "active" ? "#065f46" : "#374151",
backgroundColor: string
backgroundColor
:
const value: any
value
=== "active" ? "#d1fae5" : "#f3f4f6",
}, }; }, }, ]; const
const data: {
    id: number;
    name: string;
    status: string;
}[]
data
= [
{
id: number
id
: 1,
name: string
name
: "Alice",
status: string
status
: "active" },
{
id: number
id
: 2,
name: string
name
: "Bob",
status: string
status
: "inactive" },
]; function
function App(): JSX.Element
App
() {
return <
import Grid
Grid
data: {
    id: number;
    name: string;
    status: string;
}[]
data
={
const data: {
    id: number;
    name: string;
    status: string;
}[]
data
}
columns: ColumnDef[]
columns
={
const columns: ColumnDef[]
columns
}
width: number
width
={500}
height: number
height
={400} />;
}

Sorting and filtering

  • Sorting: Set sortable: true on columns. Click header to cycle none → asc → desc → none. State is internal (ref) so scroll stays fast.
  • Filtering: Use columnFilters / onColumnFiltersChange (controlled) or initialState.columnFilters (uncontrolled). Global filter: globalFilter / onGlobalFilterChange.

Supported instruction types for cells: text, badge, flex, box, stack, sparkline, and stubs (see Canvas components).