Import

import-grid.tsx
import { NuiGrid, type NuiGridColumn, type NuiGridHandle } from '@needless-ui/react/grid';

NuiGrid

A data grid on a native table.

NuiGrid: Properties
NameTypeDefaultDescription
rowsPropreadonly T[]The data. An edit replaces its row and calls onRowsChange; the next rows you pass replace the edits.
onRowsChangeCallback(rows: readonly T[]) => voidCalled with the rows after each committed edit.
columnsPropNuiGridColumn<T>[]The columns, as NuiGridColumn objects.
rowIdProp(row: T) => unknownrow.id ?? rowA row’s key, for selection and tracking.
labelPropstringThe grid’s accessible name.
selectionProp'none' | 'single' | 'multiple''none'Whether rows can be selected, and how many.
selected
defaultSelected
onSelectedChangeState
unknown[][]The keys of the selected rows.
sort
defaultSort
onSortChangeState
NuiGridSort[][]The sort, as { column, direction } objects; the first sorts first.
filters
defaultFilters
onFiltersChangeState
Record<string, NuiGridFilter>{}A filter per column id: an operator and a value.
search
defaultSearch
onSearchChangeState
string''Words that must all appear in a row.
pageSize
defaultPageSize
onPageSizeChangeState
number0Rows per page, or 0 for one scrolling list.
page
defaultPage
onPageChangeState
number0The page shown, from 0.
pageSizesPropnumber[][10, 25, 50, 100]The choices in the pager.
virtualPropboolean | 'auto''auto'Renders only the rows in view: always, never, or auto past 100 rows without pages.
heightPropstringA CSS length that bounds the grid; it scrolls inside.
columnState
defaultColumnState
onColumnStateChangeState
NuiGridColumnState[][]Each column’s width, order, pin and visibility, to save and restore.
modeProp'client' | 'server''client'server shows rows as they come and leaves sorting, filtering and paging to you.
totalPropnumberThe number of rows on the server.
loadingPropbooleanfalseShows a progress bar, and placeholder rows while there are none.
localePropstring'en-US'Formats numbers and dates, and reads typed numbers.
labelsPropPartial<NuiGridLabels>Every text the grid shows or announces, to translate.
cornersPropNuiCornersThe shape of its corners: round, squircle, bevel, scoop, notch or square.
radiusPropNuiRadiusHow big its corners are: none, small, medium, large or full.
densityPropNuiDensityHow much room it takes: compact, regular or roomy.
groupByPropstring[][]Columns to group rows by, outermost first.
collapsed
defaultCollapsed
onCollapsedChangeState
string[][]Keys of the groups closed; groups start open.
getChildrenProp(row: T) => T[] | undefinedA row’s children: the grid shows tree data.
expanded
defaultExpanded
onExpandedChangeState
unknown[][]Keys of the rows open in tree data; they start closed.
details
defaultDetails
onDetailsChangeState
unknown[][]Keys of the rows whose details are open.
totals, flashPropbooleanfalseA row of aggregates over every filtered row; cells that flash when their text changes, in rows with a lasting rowId.
layoutProp'table' | 'list' | 'auto''table'list shows rows as cards, and auto does on narrow screens.
toolbarPropboolean | 'auto''auto'A bar that sorts, filters and selects all rows: always, never, or auto with cards.
renderEmptyRender prop(filtered: boolean) => ReactNodeWhat shows when there are no rows; it’s told whether filters hid them.
renderDetailRender prop(row: T) => ReactNodeA row’s details, shown under it when opened. The grid adds a column of toggles.
onRowActivateCallback(row: T) => voidCalled with a row opened with Enter or a double click.
onCellEditCallback(edit: NuiGridEdit<T>) => voidCalled with each committed edit.
onQueryChangeCallback(query: NuiGridQuery) => voidCalled with the sort, filters, search and page whenever they change, and once at the start.
refPropRef<NuiGridHandle>What the grid’s ref reaches: exports, printing and focus.
exportXlsx, printMethod(options?) => Blob, () => voidThe filtered, sorted rows as a spreadsheet; prints every row.
exportCsvMethod(options?) => stringThe filtered, sorted rows of the visible columns, as CSV.
expandAllMethod(open?: boolean) => voidOpens every group and every row with children, or closes them all.
focusCellMethod(row: number, col: number) => voidFocuses a cell; row -1 is the header.
clearFiltersMethod() => voidClears every filter and the search.
fitMethod(id: string) => voidFits a column to the widest of its rendered cells.

State works like React’s own inputs: pass a value and update it from its on…Change callback, or pass a default… value and let the component keep it.

Customization props you leave unset follow the nearest data-nui-* attribute. See the customization guide.

NuiGridColumn

One column. It takes every property of the Angular column (only id and header are required), and these two that draw it.

NuiGridColumn: Properties
NameTypeDefaultDescription
renderCellRender prop({ row, value, text, column }) => ReactNodeDraws the column’s cells yourself, from the row, its value and its text.
renderHeaderRender prop(column) => ReactNodeDraws the column’s header yourself; header still names it.