-
-
Notifications
You must be signed in to change notification settings - Fork 535
Expand file tree
/
Copy pathTS.tsx
More file actions
88 lines (84 loc) · 2.22 KB
/
Copy pathTS.tsx
File metadata and controls
88 lines (84 loc) · 2.22 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import { useMemo } from 'react';
import {
MaterialReactTable,
type MRT_ColumnDef,
MRT_ToggleDensePaddingButton,
MRT_ToggleFullScreenButton,
useMaterialReactTable,
} from '@glebcha/material-react-table';
import { Box, Button, IconButton } from '@mui/material';
import PrintIcon from '@mui/icons-material/Print';
import { data, type Person } from './makeData';
const Example = () => {
const columns = useMemo<MRT_ColumnDef<Person>[]>(
//column definitions...
() => [
{
accessorKey: 'firstName',
header: 'First Name',
},
{
accessorKey: 'lastName',
header: 'Last Name',
},
{
accessorKey: 'age',
header: 'Age',
},
{
accessorKey: 'salary',
header: 'Salary',
},
],
[],
//end
);
const table = useMaterialReactTable({
columns,
data,
enableRowSelection: true,
positionToolbarAlertBanner: 'bottom', //show selected rows count on bottom toolbar
//add custom action buttons to top-left of top toolbar
renderTopToolbarCustomActions: ({ table }) => (
<Box sx={{ display: 'flex', gap: '1rem', p: '4px' }}>
<Button
color="secondary"
onClick={() => {
alert('Create New Account');
}}
variant="contained"
>
Create Account
</Button>
<Button
color="error"
disabled={!table.getIsSomeRowsSelected()}
onClick={() => {
alert('Delete Selected Accounts');
}}
variant="contained"
>
Delete Selected Accounts
</Button>
</Box>
),
//customize built-in buttons in the top-right of top toolbar
renderToolbarInternalActions: ({ table }) => (
<Box>
{/* add custom button to print table */}
<IconButton
onClick={() => {
window.print();
}}
>
<PrintIcon />
</IconButton>
{/* along-side built-in buttons in whatever order you want them */}
<MRT_ToggleDensePaddingButton table={table} />
<MRT_ToggleFullScreenButton table={table} />
</Box>
),
});
return <MaterialReactTable table={table} />;
};
export default Example;