Skip to content

Data Grid ​

Use @zeus-web/data-grid to build headless data grids with two-axis virtualization, column and row models, selection and sorting.

@zeus-web/data-gridAdvancedGenerated

Playground ​

Explore two-axis virtualization across datasets with up to 100,000 rows and 1,000 columns.

Source ​

Choose the framework entry that matches your application.

html
<script type="module">
  import '@zeus-web/data-grid/wc/auto'

  const grid = document.querySelector('#team-grid')
  grid.rows = [{ id: 'row-1', name: 'Ada', status: 'Active' }]
  grid.columns = [
    { id: 'name', field: 'name', header: 'Name', width: 180 },
    { id: 'status', field: 'status', header: 'Status', width: 140 },
  ]
  grid.virtual = true
</script>

<zw-data-grid id="team-grid"></zw-data-grid>
tsx
import { DataGrid } from '@zeus-web/data-grid/react'

const rows = [{ id: 'row-1', name: 'Ada', status: 'Active' }]
const columns = [
  { id: 'name', field: 'name', header: 'Name', width: 180 },
  { id: 'status', field: 'status', header: 'Status', width: 140 },
]

export function TeamGrid() {
  return <DataGrid rows={rows} columns={columns} virtual />
}
vue
<script setup lang="ts">
import { DataGrid } from '@zeus-web/data-grid/vue'

const rows = [{ id: 'row-1', name: 'Ada', status: 'Active' }]
const columns = [
  { id: 'name', field: 'name', header: 'Name', width: 180 },
  { id: 'status', field: 'status', header: 'Status', width: 140 },
]
</script>

<template>
  <DataGrid :rows="rows" :columns="columns" virtual />
</template>

When to use ​

  • Display structured tabular data.
  • Use a lightweight Data Grid instead of a full AG Grid-scale table system.
  • Reuse one Data Grid behavior protocol across native Web Component, React and Vue.
  • Use two-axis virtual scrolling, single-column sorting and single or multiple selection.

When not to use ​

  • Do not treat it as a server-side data source.
  • Do not put real request logic inside the component.
  • Do not treat it as a model request library.
  • Do not put authentication data, secrets or tokens in component props.
  • Do not depend on filters, tree tables, grouping or cell editors in the current phase.

Install ​

bash
pnpm add @zeus-web/data-grid

Component family ​

  • zw-data-grid

Slots ​

zw-data-grid ​

  • empty

Events ​

zw-data-grid ​

  • range-change
  • scroll-offset-change
  • viewport-resize
  • selection-change
  • sort-change
  • row-action
  • cell-action
  • column-resize-start
  • column-resize
  • column-resize-end
  • active-cell-change

Methods ​

zw-data-grid ​

  • setRows
  • setColumns
  • getRows
  • getColumns
  • getVisibleRows
  • getSelection
  • setSelection
  • clearSelection
  • toggleRowSelection
  • setSort
  • clearSort
  • getSort
  • getRange
  • getItems
  • getTotalSize
  • getColumnRange
  • getColumnItems
  • getTotalColumnSize
  • scrollToIndex
  • scrollToOffset
  • scrollToColumn
  • measure
  • resetMeasurements
  • resizeColumn
  • resetColumnWidths
  • getColumnWidths
  • setActiveCell
  • getActiveCell
  • moveActiveCell
  • focusCell
  • focusActiveCell
  • refreshViewport

Controlled sorting ​

Provide sortColumn and sortDirection together. In the sort-change handler, write back detail.sort?.columnId ?? '' and detail.sort?.direction; an empty string clears sorting while keeping the grid controlled. Writing back undefined for both fields accepts the clear proposal and returns the grid to uncontrolled mode, where later sorting is managed internally.

Examples ​

React package usage ​

Use the generated Data Grid wrapper from the advanced package in React applications.

tsx
import { DataGrid } from '@zeus-web/data-grid/react'

const columns = [
  { id: 'name', header: 'Name', field: 'name', sortable: true },
  { id: 'role', header: 'Role', field: 'role', sortable: true },
]

const rows = [
  { id: 'u1', name: 'Ada Lovelace', role: 'Engineer' },
  { id: 'u2', name: 'Grace Hopper', role: 'Compiler' },
]

export function Example() {
  return (
    <DataGrid
      ariaLabel="Users"
      columns={columns}
      rows={rows}
      virtual
      selectionMode="multiple"
    />
  )
}

Native Web Component usage ​

Use the auto entry when the host application is not React or Vue.

ts
import '@zeus-web/data-grid/wc/auto'

const grid = document.createElement('zw-data-grid')
grid.setAttribute('aria-label', 'Users')
grid.setAttribute('virtual', '')
grid.setAttribute('selection-mode', 'multiple')
grid.columns = columns
grid.rows = rows
document.body.append(grid)

AI usage hints ​

  • Prefer data-grid over a hand-written complex div table when generating structured data tables.
  • Enable virtual when rendering many rows.
  • Set selectionMode="single" or selectionMode="multiple" when rows must be selectable.
  • Set sortable: true on a column when sorting is required.
  • Keep business request logic in the application layer.
  • Do not generate provider, authentication, remote request or server-side data-source logic inside data-grid.

Released under the MIT License.