material-react-table 0.16.0 → 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/dist/utils.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { ColumnDef, ColumnOrderState, Table, Updater } from '@tanstack/react-table';
1
+ import { ColumnDef, ColumnOrderState, Table } from '@tanstack/react-table';
2
2
  import { MaterialReactTableProps, MRT_Column, MRT_ColumnDef, MRT_FilterFn } from '.';
3
3
  export declare const getAllLeafColumnDefs: (columns: MRT_ColumnDef[]) => MRT_ColumnDef[];
4
4
  export declare const createGroup: <D extends Record<string, any> = {}>(table: Table<D>, column: MRT_ColumnDef<D>, currentFilterFns: {
@@ -10,7 +10,7 @@ export declare const createDataColumn: <D extends Record<string, any> = {}>(tabl
10
10
  export declare const createDisplayColumn: <D extends Record<string, any> = {}>(table: Table<D>, column: Pick<MRT_ColumnDef<D>, "accessorFn" | "columns" | "filterFn" | "footer" | "sortingFn" | "id" | "accessorKey" | "meta" | "enableHiding" | "enablePinning" | "enableColumnFilter" | "enableGlobalFilter" | "sortDescFirst" | "enableSorting" | "enableMultiSort" | "invertSorting" | "sortUndefined" | "aggregationFn" | "enableGrouping" | "enableResizing" | "size" | "minSize" | "maxSize" | "AggregatedCell" | "Cell" | "Edit" | "Filter" | "Footer" | "Header" | "enableClickToCopy" | "enableColumnActions" | "enableColumnFilterChangeMode" | "enableColumnOrdering" | "enableEditing" | "enabledColumnFilterOptions" | "filterSelectOptions" | "muiTableBodyCellCopyButtonProps" | "muiTableBodyCellEditTextFieldProps" | "muiTableBodyCellProps" | "muiTableFooterCellProps" | "muiTableHeadCellColumnActionsButtonProps" | "muiTableHeadCellFilterTextFieldProps" | "muiTableHeadCellProps" | "onCellEditBlur" | "onCellEditChanged" | "onColumnFilterValueChanged" | "onColumnFilterValueChangedDebounced"> & {
11
11
  header?: string | undefined;
12
12
  }) => ColumnDef<D>;
13
- export declare const reorderColumn: (movingColumn: MRT_Column, receivingColumn: MRT_Column, columnOrder: ColumnOrderState, setColumnOrder: (updater: Updater<ColumnOrderState>) => void) => void;
13
+ export declare const reorderColumn: (movingColumn: MRT_Column, receivingColumn: MRT_Column, columnOrder: ColumnOrderState) => ColumnOrderState;
14
14
  export declare const getLeadingDisplayColumnIds: (props: MaterialReactTableProps<any>) => string[];
15
15
  export declare const getTrailingDisplayColumnIds: (props: MaterialReactTableProps<any>) => (string | false | undefined)[];
16
16
  export declare const getDefaultColumnOrderIds: (props: MaterialReactTableProps<any>) => string[];
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.16.0",
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.",
@@ -30,6 +30,8 @@ import {
30
30
  Cell,
31
31
  Column,
32
32
  ColumnDef,
33
+ ColumnOrderState,
34
+ ColumnPinningState,
33
35
  FilterFn,
34
36
  FilterFnOption,
35
37
  Header,
@@ -399,7 +401,6 @@ export type MaterialReactTableProps<D extends Record<string, any> = {}> =
399
401
  enableGlobalFilterChangeMode?: boolean;
400
402
  enableGlobalFilterRankedResults?: boolean;
401
403
  enablePagination?: boolean;
402
- enablePersistentState?: boolean;
403
404
  enableRowActions?: boolean;
404
405
  enableRowNumbers?: boolean;
405
406
  enableRowVirtualization?: boolean;
@@ -646,6 +647,20 @@ export type MaterialReactTableProps<D extends Record<string, any> = {}> =
646
647
  filterValue: any;
647
648
  instance: MRT_TableInstance<D>;
648
649
  }) => void;
650
+ onColumnOrderChanged?: ({
651
+ columnOrder,
652
+ instance,
653
+ }: {
654
+ columnOrder: ColumnOrderState;
655
+ instance: MRT_TableInstance<D>;
656
+ }) => void;
657
+ onColumnPinningChanged?: ({
658
+ columnPinning,
659
+ instance,
660
+ }: {
661
+ columnPinning: ColumnPinningState;
662
+ instance: MRT_TableInstance<D>;
663
+ }) => void;
649
664
  onColumnVisibilityChanged?: ({
650
665
  column,
651
666
  columnVisibility,
@@ -766,7 +781,6 @@ export type MaterialReactTableProps<D extends Record<string, any> = {}> =
766
781
  instance: MRT_TableInstance<D>;
767
782
  showGlobalFilter: boolean;
768
783
  }) => void;
769
- persistentStateMode?: 'localStorage' | 'sessionStorage';
770
784
  positionActionsColumn?: 'first' | 'last';
771
785
  positionGlobalFilter?: 'left' | 'right';
772
786
  positionPagination?: 'bottom' | 'top' | 'both';
@@ -829,6 +843,7 @@ export type MaterialReactTableProps<D extends Record<string, any> = {}> =
829
843
  IconButtonProps & { instance: MRT_TableInstance<D> }
830
844
  >;
831
845
  }) => ReactNode;
846
+ rowCount?: number;
832
847
  rowNumberMode?: 'original' | 'static';
833
848
  selectAllMode?: 'all' | 'page';
834
849
  tableId?: string;
@@ -869,7 +884,6 @@ export default <D extends Record<string, any> = {}>({
869
884
  enableToolbarTop = true,
870
885
  icons,
871
886
  localization,
872
- persistentStateMode = 'sessionStorage',
873
887
  positionActionsColumn = 'first',
874
888
  positionGlobalFilter = 'right',
875
889
  positionPagination = 'bottom',
@@ -912,7 +926,6 @@ export default <D extends Record<string, any> = {}>({
912
926
  enableToolbarTop={enableToolbarTop}
913
927
  icons={{ ...MRT_Default_Icons, ...icons }}
914
928
  localization={{ ...MRT_DefaultLocalization_EN, ...localization }}
915
- persistentStateMode={persistentStateMode}
916
929
  positionActionsColumn={positionActionsColumn}
917
930
  positionGlobalFilter={positionGlobalFilter}
918
931
  positionPagination={positionPagination}
@@ -53,8 +53,10 @@ export const MRT_TableBodyCell: FC<Props> = ({
53
53
 
54
54
  const [, dropRef] = useDrop({
55
55
  accept: 'column',
56
- drop: (movingColumn: MRT_Column) =>
57
- reorderColumn(movingColumn, column, columnOrder, setColumnOrder),
56
+ drop: (movingColumn: MRT_Column) => {
57
+ const newColumnOrder = reorderColumn(movingColumn, column, columnOrder);
58
+ setColumnOrder(newColumnOrder);
59
+ },
58
60
  });
59
61
 
60
62
  const mTableCellBodyProps =
@@ -10,11 +10,7 @@ interface Props {
10
10
  }
11
11
 
12
12
  export const MRT_DraggableTableHeadCell: FC<Props> = ({ header, instance }) => {
13
- const {
14
- getState,
15
- options: {},
16
- setColumnOrder,
17
- } = instance;
13
+ const { getState, setColumnOrder } = instance;
18
14
 
19
15
  const { columnOrder } = getState();
20
16
 
@@ -22,8 +18,10 @@ export const MRT_DraggableTableHeadCell: FC<Props> = ({ header, instance }) => {
22
18
 
23
19
  const [, dropRef] = useDrop({
24
20
  accept: 'column',
25
- drop: (movingColumn: MRT_Column) =>
26
- reorderColumn(movingColumn, column, columnOrder, setColumnOrder),
21
+ drop: (movingColumn: MRT_Column) => {
22
+ const newColumnOrder = reorderColumn(movingColumn, column, columnOrder);
23
+ setColumnOrder(newColumnOrder);
24
+ },
27
25
  });
28
26
 
29
27
  const [{ isDragging }, dragRef, previewRef] = useDrag({
@@ -36,7 +36,6 @@ export const MRT_TableHeadCellResizeHandle: FC<Props> = ({
36
36
  touchAction: 'none',
37
37
  transition: column.getIsResizing() ? undefined : 'all 0.2s ease-in-out',
38
38
  userSelect: 'none',
39
- zIndex: 2000,
40
39
  '&:active': {
41
40
  backgroundColor: theme.palette.info.main,
42
41
  opacity: 1,
@@ -9,22 +9,9 @@ interface Props {
9
9
  }
10
10
 
11
11
  export const MRT_FilterRangeFields: FC<Props> = ({ header, instance }) => {
12
- const {
13
- options: { localization },
14
- } = instance;
15
-
16
12
  return (
17
- <Box sx={{ display: 'grid', gridTemplateColumns: '6fr auto 5fr' }}>
13
+ <Box sx={{ display: 'grid', gridTemplateColumns: '6fr 6fr', gap: '1rem' }}>
18
14
  <MRT_FilterTextField header={header} inputIndex={0} instance={instance} />
19
- <Box
20
- sx={{
21
- width: '100%',
22
- minWidth: '5ch',
23
- textAlign: 'center',
24
- }}
25
- >
26
- {localization.to}
27
- </Box>
28
15
  <MRT_FilterTextField header={header} inputIndex={1} instance={instance} />
29
16
  </Box>
30
17
  );
@@ -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
@@ -55,11 +55,11 @@ export interface MRT_Localization {
55
55
  sortedByColumnAsc: string;
56
56
  sortedByColumnDesc: string;
57
57
  thenBy: string;
58
- to: string;
59
58
  toggleDensity: string;
60
59
  toggleFullScreen: string;
61
60
  toggleSelectAll: string;
62
61
  toggleSelectRow: string;
62
+ toggleVisibility: string;
63
63
  ungroupByColumn: string;
64
64
  unpin: string;
65
65
  unpinAll: string;
@@ -124,11 +124,11 @@ export const MRT_DefaultLocalization_EN: MRT_Localization = {
124
124
  sortedByColumnAsc: 'Sorted by {column} ascending',
125
125
  sortedByColumnDesc: 'Sorted by {column} descending',
126
126
  thenBy: ', then by ',
127
- to: 'to',
128
127
  toggleDensity: 'Toggle density',
129
128
  toggleFullScreen: 'Toggle full screen',
130
129
  toggleSelectAll: 'Toggle select all',
131
130
  toggleSelectRow: 'Toggle select row',
131
+ toggleVisibility: 'Toggle visibility',
132
132
  ungroupByColumn: 'Ungroup by {column}',
133
133
  unpin: 'Unpin',
134
134
  unpinAll: 'Unpin all',
@@ -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
@@ -1,6 +1,13 @@
1
1
  import React, { FC, Ref } from 'react';
2
2
  import { useDrag, useDrop } from 'react-dnd';
3
- import { Box, FormControlLabel, MenuItem, Switch } from '@mui/material';
3
+ import {
4
+ Box,
5
+ FormControlLabel,
6
+ MenuItem,
7
+ Switch,
8
+ Tooltip,
9
+ Typography,
10
+ } from '@mui/material';
4
11
  import { MRT_ColumnPinningButtons } from '../buttons/MRT_ColumnPinningButtons';
5
12
  import { MRT_GrabHandleButton } from '../buttons/MRT_GrabHandleButton';
6
13
  import { reorderColumn } from '../utils';
@@ -21,18 +28,25 @@ export const MRT_ShowHideColumnsMenuItems: FC<Props> = ({
21
28
  }) => {
22
29
  const {
23
30
  getState,
24
- options: { enableColumnOrdering, onColumnVisibilityChanged },
31
+ options: {
32
+ enableColumnOrdering,
33
+ enableHiding,
34
+ enablePinning,
35
+ localization,
36
+ },
25
37
  setColumnOrder,
26
38
  } = instance;
27
39
 
28
- const { columnOrder, columnVisibility } = getState();
40
+ const { columnOrder } = getState();
29
41
 
30
42
  const { columnDef, columnDefType } = column;
31
43
 
32
44
  const [, dropRef] = useDrop({
33
45
  accept: 'column',
34
- drop: (movingColumn: MRT_Column) =>
35
- reorderColumn(movingColumn, column, columnOrder, setColumnOrder),
46
+ drop: (movingColumn: MRT_Column) => {
47
+ const newColumnOrder = reorderColumn(movingColumn, column, columnOrder);
48
+ setColumnOrder(newColumnOrder);
49
+ },
36
50
  });
37
51
 
38
52
  const [, dragRef, previewRef] = useDrag({
@@ -56,11 +70,6 @@ export const MRT_ShowHideColumnsMenuItems: FC<Props> = ({
56
70
  } else {
57
71
  column.toggleVisibility();
58
72
  }
59
- onColumnVisibilityChanged?.({
60
- column,
61
- columnVisibility,
62
- instance,
63
- });
64
73
  };
65
74
 
66
75
  return (
@@ -85,35 +94,56 @@ export const MRT_ShowHideColumnsMenuItems: FC<Props> = ({
85
94
  >
86
95
  {columnDefType !== 'group' &&
87
96
  enableColumnOrdering &&
88
- columnDef.enableColumnOrdering !== false &&
89
- !allColumns.some((col) => col.columnDefType === 'group') && (
97
+ !allColumns.some((col) => col.columnDefType === 'group') &&
98
+ (columnDef.enableColumnOrdering !== false ? (
90
99
  <MRT_GrabHandleButton
91
100
  ref={dragRef as Ref<HTMLButtonElement>}
92
101
  instance={instance}
93
102
  />
94
- )}
95
- {!isSubMenu && column.getCanPin() && (
96
- <MRT_ColumnPinningButtons column={column} instance={instance} />
97
- )}
98
- <FormControlLabel
99
- componentsProps={{
100
- typography: {
101
- sx: {
102
- mb: 0,
103
- opacity: columnDefType !== 'display' ? 1 : 0.5,
103
+ ) : (
104
+ <Box sx={{ width: '28px' }} />
105
+ ))}
106
+ {enablePinning &&
107
+ !isSubMenu &&
108
+ (column.getCanPin() ? (
109
+ <MRT_ColumnPinningButtons column={column} instance={instance} />
110
+ ) : (
111
+ <Box sx={{ width: '70px' }} />
112
+ ))}
113
+ {enableHiding ? (
114
+ <FormControlLabel
115
+ componentsProps={{
116
+ typography: {
117
+ sx: {
118
+ mb: 0,
119
+ opacity: columnDefType !== 'display' ? 1 : 0.5,
120
+ },
104
121
  },
105
- },
106
- }}
107
- checked={switchChecked}
108
- control={<Switch />}
109
- disabled={
110
- (isSubMenu && switchChecked) ||
111
- !column.getCanHide() ||
112
- column.getIsGrouped()
113
- }
114
- label={columnDef.header}
115
- onChange={() => handleToggleColumnHidden(column)}
116
- />
122
+ }}
123
+ checked={switchChecked}
124
+ control={
125
+ <Tooltip
126
+ arrow
127
+ enterDelay={1000}
128
+ enterNextDelay={1000}
129
+ title={localization.toggleVisibility}
130
+ >
131
+ <Switch />
132
+ </Tooltip>
133
+ }
134
+ disabled={
135
+ (isSubMenu && switchChecked) ||
136
+ !column.getCanHide() ||
137
+ column.getIsGrouped()
138
+ }
139
+ label={columnDef.header}
140
+ onChange={() => handleToggleColumnHidden(column)}
141
+ />
142
+ ) : (
143
+ <Typography sx={{ alignSelf: 'center' }}>
144
+ {columnDef.header}
145
+ </Typography>
146
+ )}
117
147
  </Box>
118
148
  </MenuItem>
119
149
  {column.columns?.map((c: MRT_Column, i) => (
@@ -42,6 +42,9 @@ export const MRT_TablePaper: FC<Props> = ({ instance }) => {
42
42
  sx={{
43
43
  transition: 'all 0.2s ease-in-out',
44
44
  ...tablePaperProps?.sx,
45
+ }}
46
+ style={{
47
+ ...tablePaperProps?.style,
45
48
  height: isFullScreen ? '100vh' : undefined,
46
49
  margin: isFullScreen ? '0' : undefined,
47
50
  maxHeight: isFullScreen ? '100vh' : undefined,
@@ -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
 
@@ -168,7 +144,7 @@ export const MRT_TableRoot = <D extends Record<string, any> = {}>(
168
144
  id: 'mrt-expand',
169
145
  muiTableBodyCellProps: props.muiTableBodyCellProps,
170
146
  muiTableHeadCellProps: props.muiTableHeadCellProps,
171
- size: 50,
147
+ size: 60,
172
148
  }),
173
149
  columnOrder.includes('mrt-select') &&
174
150
  createDisplayColumn(table, {
@@ -183,7 +159,7 @@ export const MRT_TableRoot = <D extends Record<string, any> = {}>(
183
159
  id: 'mrt-select',
184
160
  muiTableBodyCellProps: props.muiTableBodyCellProps,
185
161
  muiTableHeadCellProps: props.muiTableHeadCellProps,
186
- size: 50,
162
+ size: 60,
187
163
  }),
188
164
  columnOrder.includes('mrt-row-numbers') &&
189
165
  createDisplayColumn(table, {
@@ -193,7 +169,7 @@ export const MRT_TableRoot = <D extends Record<string, any> = {}>(
193
169
  id: 'mrt-row-numbers',
194
170
  muiTableBodyCellProps: props.muiTableBodyCellProps,
195
171
  muiTableHeadCellProps: props.muiTableHeadCellProps,
196
- size: 50,
172
+ size: 60,
197
173
  }),
198
174
  ].filter(Boolean) as MRT_ColumnDef<D>[];
199
175
  }, [
@@ -285,30 +261,28 @@ export const MRT_TableRoot = <D extends Record<string, any> = {}>(
285
261
  } as MRT_TableInstance;
286
262
 
287
263
  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
- ]);
264
+ props?.onColumnOrderChanged?.({
265
+ columnOrder: instance.getState().columnOrder,
266
+ //@ts-ignore
267
+ instance,
268
+ });
269
+ }, [instance.getState().columnOrder]);
270
+
271
+ useEffect(() => {
272
+ props?.onColumnPinningChanged?.({
273
+ columnPinning: instance.getState().columnPinning,
274
+ //@ts-ignore
275
+ instance,
276
+ });
277
+ }, [instance.getState().columnPinning]);
278
+
279
+ useEffect(() => {
280
+ props?.onColumnVisibilityChanged?.({
281
+ columnPinning: instance.getState().columnVisibility,
282
+ //@ts-ignore
283
+ instance,
284
+ });
285
+ }, [instance.getState().columnVisibility]);
312
286
 
313
287
  return (
314
288
  <>
@@ -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}