-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(ts-table): interaction between getSelectionColumn and Virtualizat…
…ion (#2051)
- Loading branch information
Showing
2 changed files
with
70 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
packages/ts-table/src/stories/virtualized-selection.stories.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import { useMemo } from 'react' | ||
import type { ColumnDef } from '@tanstack/react-table' | ||
import { faker } from '@faker-js/faker' | ||
|
||
import { useVirtualizerModel } from '../use-virtualizer-model' | ||
import { getSelectionColumn, TsTable } from '../index' | ||
|
||
export default { | ||
title: 'ts-table/ts-table', | ||
parameters: { | ||
chromatic: { disableSnapshot: true }, | ||
}, | ||
} | ||
|
||
interface Service { | ||
name: string | ||
department: string | ||
price: string | ||
} | ||
|
||
const data: Service[] = Array(50000) | ||
.fill(1) | ||
.map((_, id) => { | ||
return { | ||
id: `${id}`, | ||
name: faker.company.name(), | ||
price: faker.commerce.price(), | ||
department: faker.commerce.department(), | ||
} | ||
}) | ||
|
||
export function VirtualizedSelection() { | ||
const columns = useMemo<Array<ColumnDef<Service>>>( | ||
() => [ | ||
getSelectionColumn(), | ||
{ | ||
accessorKey: 'name', | ||
header: 'Service name', | ||
}, | ||
{ | ||
accessorKey: 'price', | ||
header: 'Price', | ||
}, | ||
], | ||
[] | ||
) | ||
|
||
const virtualizer = useVirtualizerModel({ | ||
count: data.length, | ||
}) | ||
|
||
return ( | ||
<> | ||
<TsTable | ||
data={data} | ||
columns={columns} | ||
rowClick={{ | ||
type: 'action', | ||
onClick: (row) => { | ||
alert(`You clicked: ${row.original.name}`) | ||
}, | ||
}} | ||
virtualizer={virtualizer} | ||
/> | ||
<div style={{ marginTop: '16px' }}>Number of rows: {data.length}</div> | ||
</> | ||
) | ||
} |