material-react-table 0.12.1 → 0.12.2

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,3 +1,2 @@
1
- /// <reference types="react" />
2
1
  import { MaterialReactTableProps } from '../MaterialReactTable';
3
2
  export declare const MRT_TableRoot: <D extends Record<string, any> = {}>(props: MaterialReactTableProps<D>) => JSX.Element;
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.12.1",
2
+ "version": "0.12.2",
3
3
  "license": "MIT",
4
4
  "name": "material-react-table",
5
5
  "description": "A fully featured Material UI implementation of TanStack React Table, inspired by material-table and the MUI X DataGrid, written from the ground up in TypeScript.",
@@ -153,87 +153,104 @@ export const MRT_TableRoot = <D extends Record<string, any> = {}>(
153
153
  [],
154
154
  );
155
155
 
156
- const displayColumns = useMemo(
157
- () =>
158
- [
159
- showActionColumn &&
160
- createDisplayColumn(table, {
161
- Cell: ({ cell }) => (
162
- <MRT_ToggleRowActionMenuButton
163
- row={cell.row as any}
164
- instance={instance}
165
- />
166
- ),
167
- header: props.localization?.actions,
168
- id: 'mrt-row-actions',
169
- muiTableBodyCellProps: props.muiTableBodyCellProps,
170
- muiTableHeadCellProps: props.muiTableHeadCellProps,
171
- size: 70,
172
- }),
173
- showExpandColumn &&
174
- createDisplayColumn(table, {
175
- Cell: ({ cell }) => (
176
- <MRT_ExpandButton row={cell.row as any} instance={instance} />
177
- ),
178
- Header: () =>
179
- props.enableExpandAll ? (
180
- <MRT_ExpandAllButton instance={instance} />
181
- ) : null,
182
- header: props.localization?.expand,
183
- id: 'mrt-expand',
184
- muiTableBodyCellProps: props.muiTableBodyCellProps,
185
- muiTableHeadCellProps: props.muiTableHeadCellProps,
186
- size: 50,
187
- }),
188
- props.enableRowSelection &&
189
- createDisplayColumn(table, {
190
- Cell: ({ cell }) => (
191
- <MRT_SelectCheckbox row={cell.row as any} instance={instance} />
192
- ),
193
- Header: () =>
194
- props.enableSelectAll ? (
195
- <MRT_SelectCheckbox selectAll instance={instance} />
196
- ) : null,
197
- header: props.localization?.select,
198
- id: 'mrt-select',
199
- muiTableBodyCellProps: props.muiTableBodyCellProps,
200
- muiTableHeadCellProps: props.muiTableHeadCellProps,
201
- size: 50,
202
- }),
203
- props.enableRowNumbers &&
204
- createDisplayColumn(table, {
205
- Cell: ({ cell }) => cell.row.index + 1,
206
- Header: () => props.localization?.rowNumber,
207
- header: props.localization?.rowNumbers,
208
- id: 'mrt-row-numbers',
209
- muiTableBodyCellProps: props.muiTableBodyCellProps,
210
- muiTableHeadCellProps: props.muiTableHeadCellProps,
211
- size: 50,
212
- }),
213
- ].filter(Boolean),
214
- [
215
- props.editingMode,
216
- props.enableEditing,
217
- props.enableExpandAll,
218
- props.enableExpanding,
219
- props.enableGrouping,
220
- props.enableRowActions,
221
- props.enableRowNumbers,
222
- props.enableRowSelection,
223
- props.enableSelectAll,
224
- props.localization,
225
- table,
226
- ],
227
- );
156
+ const [leadingDisplayColumns, trailingDisplayColumns] = useMemo(() => {
157
+ const leadingDisplayColumns = [
158
+ showActionColumn &&
159
+ createDisplayColumn(table, {
160
+ Cell: ({ cell }) => (
161
+ <MRT_ToggleRowActionMenuButton
162
+ row={cell.row as any}
163
+ instance={instance}
164
+ />
165
+ ),
166
+ header: props.localization?.actions,
167
+ id: 'mrt-row-actions',
168
+ muiTableBodyCellProps: props.muiTableBodyCellProps,
169
+ muiTableHeadCellProps: props.muiTableHeadCellProps,
170
+ size: 70,
171
+ }),
172
+ showExpandColumn &&
173
+ createDisplayColumn(table, {
174
+ Cell: ({ cell }) => (
175
+ <MRT_ExpandButton row={cell.row as any} instance={instance} />
176
+ ),
177
+ Header: () =>
178
+ props.enableExpandAll ? (
179
+ <MRT_ExpandAllButton instance={instance} />
180
+ ) : null,
181
+ header: props.localization?.expand,
182
+ id: 'mrt-expand',
183
+ muiTableBodyCellProps: props.muiTableBodyCellProps,
184
+ muiTableHeadCellProps: props.muiTableHeadCellProps,
185
+ size: 50,
186
+ }),
187
+ props.enableRowSelection &&
188
+ createDisplayColumn(table, {
189
+ Cell: ({ cell }) => (
190
+ <MRT_SelectCheckbox row={cell.row as any} instance={instance} />
191
+ ),
192
+ Header: () =>
193
+ props.enableSelectAll ? (
194
+ <MRT_SelectCheckbox selectAll instance={instance} />
195
+ ) : null,
196
+ header: props.localization?.select,
197
+ id: 'mrt-select',
198
+ muiTableBodyCellProps: props.muiTableBodyCellProps,
199
+ muiTableHeadCellProps: props.muiTableHeadCellProps,
200
+ size: 50,
201
+ }),
202
+ props.enableRowNumbers &&
203
+ createDisplayColumn(table, {
204
+ Cell: ({ cell }) => cell.row.index + 1,
205
+ Header: () => props.localization?.rowNumber,
206
+ header: props.localization?.rowNumbers,
207
+ id: 'mrt-row-numbers',
208
+ muiTableBodyCellProps: props.muiTableBodyCellProps,
209
+ muiTableHeadCellProps: props.muiTableHeadCellProps,
210
+ size: 50,
211
+ }),
212
+ ].filter(Boolean) as MRT_ColumnDef<D>[];
213
+
214
+ const trailingDisplayColumns = [] as MRT_ColumnDef<D>[];
215
+
216
+ if (props.enableRowActions && props.positionActionsColumn === 'last') {
217
+ trailingDisplayColumns.push(
218
+ ...leadingDisplayColumns.splice(
219
+ leadingDisplayColumns.findIndex(
220
+ (col) => col.id === 'mrt-row-actions',
221
+ ),
222
+ 1,
223
+ ),
224
+ );
225
+ }
226
+
227
+ return [leadingDisplayColumns, trailingDisplayColumns];
228
+ }, [
229
+ props.editingMode,
230
+ props.enableEditing,
231
+ props.enableExpandAll,
232
+ props.enableExpanding,
233
+ props.enableGrouping,
234
+ props.enableRowActions,
235
+ props.enableRowNumbers,
236
+ props.enableRowSelection,
237
+ props.enableSelectAll,
238
+ props.localization,
239
+ props.muiTableBodyCellProps,
240
+ props.muiTableHeadCellProps,
241
+ props.positionActionsColumn,
242
+ table,
243
+ ]);
228
244
 
229
245
  const columns = useMemo(
230
246
  () => [
231
- ...displayColumns,
247
+ ...leadingDisplayColumns,
232
248
  ...props.columns.map((column) =>
233
249
  column.columns
234
250
  ? createGroup(table, column as any, currentFilterFns)
235
251
  : createDataColumn(table, column as any, currentFilterFns),
236
252
  ),
253
+ ...trailingDisplayColumns,
237
254
  ],
238
255
  [table, props.columns, currentFilterFns],
239
256
  );