@lminii/material-react-table 4.0.0 → 4.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,213 +1,213 @@
1
- ---
2
- name: getting-started
3
- description: >
4
- Build a Material React Table V4 with useMaterialReactTable and the MaterialReactTable table prop: install @lminii/material-react-table with Material UI V9 peers, define stable data and MRT_ColumnDef columns, toggle features with enable* options, and read the instance. Load for a first MRT table, a Material UI data grid on TanStack Table V9, or when a TanStack useTable or upstream material-react-table example is producing the wrong setup.
5
- metadata:
6
- type: framework
7
- library: '@lminii/material-react-table'
8
- library_version: '4.0.0'
9
- framework: react
10
- requires:
11
- - '@tanstack/table-core#core'
12
- sources:
13
- - 'lminii/material-react-table:apps/material-react-table-docs/pages/docs/getting-started/install.mdx'
14
- - 'lminii/material-react-table:apps/material-react-table-docs/pages/docs/getting-started/usage.mdx'
15
- - 'lminii/material-react-table:apps/material-react-table-docs/pages/docs/guides/best-practices.mdx'
16
- - 'lminii/material-react-table:packages/material-react-table/src/hooks/useMaterialReactTable.ts'
17
- - 'lminii/material-react-table:packages/material-react-table/src/types.ts'
18
- ---
19
-
20
- This skill builds on `@tanstack/table-core#core` for the headless model and stable inputs. Material React Table (MRT) owns the TanStack Table instance, feature registration, and all Material UI rendering. Application code never calls `useTable` or `tableFeatures`; it configures MRT options and renders MRT components.
21
-
22
- ## Setup
23
-
24
- ```bash
25
- npm install @lminii/material-react-table @mui/material@^9 @mui/icons-material@^9 @mui/x-date-pickers@^9 @emotion/react @emotion/styled
26
- ```
27
-
28
- Do not install `@tanstack/react-table`; MRT pins its own exact version. Node 22.12 or newer is required for the CommonJS build because TanStack Table V9 is ESM-only.
29
-
30
- ```tsx
31
- import { useMemo } from 'react'
32
- import {
33
- MaterialReactTable,
34
- useMaterialReactTable,
35
- type MRT_ColumnDef,
36
- } from '@lminii/material-react-table'
37
-
38
- type Person = { name: string; age: number }
39
-
40
- const data: Person[] = [
41
- { name: 'Ada', age: 36 },
42
- { name: 'Grace', age: 45 },
43
- ]
44
-
45
- export function PeopleTable() {
46
- const columns = useMemo<MRT_ColumnDef<Person>[]>(
47
- () => [
48
- { accessorKey: 'name', header: 'Name' },
49
- { accessorKey: 'age', header: 'Age' },
50
- ],
51
- [],
52
- )
53
-
54
- const table = useMaterialReactTable({
55
- columns,
56
- data,
57
- enableRowSelection: true,
58
- })
59
-
60
- return <MaterialReactTable table={table} />
61
- }
62
- ```
63
-
64
- `useMaterialReactTable(options)` returns an `MRT_TableInstance<TData>`. Every MRT component takes that instance through a `table` prop; nothing is passed through React context.
65
-
66
- ## Core Patterns
67
-
68
- ### Accessors return primitives, renders return markup
69
-
70
- ```tsx
71
- const columns: MRT_ColumnDef<Person>[] = [
72
- {
73
- accessorFn: (row) => `${row.firstName} ${row.lastName}`,
74
- id: 'fullName',
75
- header: 'Name',
76
- Cell: ({ cell, row }) => (
77
- <a href={row.original.profileUrl}>{cell.getValue<string>()}</a>
78
- ),
79
- },
80
- ]
81
- ```
82
-
83
- `accessorKey` or `accessorFn` feeds sorting, filtering, grouping, and search, so it must return a string, number, boolean, or Date. `Cell`, `Header`, `Footer`, `Edit`, `Filter`, `AggregatedCell`, and `GroupedCell` are the render slots. An `accessorFn` column needs an explicit `id`.
84
-
85
- ### Infer column types with createMRTColumnHelper
86
-
87
- ```tsx
88
- import { createMRTColumnHelper } from '@lminii/material-react-table'
89
-
90
- const helper = createMRTColumnHelper<Person>()
91
- const columns = [
92
- helper.accessor('name', { header: 'Name' }),
93
- helper.accessor((row) => row.age, {
94
- id: 'age',
95
- header: 'Age',
96
- Cell: ({ cell }) => cell.getValue().toLocaleString(), // typed number
97
- }),
98
- helper.display({ id: 'actions', header: 'Actions' }),
99
- ]
100
- ```
101
-
102
- ### Toggle features with enable* options
103
-
104
- Table-level `enable*` options switch a feature on for every column; the same option on a column definition overrides it for that column. `enableColumnFilters`, `enableSorting`, `enablePagination`, `enableGlobalFilter`, `enableColumnActions`, `enableDensityToggle`, `enableFullScreenToggle`, `enableHiding`, and `enableTopToolbar` are on by default. Row selection, editing, grouping, pinning, ordering, expanding, virtualization, and row actions are off until enabled.
105
-
106
- ```tsx
107
- const table = useMaterialReactTable({
108
- columns,
109
- data,
110
- enableColumnOrdering: true,
111
- enableColumnPinning: true,
112
- enableGrouping: true,
113
- enablePagination: false,
114
- renderDetailPanel: ({ row }) => <pre>{JSON.stringify(row.original)}</pre>,
115
- })
116
- ```
117
-
118
- ### Read the instance where you need it
119
-
120
- ```tsx
121
- const selectedRows = table.getSelectedRowModel().rows
122
- const { pagination, sorting } = table.getState()
123
- table.resetRowSelection()
124
- ```
125
-
126
- `table.getState()` returns the full MRT state, including MRT-only slices such as `density`, `isFullScreen`, and `showColumnFilters`. Inside render code `table.state` is the reactive equivalent.
127
-
128
- ## Common Mistakes
129
-
130
- ### HIGH Building the table with TanStack hooks
131
-
132
- Wrong:
133
-
134
- ```tsx
135
- const table = useTable({ features, columns, data })
136
- return <MaterialReactTable table={table} />
137
- ```
138
-
139
- Correct:
140
-
141
- ```tsx
142
- const table = useMaterialReactTable({ columns, data })
143
- return <MaterialReactTable table={table} />
144
- ```
145
-
146
- `MaterialReactTable` needs the MRT instance, which registers MRT's features, display columns, localization, icons, and Material UI props. A bare TanStack instance lacks all of them.
147
-
148
- Source: `packages/material-react-table/src/hooks/useMaterialReactTable.ts`
149
-
150
- ### HIGH Unstable data or columns
151
-
152
- Wrong:
153
-
154
- ```tsx
155
- const table = useMaterialReactTable({
156
- columns: [{ accessorKey: 'name', header: 'Name' }],
157
- data: response.data ?? [],
158
- })
159
- ```
160
-
161
- Correct:
162
-
163
- ```tsx
164
- const columns = useMemo<MRT_ColumnDef<Person>[]>(() => [...], [])
165
- const EMPTY: Person[] = []
166
- const table = useMaterialReactTable({ columns, data: response.data ?? EMPTY })
167
- ```
168
-
169
- A new array each render invalidates every row model and can loop forever. Keep `columns` and `data` in `useMemo`, `useState`, module scope, or a query cache.
170
-
171
- Source: `docs/getting-started/usage.mdx`
172
-
173
- ### MEDIUM Mixing the upstream and fork package names
174
-
175
- Wrong:
176
-
177
- ```tsx
178
- import { MaterialReactTable } from 'material-react-table'
179
- import { MRT_Localization_DE } from '@lminii/material-react-table/locales/de'
180
- ```
181
-
182
- Correct:
183
-
184
- ```tsx
185
- import { MaterialReactTable } from '@lminii/material-react-table'
186
- import { MRT_Localization_DE } from '@lminii/material-react-table/locales/de'
187
- ```
188
-
189
- Two copies of MRT produce two `MRT_TableInstance` types and duplicate Emotion styles. Pick the fork everywhere, or alias `material-react-table` to it in `package.json`.
190
-
191
- Source: `MIGRATION.md`
192
-
193
- ### MEDIUM Returning JSX from an accessor
194
-
195
- Wrong:
196
-
197
- ```tsx
198
- { accessorFn: (row) => <b>{row.name}</b>, id: 'name', header: 'Name' }
199
- ```
200
-
201
- Correct:
202
-
203
- ```tsx
204
- { accessorKey: 'name', header: 'Name', Cell: ({ cell }) => <b>{cell.getValue<string>()}</b> }
205
- ```
206
-
207
- Sorting, filtering, and global search compare accessor values, so JSX breaks all three.
208
-
209
- Source: `docs/getting-started/usage.mdx`
210
-
211
- ## API Discovery
212
-
213
- Read `node_modules/@lminii/material-react-table/dist/index.d.ts` for `MRT_TableOptions`, `MRT_ColumnDef`, `MRT_TableInstance`, and `MRT_TableState`; the `mui*Props`, `render*`, `enable*`, and `on*Change` option families are all declared there with JSDoc. The docs prop tables at `/docs/api/table-options`, `/docs/api/column-options`, and `/docs/api/state-options` list every option with its default and source library.
1
+ ---
2
+ name: getting-started
3
+ description: >
4
+ Build a Material React Table V4 with useMaterialReactTable and the MaterialReactTable table prop: install @lminii/material-react-table with Material UI V9 peers, define stable data and MRT_ColumnDef columns, toggle features with enable* options, and read the instance. Load for a first MRT table, a Material UI data grid on TanStack Table V9, or when a TanStack useTable or upstream material-react-table example is producing the wrong setup.
5
+ metadata:
6
+ type: framework
7
+ library: '@lminii/material-react-table'
8
+ library_version: '4.0.0'
9
+ framework: react
10
+ requires:
11
+ - '@tanstack/table-core#core'
12
+ sources:
13
+ - 'lminii/material-react-table:apps/material-react-table-docs/pages/docs/getting-started/install.mdx'
14
+ - 'lminii/material-react-table:apps/material-react-table-docs/pages/docs/getting-started/usage.mdx'
15
+ - 'lminii/material-react-table:apps/material-react-table-docs/pages/docs/guides/best-practices.mdx'
16
+ - 'lminii/material-react-table:packages/material-react-table/src/hooks/useMaterialReactTable.ts'
17
+ - 'lminii/material-react-table:packages/material-react-table/src/types.ts'
18
+ ---
19
+
20
+ This skill builds on `@tanstack/table-core#core` for the headless model and stable inputs. Material React Table (MRT) owns the TanStack Table instance, feature registration, and all Material UI rendering. Application code never calls `useTable` or `tableFeatures`; it configures MRT options and renders MRT components.
21
+
22
+ ## Setup
23
+
24
+ ```bash
25
+ npm install @lminii/material-react-table @mui/material@^9 @mui/icons-material@^9 @mui/x-date-pickers@^9 @emotion/react @emotion/styled
26
+ ```
27
+
28
+ Do not install `@tanstack/react-table`; MRT pins its own exact version. Node 22.12 or newer is required for the CommonJS build because TanStack Table V9 is ESM-only.
29
+
30
+ ```tsx
31
+ import { useMemo } from 'react'
32
+ import {
33
+ MaterialReactTable,
34
+ useMaterialReactTable,
35
+ type MRT_ColumnDef,
36
+ } from '@lminii/material-react-table'
37
+
38
+ type Person = { name: string; age: number }
39
+
40
+ const data: Person[] = [
41
+ { name: 'Ada', age: 36 },
42
+ { name: 'Grace', age: 45 },
43
+ ]
44
+
45
+ export function PeopleTable() {
46
+ const columns = useMemo<MRT_ColumnDef<Person>[]>(
47
+ () => [
48
+ { accessorKey: 'name', header: 'Name' },
49
+ { accessorKey: 'age', header: 'Age' },
50
+ ],
51
+ [],
52
+ )
53
+
54
+ const table = useMaterialReactTable({
55
+ columns,
56
+ data,
57
+ enableRowSelection: true,
58
+ })
59
+
60
+ return <MaterialReactTable table={table} />
61
+ }
62
+ ```
63
+
64
+ `useMaterialReactTable(options)` returns an `MRT_TableInstance<TData>`. Every MRT component takes that instance through a `table` prop; nothing is passed through React context.
65
+
66
+ ## Core Patterns
67
+
68
+ ### Accessors return primitives, renders return markup
69
+
70
+ ```tsx
71
+ const columns: MRT_ColumnDef<Person>[] = [
72
+ {
73
+ accessorFn: (row) => `${row.firstName} ${row.lastName}`,
74
+ id: 'fullName',
75
+ header: 'Name',
76
+ Cell: ({ cell, row }) => (
77
+ <a href={row.original.profileUrl}>{cell.getValue<string>()}</a>
78
+ ),
79
+ },
80
+ ]
81
+ ```
82
+
83
+ `accessorKey` or `accessorFn` feeds sorting, filtering, grouping, and search, so it must return a string, number, boolean, or Date. `Cell`, `Header`, `Footer`, `Edit`, `Filter`, `AggregatedCell`, and `GroupedCell` are the render slots. An `accessorFn` column needs an explicit `id`.
84
+
85
+ ### Infer column types with createMRTColumnHelper
86
+
87
+ ```tsx
88
+ import { createMRTColumnHelper } from '@lminii/material-react-table'
89
+
90
+ const helper = createMRTColumnHelper<Person>()
91
+ const columns = [
92
+ helper.accessor('name', { header: 'Name' }),
93
+ helper.accessor((row) => row.age, {
94
+ id: 'age',
95
+ header: 'Age',
96
+ Cell: ({ cell }) => cell.getValue().toLocaleString(), // typed number
97
+ }),
98
+ helper.display({ id: 'actions', header: 'Actions' }),
99
+ ]
100
+ ```
101
+
102
+ ### Toggle features with enable* options
103
+
104
+ Table-level `enable*` options switch a feature on for every column; the same option on a column definition overrides it for that column. `enableColumnFilters`, `enableSorting`, `enablePagination`, `enableGlobalFilter`, `enableColumnActions`, `enableDensityToggle`, `enableFullScreenToggle`, `enableHiding`, and `enableTopToolbar` are on by default. Row selection, editing, grouping, pinning, ordering, expanding, virtualization, and row actions are off until enabled.
105
+
106
+ ```tsx
107
+ const table = useMaterialReactTable({
108
+ columns,
109
+ data,
110
+ enableColumnOrdering: true,
111
+ enableColumnPinning: true,
112
+ enableGrouping: true,
113
+ enablePagination: false,
114
+ renderDetailPanel: ({ row }) => <pre>{JSON.stringify(row.original)}</pre>,
115
+ })
116
+ ```
117
+
118
+ ### Read the instance where you need it
119
+
120
+ ```tsx
121
+ const selectedRows = table.getSelectedRowModel().rows
122
+ const { pagination, sorting } = table.getState()
123
+ table.resetRowSelection()
124
+ ```
125
+
126
+ `table.getState()` returns the full MRT state, including MRT-only slices such as `density`, `isFullScreen`, and `showColumnFilters`. Inside render code `table.state` is the reactive equivalent.
127
+
128
+ ## Common Mistakes
129
+
130
+ ### HIGH Building the table with TanStack hooks
131
+
132
+ Wrong:
133
+
134
+ ```tsx
135
+ const table = useTable({ features, columns, data })
136
+ return <MaterialReactTable table={table} />
137
+ ```
138
+
139
+ Correct:
140
+
141
+ ```tsx
142
+ const table = useMaterialReactTable({ columns, data })
143
+ return <MaterialReactTable table={table} />
144
+ ```
145
+
146
+ `MaterialReactTable` needs the MRT instance, which registers MRT's features, display columns, localization, icons, and Material UI props. A bare TanStack instance lacks all of them.
147
+
148
+ Source: `packages/material-react-table/src/hooks/useMaterialReactTable.ts`
149
+
150
+ ### HIGH Unstable data or columns
151
+
152
+ Wrong:
153
+
154
+ ```tsx
155
+ const table = useMaterialReactTable({
156
+ columns: [{ accessorKey: 'name', header: 'Name' }],
157
+ data: response.data ?? [],
158
+ })
159
+ ```
160
+
161
+ Correct:
162
+
163
+ ```tsx
164
+ const columns = useMemo<MRT_ColumnDef<Person>[]>(() => [...], [])
165
+ const EMPTY: Person[] = []
166
+ const table = useMaterialReactTable({ columns, data: response.data ?? EMPTY })
167
+ ```
168
+
169
+ A new array each render invalidates every row model and can loop forever. Keep `columns` and `data` in `useMemo`, `useState`, module scope, or a query cache.
170
+
171
+ Source: `docs/getting-started/usage.mdx`
172
+
173
+ ### MEDIUM Mixing the upstream and fork package names
174
+
175
+ Wrong:
176
+
177
+ ```tsx
178
+ import { MaterialReactTable } from 'material-react-table'
179
+ import { MRT_Localization_DE } from '@lminii/material-react-table/locales/de'
180
+ ```
181
+
182
+ Correct:
183
+
184
+ ```tsx
185
+ import { MaterialReactTable } from '@lminii/material-react-table'
186
+ import { MRT_Localization_DE } from '@lminii/material-react-table/locales/de'
187
+ ```
188
+
189
+ Two copies of MRT produce two `MRT_TableInstance` types and duplicate Emotion styles. Pick the fork everywhere, or alias `material-react-table` to it in `package.json`.
190
+
191
+ Source: `MIGRATION.md`
192
+
193
+ ### MEDIUM Returning JSX from an accessor
194
+
195
+ Wrong:
196
+
197
+ ```tsx
198
+ { accessorFn: (row) => <b>{row.name}</b>, id: 'name', header: 'Name' }
199
+ ```
200
+
201
+ Correct:
202
+
203
+ ```tsx
204
+ { accessorKey: 'name', header: 'Name', Cell: ({ cell }) => <b>{cell.getValue<string>()}</b> }
205
+ ```
206
+
207
+ Sorting, filtering, and global search compare accessor values, so JSX breaks all three.
208
+
209
+ Source: `docs/getting-started/usage.mdx`
210
+
211
+ ## API Discovery
212
+
213
+ Read `node_modules/@lminii/material-react-table/dist/index.d.ts` for `MRT_TableOptions`, `MRT_ColumnDef`, `MRT_TableInstance`, and `MRT_TableState`; the `mui*Props`, `render*`, `enable*`, and `on*Change` option families are all declared there with JSDoc. The docs prop tables at `/docs/api/table-options`, `/docs/api/column-options`, and `/docs/api/state-options` list every option with its default and source library.