-
-
Notifications
You must be signed in to change notification settings - Fork 94
Expand file tree
/
Copy pathVirtualizationExample.tsx
More file actions
63 lines (56 loc) · 1.62 KB
/
VirtualizationExample.tsx
File metadata and controls
63 lines (56 loc) · 1.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
'use client';
import { faker } from '@faker-js/faker';
import { Button, Center, Paper } from '@mantine/core';
import { DataTable } from '__PACKAGE__';
import { useState } from 'react';
import classes from './VirtualizationExample.module.css';
type User = {
id: string;
name: string;
age: number;
};
const userData: User[] = Array.from({ length: 2000 }, () => ({
id: faker.string.uuid(),
name: faker.person.fullName(),
age: faker.number.int({ min: 18, max: 65 }),
}));
export function VirtualizationExample() {
const [virtualized, setVirtualized] = useState(false);
const toggleVirtualized = () => setVirtualized((current) => !current);
// example-start
// ...
return (
<>
<DataTable
virtualize={virtualized}
borderRadius="sm"
withTableBorder
minHeight={200}
columns={[{ accessor: 'id' }, { accessor: 'name' }, { accessor: 'age' }]}
records={userData}
height={400}
rowExpansion={{
content: ({ record }) => (
<div style={{ padding: 10 }}>
<div>ID: {record.id}</div>
<div>Name: {record.name}</div>
<div>Age: {record.age}</div>
</div>
),
}}
/>
{/* example-skip */}
<Paper p="md" mt="sm" withBorder>
<Center>
<div className={classes.buttons}>
<Button className={classes.button} color="green" onClick={toggleVirtualized}>
{virtualized ? 'Disable' : 'Enable'} virtualization
</Button>
</div>
</Center>
</Paper>
{/* example-resume */}
</>
);
// example-end
}