Documentation
API: Vue (@fragiola/data-grid-vue)

Vue primitives

The same primitives and hooks for Vue 3, from @fragiola/data-grid-vue, and how each React prop maps onto Vue props, slots and attributes.

@fragiola/data-grid-vue has every primitive of the React package, as a Vue 3.5 component, and every hook as a composable, over the same core (re-exported whole). The behaviour, the data-* attributes, the ARIA and the structural style of every element are the same: the other pages of these docs describe each part, and this page says how its React API is written in Vue.

import {
    typedDataGrid,
    useDataGrid,
    useDataGridRef,
    useRowWindow,
    type Column,
} from "@fragiola/data-grid-vue";
import type { VNodeChild } from "vue";

Typing by your row

A React part takes the row type as a type argument (<DataGrid.Rows<Person>>, or inferred from Root's rows); a Vue template cannot pass one. typedDataGrid<Person>() returns the same components, typed by Person: the row of a slot, a cell's row and the columns Root takes are then of your row type.

people-grid.vue
<script setup lang="ts">
import { type Column, typedDataGrid } from "@fragiola/data-grid-vue";
import type { VNodeChild } from "vue";

interface Person {
    id: number;
    name: string;
}

const DataGrid = typedDataGrid<Person>();
const columns: Column<Person, VNodeChild>[] = [{ key: "name", name: "Name", width: 180 }];
defineProps<{ people: Person[] }>();
</script>

<template>
    <DataGrid.Root :columns="columns" :rows="people" :row-key="(row) => row.id" style="height: 400px">
        <DataGrid.Grid aria-label="People">
            <DataGrid.Header />
            <DataGrid.Body />
        </DataGrid.Grid>
    </DataGrid.Root>
</template>

A grid that installs features passes them too: typedDataGrid<Person, typeof features>() types Root by their props. Declare the list as const, once, in setup.

people-grid.vue
<script setup lang="ts">
import { typedDataGrid } from "@fragiola/data-grid-vue";
import { navigation } from "@fragiola/data-grid-vue/navigation";
import { sorting } from "@fragiola/data-grid-vue/sorting";

const features = [navigation(), sorting()] as const;
const DataGrid = typedDataGrid<Person, typeof features>();
</script>

<template>
    <DataGrid.Root :features="features" :columns="columns" :rows="people">
        <!-- … -->
    </DataGrid.Root>
</template>
exportdescription
typedDataGrid<TRow, TFeatures>()the DataGrid components typed by the row type TRow and the installed features (none when left out), as a TypedDataGrid<TRow, TFeatures> (the same objects as DataGrid); Vue only
DataGridthe components, with the row type erased: enough for a part that never reads the row type

How React's props map

ReactVue
render={<table />}as="table" (a tag or a component)
render={(props, state) => …}the render scoped slot, #render="{ props, state, children }": bind v-bind="props" on your element and render <component :is="children" /> inside it
className, stylethe class and style attributes, merged under the structural style (structural keys win; the layers and the pinned cells drop the keys the engine writes, as in React)
className={(state) => …}, style={(state) => …}no function form: a data-* selector (data-active:outline-2), or the render slot's state
onKeyDown, onClick, onPointerDown, onCopy, onPaste, …listeners (@keydown, @click, @pointerdown, @copy, @paste): the part's own first, then yours, then the grid's keys, clicks, presses and clipboard on Root, so preventDefault in yours cancels the grid's
onColumnWidthsChange (with columnResize()) and the other Root callbacksthe same props, :on-column-widths-change="…", or the listener form @column-widths-change="…"
features={features}:features="features", fixed when the grid is created
a feature's props (sortColumns, activePosition, rowSelection, selectedRange, onRangePaste, onFill, editingCell, onCellEdit, …)attributes on Root: :sort-columns, @sort-columns-change, :active-position, @active-position-change, :on-fill (or camelCase), typed by typedDataGrid<TRow, typeof features>()
refa template ref on a part is its component instance; the element is its $el. A handle on the grid is a gridRef
children functions (Rows, Cells, HeaderRows, HeaderCells, SummaryRows, SummaryCells)the default scoped slot: v-slot="{ row }" or v-slot="{ cell }"
Cell childrenthe default slot, v-slot="{ cell, state }"; Row, HeaderCell, SummaryRow, SummaryCell and RowDetail give { state }
renderCell, renderHeaderCell and the other column renderersthe same, returning vnodes: columns are Column<TRow, VNodeChild> (renderCell: ({ row }) => h("b", row.name))
<DataGrid.Rows<Person>> and the other type argumentstypedDataGrid<Person>().Rows

A number in the structural style is written with its unit (px): Vue, unlike React, adds none.

Components

Every part is DataGrid.<Part>, with the props of its React counterpart except render, className, style, ref and children (see the table above). Each accepts as and the render slot, except the collection parts, which render no element of their own.

partVue propsslots
DataGrid.Rootthe core's root props (GridRootProps: columns, rows or rowCount + getRow, rowKey, the sizes, every piece of state controlled or not, its callbacks, the engine's options), gridRef, features; an installed feature's props as attributesdefault
DataGrid.Gridnonedefault
DataGrid.Headernonedefault
DataGrid.HeaderRowsnonedefault { row }
DataGrid.HeaderRowrowdefault
DataGrid.HeaderCellsnonedefault { cell }
DataGrid.HeaderCellcelldefault { state }
DataGrid.Bodynonedefault
DataGrid.Rowsnonedefault { row }
DataGrid.Rowrowdefault { state }
DataGrid.Cellsnonedefault { cell }
DataGrid.Cellcelldefault { cell, state }
DataGrid.Emptynonedefault
RowDetail (/row-expansion)nonedefault { state }
Summary (/summary-rows)positiondefault
SummaryRows (/summary-rows)positiondefault { row }
SummaryRow (/summary-rows)rowdefault { state }
SummaryCells (/summary-rows)nonedefault { cell }
SummaryCell (/summary-rows)celldefault { state }

A feature's parts are not in typedDataGrid(): RowDetail comes from /row-expansion, the summary's from /summary-rows (typedSummaryRows<TRow>() types them by your row type).

people-grid.vue
<DataGrid.Grid as="table" aria-label="People">
    <DataGrid.Body as="tbody">
        <DataGrid.Rows v-slot="{ row }">
            <DataGrid.Row :row="row" as="tr">
                <DataGrid.Cells v-slot="{ cell }">
                    <DataGrid.Cell :cell="cell">
                        <template #render="{ props, state, children }">
                            <td v-bind="props" :title="state.active ? 'active' : undefined">
                                <component :is="children" />
                            </td>
                        </template>
                    </DataGrid.Cell>
                </DataGrid.Cells>
            </DataGrid.Row>
        </DataGrid.Rows>
    </DataGrid.Body>
</DataGrid.Grid>

Scrolling renders nothing until the rendered window changes: the engine writes the layers' offsets itself, and Vue never patches them.

Composables

The hooks of the React package, as composables. Call them in setup. A part composable takes its row or cell (a value, a ref or a getter) and returns { state, props } as computed refs (PartComposableResult): bind v-bind="props.value" on your element, the structural style in props.value.style, its listeners Vue's (onPointerdown, onKeydown).

composablereturns
useDataGrid(){ model, engine } of the enclosing Root (plain values); with a gridRef, a shallow ref of them, null until a root holds it. useDataGrid<Person, typeof features>() types the features' keys
useDataGridRef(), createDataGridRef()a handle on a grid for <DataGrid.Root :grid-ref="gridRef">: the same object for the component's life; createDataGridRef outside a component. Both take the features after the row type
useRowWindow(gridRef?), useColumnWindow(gridRef?)the rows or the columns in view and rendered (AxisWindow), as a shallow ref
useGridView()the grid's view, as a shallow ref
useRows(), useCells(row)the rendered rows, a row's rendered cells, as computed refs
useHeaderRows(), useHeaderCells(row?)the header rows, a header row's cells
/summary-rows's useSummaryRows(position?), useSummaryCells(row?)the summary rows, a summary row's cells
useRow(row), useCell(cell), useHeaderCell(cell); /summary-rows's useSummaryRow(row), useSummaryCell(cell); /row-expansion's useRowDetail(row)a part's { state, props }
/row-reorder's useRowDragHandle(row), /row-grouping's useGroupToggle(row), useGroupLabel(cell), /column-resize's useColumnResizer(cell)the { state, props } of an element of yours: a drag handle, a group's toggle, a sticky group label, a resize handle
/editing's useCellEdit(cell)the editor props of the cell being edited (EditCellRenderProps), a computed ref, null otherwise

The opt-in entry points have the same exports as React's:

entrycomposable
@fragiola/data-grid-vue/localuseLocalRows(rows, columns, options?): rows in memory, sorted, filtered, searched, grouped and paged by the features in options.features (the root's list: sorting(), filtering(), search(), pagination(), each one's stage; one not installed is skipped). Bind v-bind="local.props" on Root: the rows and those features' state; each field is a getter, read when used
@fragiola/data-grid-vue/sortingsorting(), the sorting feature, and sortColumnsOf(view), headerCellSort, SortColumn (the core's, re-exported)
@fragiola/data-grid-vue/navigationnavigation(), the keys and the active cell, and samePosition
@fragiola/data-grid-vue/row-selectionrowSelection(), the row selection, its helpers (selectionStatus, withRowKeys, …), and useSelectAll(rowKeys, gridRef?): a "select all" control's state and its toggle, each field a getter
@fragiola/data-grid-vue/rangecellRange(), ranges of cells (with navigation()), keptRange, sameCellRange
@fragiola/data-grid-vue/clipboardclipboard() (with cellRange()), parseTsv, toTsv, pastedRange, rangeText
@fragiola/data-grid-vue/fillfillHandle(), the fill handle (with cellRange()), repeatedFill, and useFillHandle(cell): the { state, props } of your handle
@fragiola/data-grid-vue/editingediting(), cells edited in place (with navigation()), CellEditEvent, editActions, editCellPropsOf, EDITOR_ATTRIBUTE, and useCellEdit(cell): the editor props of the cell being edited
@fragiola/data-grid-vue/row-expansionrowExpansion(), rows that expand, RowDetail and useRowDetail(row)
@fragiola/data-grid-vue/row-groupingrowGrouping(), row groups and trees that expand, useGroupToggle(row)
@fragiola/data-grid-vue/row-reorderrowReorder(), rows moved by a handle or the keys, useRowDragHandle(row)
@fragiola/data-grid-vue/spanscellSpans(), a column's colSpan in the body
@fragiola/data-grid-vue/filteringfiltering(), the column filters as the model's state (columnFilters, defaultColumnFilters, @column-filters-change; data-filtered on a filtered column's header cell)
@fragiola/data-grid-vue/searchsearch(), the search text as the model's state (searchText, defaultSearchText, @search-text-change)
@fragiola/data-grid-vue/paginationpagination(), the page and its size as the model's state (pageIndex, pageSize, their defaults and events, totalRowCount), pageCount
@fragiola/data-grid-vue/summary-rowssummaryRows(), the summary rows, Summary, SummaryRows, SummaryRow, SummaryCells, SummaryCell, their composables, typedSummaryRows<TRow>(); the feature's root props are SummaryRowsFeatureProps

Types

Each part exports its props and its slots, named as in React: RootProps, RootSlots, RootState, GridProps, GridSlots, HeaderProps, HeaderSlots, HeaderRowsProps, HeaderRowsSlots, HeaderRowProps, HeaderRowSlots, HeaderCellsProps, HeaderCellsSlots, HeaderCellProps, HeaderCellSlots, BodyProps, BodySlots, RowsProps, RowsSlots, RowProps, RowSlots, CellsProps, CellsSlots, CellProps, CellSlots, EmptyProps, EmptySlots; /row-expansion's RowDetailProps, RowDetailSlots; /summary-rows's SummaryProps, SummarySlots, SummaryRowsProps, SummaryRowsSlots, SummaryRowProps, SummaryRowSlots, SummaryCellsProps, SummaryCellsSlots, SummaryCellProps, SummaryCellSlots.

typedescription
DataGridComponent<Props, Slots>a part's component type: its props, plus any fallthrough attribute, and its scoped slots
TypedDataGrid<TRow, TFeatures>what typedDataGrid<TRow, TFeatures>() returns: every part typed by TRow, Root by the features' props too
PrimitivePropswhat every part accepts: as
AsPropa tag name or a component
RenderSlot<State>the render slot every part accepts
RenderSlotProps<State>what it receives: props, state, children
SlotFunction<Scope>a scoped slot: its scope in, the nodes it renders out
PartComposableResult<State>what a part composable returns: state and props, computed refs

React's DivPrimitiveProps, PrimitiveProps (its own: render, className, style), RenderedProps and RenderProp have no Vue counterpart: the slots and attributes above replace them.

Server rendering

Not supported yet in Vue: the Vue package renders in the browser. The React package's server rendering has no Vue counterpart today.