Skip to content

Commit 5e442a7

Browse files
feat(Table): useTableColumnsVirtualization windows the unpinned columns
Table.virtualization accepts a columns capability, alone or in a list with at most one rows capability. Table mounts only the unpinned columns near the inline viewport, plus two overscan columns per side, and keeps the pinned start and end runs mounted. Each column's pitch is the width it renders at the table's minimum width. The header row and every body row render the same inaccessible spacer cells for unmounted columns. While columns window, the table carries aria-colcount and mounted cells carry full-table aria-colindex. The server and first client use the same seed from initialViewportWidth. Inline geometry comes from the shared Table viewport measurement. Unsupported content or structure renders every column with a development warning. With both capabilities, this slice windows the rows and renders every column. The retained focused column, the first-visible-column anchor and windowing both axes together come in later slices. This diff was generated with AI assistance (Navi). Tags: ai-generated
1 parent 6217d0f commit 5e442a7

21 files changed

Lines changed: 1620 additions & 55 deletions
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'@astryxdesign/core': patch
3+
---
4+
5+
[feat] Tables can window their columns: pass `useTableColumnsVirtualization({initialViewportWidth})` to `Table.virtualization`. Table keeps every column definition and width, mounts only the unpinned columns near the inline viewport plus two overscan columns per side, keeps pinned columns mounted, and gives mounted cells full-table `aria-colindex` values with `aria-colcount` on the table. When the scroll area is at least as wide as the table's minimum width, every column mounts. `Table.virtualization` also accepts a list with at most one rows and one columns capability; with both, this release windows the rows and renders every column. Unsupported content or structure renders every column with a development warning. Tables that do not opt in are unchanged.
6+
7+
@humbertovirtudes

‎apps/storybook/stories/TableVirtualization.stories.tsx‎

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@ import {
44
Card,
55
Table,
66
VStack,
7+
pixel,
8+
useTableColumnsVirtualization,
79
useTableRowsVirtualization,
10+
useTableStickyColumns,
11+
type TableColumn,
812
} from '@astryxdesign/core';
913
const rows = Array.from({length: 2000}, (_, index) => ({
1014
id: String(index),
@@ -65,3 +69,44 @@ function InCard() {
6569
export const InSizedCard: StoryObj = {
6670
render: () => <InCard />,
6771
};
72+
73+
type WideRow = Record<string, string> & {id: string};
74+
const wideColumns: TableColumn<WideRow>[] = [
75+
{key: 'name', header: 'Name', width: pixel(160)},
76+
...Array.from({length: 299}, (_, index) => ({
77+
key: `metric${index + 1}`,
78+
header: `Metric ${index + 1}`,
79+
width: pixel(120),
80+
})),
81+
];
82+
const wideRows: WideRow[] = Array.from({length: 200}, (_, row) => {
83+
const item: WideRow = {id: String(row), name: `Account ${row + 1}`};
84+
for (let index = 1; index < 300; index++) {
85+
item[`metric${index}`] = `${row + 1}.${index}`;
86+
}
87+
return item;
88+
});
89+
90+
function ColumnWindowingExample() {
91+
const virtualization = useTableColumnsVirtualization({
92+
initialViewportWidth: 900,
93+
});
94+
const sticky = useTableStickyColumns<WideRow>({startKeys: ['name']});
95+
// 300 columns and 200 rows: only the columns near the viewport mount.
96+
return (
97+
<VStack width={900}>
98+
<Table
99+
aria-label="Account metrics"
100+
data={wideRows}
101+
columns={wideColumns}
102+
idKey="id"
103+
plugins={{sticky}}
104+
virtualization={virtualization}
105+
dividers="grid"
106+
/>
107+
</VStack>
108+
);
109+
}
110+
export const ColumnWindowing: StoryObj = {
111+
render: () => <ColumnWindowingExample />,
112+
};

‎internal/shadcn-registry/routes.lock.json‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4371,6 +4371,11 @@
43714371
"path": "hooks/use-table-column-settings-state",
43724372
"aliases": []
43734373
},
4374+
{
4375+
"name": "hook-use-table-columns-virtualization",
4376+
"path": "hooks/use-table-columns-virtualization",
4377+
"aliases": []
4378+
},
43744379
{
43754380
"name": "hook-use-table-filter-state",
43764381
"path": "hooks/use-table-filter-state",

‎packages/core/api-report.md‎

Lines changed: 6 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)