Skip to main content

Auto-generate columns

Prop enableAutoColumns — engine behaviour, default false.

Guide

When to use it

Prototyping, or rendering data whose shape you don't know ahead of time — get a working grid without hand-writing a single column definition.

How it works

Pass columns={[]} and turn this on: the engine samples the first rows, infers one column per key (number / boolean / date, else text) and a humanized header. The moment you pass real columns, they win and this is ignored.

<BstTableMui data={rows} columns={[]} getRowId={(r) => r.id} enableAutoColumns />

Tune it with the autoColumns option (sampleRows, include, exclude, header, inferType).

Gotchas

  • It's a no-op the instant columns is non-empty — explicit columns always take over.
  • Type inference is a best guess from a sample; declare real columns for production so formatting and editors are exact.

Live example

Example source
import React from 'react'
import { BstTableMui } from '@bloomskill/table-mui'
import type { BstTableColumn } from '@bloomskill/table-engine'
import '@bloomskill/table-engine/styles.css'
type Row = { id: string; name: string; team: string; role: string; score: number }
const seed: Row[] = [
{ id: '1', name: 'Ada Lovelace', team: 'Platform', role: 'Engineer', score: 92 },
{ id: '2', name: 'Alan Turing', team: 'Research', role: 'Scientist', score: 88 },
{ id: '3', name: 'Grace Hopper', team: 'Platform', role: 'Engineer', score: 95 },
{ id: '4', name: 'Katherine J.', team: 'Research', role: 'Analyst', score: 90 },
{ id: '5', name: 'Edsger Dijkstra', team: 'Platform', role: 'Architect', score: 84 },
]
const columns: BstTableColumn<Row>[] = [
{ id: 'name', accessorKey: 'name', header: 'Name' },
{ id: 'team', accessorKey: 'team', header: 'Team' },
{ id: 'role', accessorKey: 'role', header: 'Role' },
{ id: 'score', accessorKey: 'score', header: 'Score', sortFn: 'basic' },
]
export default function App() {
// No columns passed — Bst-Table infers one column per key from the data.
return <BstTableMui data={seed} columns={[]} getRowId={(r) => r.id} enableAutoColumns />
}
Loading live example…

Overview

Layerenable* (engine, resolved in useBstTable)
Typeboolean
Defaultfalse
Maps tocustom — when no columns are supplied (empty array), infer one column per key found across a sample of rows (first-seen order) with a guessed cell type (number / boolean / date, else text) + humanized header; ignored the moment columns is non-empty (explicit columns win). Tune via autoColumns (sampleRows / include / exclude / header / inferType); helper autoGenerateColumns(data, opts) exported. In settings ("Columns")
Status✅ done
Sincev0.40.0
Settings sheetColumns

Auto-generate columns from data — when no columns are supplied (an empty array), infer them from the row data: one column per key found in a sample of rows, with the cell type guessed from the value (number / boolean / date / text) and a humanized header. Ignored the moment columns is non-empty, so explicit columns always win. Tune via autoColumns. Default: false.

Enable it

<BstTableMui
data={rows}
columns={columns}
enableAutoColumns
/>

Swap BstTableMui for BstTableShadcn (and the CSS import) for the shadcn skin — same props.

Options

OptionNotes
autoColumnsRelated prop for this feature.

Behavior & interactions

  • Generates columns from the data ONLY when columns is empty — one column per key found in a sample of rows, with a guessed cell type + humanized header. Ignored the moment columns is non-empty. Tune via autoColumns (sampleRows / include / exclude / header / inferType).