Patterns
Data table
Shows records in rows to sort, filter, select and page through, with columns that stay in view, rows in groups, rows of two or three lines, and cells that can be edited in place.
Unreleased
These changes are merged and will be in the next release of the packages.
- Data table: a selected row is marked by a bar at the start of its first cell as well as by its fill, 3px wide in
primary-text, as the Sidebar marks its active item, so a chosen row never rests on colour alone. In a pinned first cell the bar stays in view while the rest of the row scrolls sideways. Its grade stays tested. - Data table: group rows with
groupsandgetGroupId. Each group is its owntbodyunder a heading row, athwithscope="rowgroup"across every column, with the group's label, its count fromgroupCountand an optionaldescription. A collapsible group's label and count are a button witharia-expanded, and a collapsed group keeps its heading and count. Collapse state works controlled, withcollapsedGroupsandonCollapsedGroupsChange, or uncontrolled, withdefaultCollapsedGroups. The groups keep the order they are given, a column's sort applies within each group, and a group can take theinfotone or be marked not collapsible. A group's rows take a lighter shade of its heading's fill, pinned columns stay pinned inside groups, and a heading's words stay in view while the table scrolls sideways. Its grade stays tested. - Data table: a sortable column's heading is the same text size as a plain heading. It was the small button's size, so sorted and plain headings looked different in one row.
- Data table: pinned columns, fixed column widths and cells edited in place.
dataTableFeaturesnow registers TanStack Table's column pinning and column sizing. A column pinned withcolumnPinningstays at its side while the table scrolls sideways, on an opaque background that takes the row's fill, and the pinned column nearest the scrolling ones shows an edge once something is under it. The table measures the pinned columns, so their offsets are right at either density. Pinned columns stop sticking when together they would cover more than two thirds of the table's box. A column with asizekeeps that width in pixels, and a column without one fits its content as before. AddDataTableEditableCell: text edited in an Input in place, or any value edited in a popover througheditor, such as a date chosen from a Calendar. Enter or leaving saves, Escape cancels, focus returns to the cell, the row keeps its height, and the change is announced politely. The data table's registry item now depends on Input and Popover. Its grade stays tested. - Data table:
onRowClickis called when a row is clicked anywhere but on a control inside it, such as a link, a checkbox or a cell edited in place, and not when the click ends a selection of text or comes from a popover a cell opened. The row getscursor-pointeranddata-clickable, and stays a plain row with no tab stop: put a button in each row that does the same, for the keyboard and a screen reader.DataTableEditableCelldocumentsdisabled, which shows the cell faded and not pressable, witharia-describedbyfor the reason. Its grade stays tested. - Data table:
rowLinessets how many lines of text every row holds,2or3, and makes every row that tall.DataTableCellTextis text in a cell cut to the row's lines with an ellipsis, or a line sooner withreserveLines={1}, andDataTableEditableCellcuts what it shows at rest the same way.useDataTableRowLines()gives a cell the row's lines, so it can lay itself out by them, and the table carriesdata-row-lines. A column'smeta.widthtakes a CSS width in place ofsize, such as a width inemthat follows the density. Its grade stays tested.
0.1.0
- Data table, on TanStack Table 9, from its own entry point
@cadence-clinical/ui/data-tablewith TanStack Table as an optional peer dependency.DataTablerenders a table you build withuseTableanddataTableFeatures;DataTableColumnHeader,selectionColumn(),DataTablePaginationandDataTableViewOptionssort, select, page and show columns, with the state in words as well as marks. - A Data table with a sortable column no longer scrolls sideways when its columns fit. The sort button hung past the last column's padding, which put a scrollbar under every table. It now fills its heading cell, and its words line up with a plain heading's to the pixel.
- Data table:
DataTableColumnHeader,DataTablePaginationandDataTableViewOptionstake the props of the element they render, not onlyclassName, and mergeclassNamelast. The column header'sonClickruns before it sorts.DataTableViewOptionsPropsis exported. The rows-per-page label's id comes fromuseId, so two paginations on one page no longer share one, and a column heading that cannot sort carriesdata-slot="data-table-column-header".
Data table code
How to install Data table, its parts and props, pinned columns, column widths, grouped rows and cells edited in place, and how it differs from shadcn's data table.
Date picker
A date that can be typed or chosen from a calendar, with a time where one is wanted. What is typed is read in the locale's order.