-
-
Notifications
You must be signed in to change notification settings - Fork 534
Expand file tree
/
Copy pathTS.tsx
More file actions
70 lines (66 loc) · 1.7 KB
/
TS.tsx
File metadata and controls
70 lines (66 loc) · 1.7 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
import { useMemo } from 'react';
import {
MaterialReactTable,
useMaterialReactTable,
type MRT_ColumnDef,
} from 'material-react-table';
import { data, type Person } from './makeData';
import { MenuItem } from '@mui/material';
const Example = () => {
const columns = useMemo<MRT_ColumnDef<Person>[]>(
() => [
{
accessorKey: 'id',
enableColumnPinning: false, //disable column pinning for this column
header: 'ID',
size: 50,
},
//column definitions...
{
accessorKey: 'firstName',
header: 'First Name',
},
{
accessorKey: 'middleName',
header: 'Middle Name',
},
{
accessorKey: 'lastName',
header: 'Last Name',
},
{
accessorKey: 'address',
header: 'Address',
size: 300,
},
//end
{
accessorKey: 'city', //this column gets pinned to the right by default because of the initial state,
header: 'City',
},
{
accessorKey: 'state', //this column gets pinned left by default because of the the initial state,
header: 'State',
},
{
accessorKey: 'country',
header: 'Country',
},
],
[],
);
const table = useMaterialReactTable({
columns,
data,
enableColumnPinning: true,
enableColumnResetPins: true,
enableRowActions: true,
layoutMode: 'grid-no-grow', //constant column widths
renderRowActionMenuItems: () => [<MenuItem key="action">Action</MenuItem>],
initialState: {
columnPinning: { left: ['mrt-row-actions', 'state'], right: ['city'] },
},
});
return <MaterialReactTable table={table} />;
};
export default Example;