material-react-table 0.16.2 → 0.17.0

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.
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.16.2",
2
+ "version": "0.17.0",
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.",
@@ -401,7 +401,6 @@ export type MaterialReactTableProps<D extends Record<string, any> = {}> =
401
401
  enableGlobalFilterChangeMode?: boolean;
402
402
  enableGlobalFilterRankedResults?: boolean;
403
403
  enablePagination?: boolean;
404
- enablePersistentState?: boolean;
405
404
  enableRowActions?: boolean;
406
405
  enableRowNumbers?: boolean;
407
406
  enableRowVirtualization?: boolean;
@@ -782,7 +781,6 @@ export type MaterialReactTableProps<D extends Record<string, any> = {}> =
782
781
  instance: MRT_TableInstance<D>;
783
782
  showGlobalFilter: boolean;
784
783
  }) => void;
785
- persistentStateMode?: 'localStorage' | 'sessionStorage';
786
784
  positionActionsColumn?: 'first' | 'last';
787
785
  positionGlobalFilter?: 'left' | 'right';
788
786
  positionPagination?: 'bottom' | 'top' | 'both';
@@ -845,6 +843,7 @@ export type MaterialReactTableProps<D extends Record<string, any> = {}> =
845
843
  IconButtonProps & { instance: MRT_TableInstance<D> }
846
844
  >;
847
845
  }) => ReactNode;
846
+ rowCount?: number;
848
847
  rowNumberMode?: 'original' | 'static';
849
848
  selectAllMode?: 'all' | 'page';
850
849
  tableId?: string;
@@ -885,7 +884,6 @@ export default <D extends Record<string, any> = {}>({
885
884
  enableToolbarTop = true,
886
885
  icons,
887
886
  localization,
888
- persistentStateMode = 'sessionStorage',
889
887
  positionActionsColumn = 'first',
890
888
  positionGlobalFilter = 'right',
891
889
  positionPagination = 'bottom',
@@ -928,7 +926,6 @@ export default <D extends Record<string, any> = {}>({
928
926
  enableToolbarTop={enableToolbarTop}
929
927
  icons={{ ...MRT_Default_Icons, ...icons }}
930
928
  localization={{ ...MRT_DefaultLocalization_EN, ...localization }}
931
- persistentStateMode={persistentStateMode}
932
929
  positionActionsColumn={positionActionsColumn}
933
930
  positionGlobalFilter={positionGlobalFilter}
934
931
  positionPagination={positionPagination}
@@ -177,9 +177,13 @@ export const MRT_FilterTextField: FC<Props> = ({
177
177
  const allowedColumnFilterOptions =
178
178
  columnDef?.enabledColumnFilterOptions ?? enabledColumnFilterOptions;
179
179
 
180
- const allowColumnChangeMode =
180
+ const showChangeModeButton =
181
181
  enableColumnFilterChangeMode &&
182
- columnDef.enableColumnFilterChangeMode !== false;
182
+ columnDef.enableColumnFilterChangeMode !== false &&
183
+ !isSelectFilter &&
184
+ !inputIndex &&
185
+ (allowedColumnFilterOptions === undefined ||
186
+ !!allowedColumnFilterOptions?.length);
183
187
 
184
188
  return (
185
189
  <>
@@ -195,10 +199,7 @@ export const MRT_FilterTextField: FC<Props> = ({
195
199
  title: filterPlaceholder,
196
200
  }}
197
201
  helperText={
198
- allowColumnChangeMode &&
199
- !inputIndex &&
200
- (allowedColumnFilterOptions === undefined ||
201
- (allowedColumnFilterOptions?.length ?? 0) > 0) ? (
202
+ showChangeModeButton ? (
202
203
  <label htmlFor={filterId}>
203
204
  {filterFn instanceof Function
204
205
  ? localization.filterMode.replace(
@@ -240,35 +241,30 @@ export const MRT_FilterTextField: FC<Props> = ({
240
241
  value={filterValue ?? ''}
241
242
  variant="standard"
242
243
  InputProps={{
243
- startAdornment:
244
- allowColumnChangeMode &&
245
- !isSelectFilter &&
246
- !inputIndex &&
247
- (allowedColumnFilterOptions === undefined ||
248
- !!allowedColumnFilterOptions?.length) ? (
249
- <InputAdornment position="start">
250
- <Tooltip arrow title={localization.changeFilterMode}>
251
- <span>
252
- <IconButton
253
- aria-label={localization.changeFilterMode}
254
- onClick={handleFilterMenuOpen}
255
- size="small"
256
- sx={{ height: '1.75rem', width: '1.75rem' }}
257
- >
258
- <FilterListIcon />
259
- </IconButton>
260
- </span>
261
- </Tooltip>
262
- {filterChipLabel && (
263
- <Chip
264
- onDelete={handleClearFilterChip}
265
- label={filterChipLabel}
266
- />
267
- )}
268
- </InputAdornment>
269
- ) : (
270
- <FilterListIcon />
271
- ),
244
+ startAdornment: showChangeModeButton ? (
245
+ <InputAdornment position="start">
246
+ <Tooltip arrow title={localization.changeFilterMode}>
247
+ <span>
248
+ <IconButton
249
+ aria-label={localization.changeFilterMode}
250
+ onClick={handleFilterMenuOpen}
251
+ size="small"
252
+ sx={{ height: '1.75rem', width: '1.75rem' }}
253
+ >
254
+ <FilterListIcon />
255
+ </IconButton>
256
+ </span>
257
+ </Tooltip>
258
+ {filterChipLabel && (
259
+ <Chip
260
+ onDelete={handleClearFilterChip}
261
+ label={filterChipLabel}
262
+ />
263
+ )}
264
+ </InputAdornment>
265
+ ) : (
266
+ <FilterListIcon />
267
+ ),
272
268
  endAdornment: !filterChipLabel && (
273
269
  <InputAdornment position="end">
274
270
  <Tooltip
@@ -34,12 +34,14 @@ export const MRT_ColumnActionMenu: FC<Props> = ({
34
34
  toggleAllColumnsVisible,
35
35
  setColumnOrder,
36
36
  options: {
37
+ enableColumnFilterChangeMode,
37
38
  enableColumnFilters,
38
39
  enableColumnResizing,
39
40
  enableGrouping,
40
41
  enableHiding,
41
42
  enablePinning,
42
43
  enableSorting,
44
+ enabledColumnFilterOptions,
43
45
  icons: {
44
46
  ArrowRightIcon,
45
47
  ClearAllIcon,
@@ -144,6 +146,18 @@ export const MRT_ColumnActionMenu: FC<Props> = ({
144
146
  setShowHideColumnsMenuAnchorEl(event.currentTarget);
145
147
  };
146
148
 
149
+ const isSelectFilter = !!columnDef.filterSelectOptions;
150
+
151
+ const allowedColumnFilterOptions =
152
+ columnDef?.enabledColumnFilterOptions ?? enabledColumnFilterOptions;
153
+
154
+ const showFilterModeSubMenu =
155
+ enableColumnFilterChangeMode &&
156
+ columnDef.enableColumnFilterChangeMode !== false &&
157
+ !isSelectFilter &&
158
+ (allowedColumnFilterOptions === undefined ||
159
+ !!allowedColumnFilterOptions?.length);
160
+
147
161
  return (
148
162
  <Menu
149
163
  anchorEl={anchorEl}
@@ -203,7 +217,8 @@ export const MRT_ColumnActionMenu: FC<Props> = ({
203
217
  </MenuItem>,
204
218
  ]}
205
219
  {enableColumnFilters &&
206
- column.getCanFilter() && [
220
+ column.getCanFilter() &&
221
+ [
207
222
  <MenuItem
208
223
  disabled={!column.getFilterValue()}
209
224
  key={0}
@@ -232,7 +247,7 @@ export const MRT_ColumnActionMenu: FC<Props> = ({
232
247
  String(columnDef.header),
233
248
  )}
234
249
  </Box>
235
- {!columnDef.filterSelectOptions && (
250
+ {showFilterModeSubMenu && (
236
251
  <IconButton
237
252
  onClick={handleOpenFilterModeMenu}
238
253
  onMouseEnter={handleOpenFilterModeMenu}
@@ -243,15 +258,17 @@ export const MRT_ColumnActionMenu: FC<Props> = ({
243
258
  </IconButton>
244
259
  )}
245
260
  </MenuItem>,
246
- <MRT_FilterOptionMenu
247
- anchorEl={filterMenuAnchorEl}
248
- header={header}
249
- key={2}
250
- onSelect={handleFilterByColumn}
251
- setAnchorEl={setFilterMenuAnchorEl}
252
- instance={instance}
253
- />,
254
- ]}
261
+ showFilterModeSubMenu && (
262
+ <MRT_FilterOptionMenu
263
+ anchorEl={filterMenuAnchorEl}
264
+ header={header}
265
+ key={2}
266
+ onSelect={handleFilterByColumn}
267
+ setAnchorEl={setFilterMenuAnchorEl}
268
+ instance={instance}
269
+ />
270
+ ),
271
+ ].filter(Boolean)}
255
272
  {enableGrouping &&
256
273
  column.getCanGroup() && [
257
274
  <MenuItem
@@ -56,30 +56,6 @@ export const MRT_TableRoot = <D extends Record<string, any> = {}>(
56
56
  const initState = props.initialState ?? {};
57
57
  initState.columnOrder =
58
58
  initState.columnOrder ?? getDefaultColumnOrderIds(props);
59
-
60
- if (!props.enablePersistentState || !props.tableId) {
61
- return initState;
62
- }
63
- if (typeof window === 'undefined') {
64
- if (process.env.NODE_ENV !== 'production') {
65
- console.error(
66
- 'The MRT Persistent Table State feature is not supported if using SSR, but you can wrap your <MaterialReactTable /> in a MUI <NoSsr> tags to let it work',
67
- );
68
- }
69
- return initState;
70
- }
71
- const storedState =
72
- props.persistentStateMode === 'localStorage'
73
- ? localStorage.getItem(`mrt-${tableId}-table-state`)
74
- : props.persistentStateMode === 'sessionStorage'
75
- ? sessionStorage.getItem(`mrt-${tableId}-table-state`)
76
- : '{}';
77
- if (storedState) {
78
- const parsedState = JSON.parse(storedState);
79
- if (parsedState) {
80
- return { ...initState, ...parsedState };
81
- }
82
- }
83
59
  return initState;
84
60
  }, []);
85
61
 
@@ -284,32 +260,6 @@ export const MRT_TableRoot = <D extends Record<string, any> = {}>(
284
260
  setShowGlobalFilter: props.onShowGlobalFilterChange ?? setShowGlobalFilter,
285
261
  } as MRT_TableInstance;
286
262
 
287
- useEffect(() => {
288
- if (typeof window === 'undefined' || !props.enablePersistentState) {
289
- return;
290
- }
291
- if (!props.tableId && process.env.NODE_ENV !== 'production') {
292
- console.warn(
293
- 'a unique tableId prop is required for persistent table state to work',
294
- );
295
- return;
296
- }
297
- const itemArgs: [string, string] = [
298
- `mrt-${tableId}-table-state`,
299
- JSON.stringify(instance.getState()),
300
- ];
301
- if (props.persistentStateMode === 'localStorage') {
302
- localStorage.setItem(...itemArgs);
303
- } else if (props.persistentStateMode === 'sessionStorage') {
304
- sessionStorage.setItem(...itemArgs);
305
- }
306
- }, [
307
- props.enablePersistentState,
308
- props.tableId,
309
- props.persistentStateMode,
310
- instance,
311
- ]);
312
-
313
263
  useEffect(() => {
314
264
  props?.onColumnOrderChanged?.({
315
265
  columnOrder: instance.getState().columnOrder,
@@ -13,7 +13,11 @@ export const MRT_TablePagination: FC<Props> = ({ instance, position }) => {
13
13
  getState,
14
14
  setPageIndex,
15
15
  setPageSize,
16
- options: { muiTablePaginationProps, enableToolbarInternalActions },
16
+ options: {
17
+ muiTablePaginationProps,
18
+ enableToolbarInternalActions,
19
+ rowCount,
20
+ },
17
21
  } = instance;
18
22
 
19
23
  const {
@@ -30,8 +34,9 @@ export const MRT_TablePagination: FC<Props> = ({ instance, position }) => {
30
34
  setPageSize(+event.target.value);
31
35
  };
32
36
 
33
- const showFirstLastPageButtons =
34
- getPrePaginationRowModel().rows.length / pageSize > 2;
37
+ const totalRowCount = rowCount ?? getPrePaginationRowModel().rows.length;
38
+
39
+ const showFirstLastPageButtons = totalRowCount / pageSize > 2;
35
40
 
36
41
  return (
37
42
  <TablePagination
@@ -40,7 +45,7 @@ export const MRT_TablePagination: FC<Props> = ({ instance, position }) => {
40
45
  MenuProps: { MenuListProps: { disablePadding: true } },
41
46
  }}
42
47
  component="div"
43
- count={getPrePaginationRowModel().rows.length}
48
+ count={totalRowCount}
44
49
  onPageChange={(_: any, newPage: number) => setPageIndex(newPage)}
45
50
  onRowsPerPageChange={handleChangeRowsPerPage}
46
51
  page={pageIndex}