Data table
ProBrowse, sort, filter, select and act on records, from the browser or a server, with saved views and a compact form. Not an M3 component (@windmorph/react-pro).
import { DataTable, DataTableToolbar, DataTableView, DataTablePagination, DataTableFilterChips, DataTableFilterDialog, DataTableColumnSettings, useDataTable } from '@windmorph/react-pro';Part of Windmorph Pro, paid components on the free core, not on sale yet. See the Pro guide for what it includes and to register interest.
Purpose
Browse, sort, filter, select and act on records, comparing them across columns. Use plain for a short read-only table, a DataGrid to edit cell by cell, and a List for items with a single column.
Column widths
width: 180(a number, the default) for values of a known, steady length: dates, amounts, ids, a status chip.width: 'fit'for text whose length follows the data or the language: names, places, labels. The column takes the widest of its header and values, withinminWidth(80 by default) andmaxWidth, so a translated value isn't cut short.grow, with either, for the column that takes the table's spare width, usually the main text column. A fit column that grows is never narrower than its content.- A person's resize wins: their width is saved in
state.widthsand fit stops for that column. Reset in column settings, or a double-click on its edge, brings fit back. - Client mode measures every row's value, so the widths stay put as people page, sort and search; server mode fits the rows on the page. A column with its own
cellfits the cells shown, so a cell that wraps or grows with its box (several tags, a progress bar) should take a number instead. - The server's HTML gives a fit column 180px until the browser measures it, once it shows and once the page's fonts load. A DataGrid's columns take numbers: it renders only the rows in view, so it can't measure the rest.
Height and scrolling
maxHeight(px, or any CSS length such as'60dvh') caps the rows: past it they scroll under the header, which stays in view. The compact list scrolls within the same height. Without it the table is as tall as its rows.- Columns wider than the table scroll sideways, and pinned columns stay in place. The keyboard reaches what's cut off: a grid's focus moves to every cell and brings it into view, and a
plaintable that cuts rows or columns off becomes a tab stop itself, a region named after the table, which the arrow and page keys scroll. The compact list kept tomaxHeightdoes the same whenever its rows have nothing to press. When nothing is cut off it is neither. - The arrow keys bring a cell into view only as far as it needs, so the page never jumps to centre the table.
- To let the page, or a region of your own, scroll the table instead, turn its scroller off with
classNames={{ container: 'overflow-visible' }}: the header then sticks to the nearest scrolling ancestor.
Behaviour
- Everything a person changes is one serializable
TableState: order, hidden columns, widths, pins, sort, filters, search, page and selection. PassstateandonStateChangeto save a view, andrepairTableStateto check a saved one against today's columns. mode="client"sorts, filters and pages the array, up to about 5,000 rows.mode="server"reports the state and takes one page andtotalRows; the row counts stay true for assistive technology.- A press on a header cycles ascending, descending and none. Shift adds a level, up to
maxSortLevels, and each change is announced. - Columns resize by dragging, or from the keyboard with R on a focused header. A double-click on a column's edge, or R then Enter, fits it to its content. They reorder by dragging a header, or in column settings, which also shows, hides and pins them.
- A selection survives page changes and clears when the search or filters change the set. In server mode the bulk bar offers every matching row, through
selection.allMatching. - Below
compactBelowof its own width the table becomes a list, through a container query, so the server's HTML is right. Each row shows its row header, with the next column that isn't end-aligned as supporting text; a table of figures with no such column lists every other column's name and value instead.renderCompactRowchooses what each row shows, and selection and actions carry over. useDataTableand theDataTable*parts compose the same pieces differently: pass the hook's result to each part astable.
When not to use
To edit cell by cell use a DataGrid; for single-column items, a List.
See also
- Data grid: Spreadsheet-style editing, virtualized both ways, with typed editors, validation, keyboard ranges, and copy and paste. Not an M3 component (@windmorph/react-pro).
- List: Rows with headline, overline, supporting text and leading or trailing content (icons, avatars, images, video thumbnails); items can be links, switches, checkboxes or radio buttons, and put in order by drag or a menu.
- Tree view: A hierarchy of rows that open and fold, with selection, their own controls and children that load. Not an M3 component (@windmorph/react-pro).