Skip to content

Advanced Data Grid

DataMIT
View in Storybook

Data grid with row selection, sorting, a column visibility menu, column resizing, and virtual scrolling for large datasets.

bun add @otfdashkit/ui

Preview

Advanced Data Grid
Loading Storybook preview…

Code

import type { ColumnDef } from '@tanstack/react-table'
import { AdvancedDataGrid as DataGrid } from '@otfdashkit/ui'

interface User {
  id: string
  name: string
  email: string
  role: 'Admin' | 'Member' | 'Viewer'
  status: 'Active' | 'Inactive' | 'Pending'
  createdAt: string
}

const columns: ColumnDef<User, unknown>[] = [
  { accessorKey: 'name', header: 'Name', size: 160 },
  { accessorKey: 'email', header: 'Email', size: 220 },
  { accessorKey: 'role', header: 'Role', size: 100 },
  { accessorKey: 'status', header: 'Status', size: 100 },
  { accessorKey: 'createdAt', header: 'Created', size: 120 },
]

function makeUsers(n: number): User[] {
  const roles: User['role'][] = ['Admin', 'Member', 'Viewer']
  const statuses: User['status'][] = ['Active', 'Inactive', 'Pending']
  return Array.from({ length: n }, (_, i) => ({
    id: String(i + 1),
    name: `User ${i + 1}`,
    email: `user${i + 1}@example.com`,
    role: roles[i % 3]!,
    status: statuses[i % 3]!,
    createdAt: new Date(Date.now() - i * 86400000).toLocaleDateString(),
  }))
}

export function Example() {
  return (
    <div className="p-6">
      <DataGrid
        columns={columns}
        data={makeUsers(20)}
        columnVisibility
        selectable
      />
    </div>
  )
}

Free with the SDK. This component ships in @otfdashkit/ui under the MIT license.

Props

Props declared in the AdvancedDataGrid source. Inherited HTML attributes are not listed.

PropTypeDefaultDescription
columnsrequiredColumnDef<T, unknown>[]
datarequiredT[]
classNamestring
columnVisibilitybooleanfalseEnable column visibility toggle
emptyStateReactNodeSlot rendered when data is empty
filterablebooleanfalseEnable client-side column filtering
loadingbooleanfalseSlot rendered while loading
onRowClick(row: T) => voidCalled on row click
onSelectionChange(rows: T[]) => voidCalled when selection changes
resizablebooleantrueEnable column resize
rowHeightnumber40Row height estimate for virtualizer (default 40)
selectablebooleanfalseEnable row checkboxes + bulk selection
skeletonRowsnumber5Number of skeleton rows to show while loading (default 5)
sortablebooleantrueEnable column sorting
virtualbooleanfalseVirtualise rows for large datasets — enable when rows > ~100
virtualHeightnumber480Height of the scroll container when virtual=true (default 480)