material-react-table 0.26.5 → 0.28.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.26.5",
2
+ "version": "0.28.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.",
@@ -57,12 +57,12 @@
57
57
  }
58
58
  ],
59
59
  "devDependencies": {
60
- "@babel/core": "^7.18.6",
60
+ "@babel/core": "^7.18.9",
61
61
  "@emotion/react": "^11.9.3",
62
62
  "@emotion/styled": "^11.9.3",
63
63
  "@faker-js/faker": "^7.3.0",
64
64
  "@mui/icons-material": "^5.8.4",
65
- "@mui/material": "^5.9.0",
65
+ "@mui/material": "^5.9.1",
66
66
  "@size-limit/preset-small-lib": "^7.0.8",
67
67
  "@storybook/addon-a11y": "^6.5.9",
68
68
  "@storybook/addon-actions": "^6.5.9",
@@ -101,6 +101,6 @@
101
101
  "dependencies": {
102
102
  "@tanstack/match-sorter-utils": "8.1.1",
103
103
  "@tanstack/react-table": "8.2.6",
104
- "react-virtual": "^2.10.4"
104
+ "@tanstack/react-virtual": "^3.0.0-beta.13"
105
105
  }
106
106
  }
@@ -40,7 +40,7 @@ import type {
40
40
  TableOptions,
41
41
  TableState,
42
42
  } from '@tanstack/react-table';
43
- import type { Options as VirtualizerOptions } from 'react-virtual';
43
+ import type { VirtualizerOptions } from '@tanstack/react-virtual';
44
44
  import { MRT_Localization, MRT_DefaultLocalization_EN } from './localization';
45
45
  import { MRT_Default_Icons, MRT_Icons } from './icons';
46
46
  import { MRT_TableRoot } from './table/MRT_TableRoot';
@@ -134,7 +134,7 @@ export type MRT_TableState<TData extends Record<string, any> = {}> =
134
134
  };
135
135
 
136
136
  export type MRT_ColumnDef<TData extends Record<string, any> = {}> = Omit<
137
- ColumnDef<TData>,
137
+ ColumnDef<TData, unknown>,
138
138
  | 'accessorFn'
139
139
  | 'accessorKey'
140
140
  | 'aggregatedCell'
@@ -215,6 +215,7 @@ export type MRT_ColumnDef<TData extends Record<string, any> = {}> = Omit<
215
215
  * @example columnDefType: 'display'
216
216
  */
217
217
  columnDefType?: 'data' | 'display' | 'group';
218
+ columnFilterModeOptions?: MRT_FilterOption[] | null;
218
219
  columns?: MRT_ColumnDef<TData>[];
219
220
  enableClickToCopy?: boolean;
220
221
  enableColumnActions?: boolean;
@@ -222,7 +223,6 @@ export type MRT_ColumnDef<TData extends Record<string, any> = {}> = Omit<
222
223
  enableColumnFilterChangeMode?: boolean;
223
224
  enableColumnOrdering?: boolean;
224
225
  enableEditing?: boolean;
225
- enabledColumnFilterOptions?: MRT_FilterOption[] | null;
226
226
  filterFn?: MRT_FilterFn<TData>;
227
227
  filterSelectOptions?: (string | { text: string; value: string })[];
228
228
  /**
@@ -422,6 +422,7 @@ export type MaterialReactTableProps<TData extends Record<string, any> = {}> =
422
422
  displayColumnDefOptions?: Partial<{
423
423
  [key in MRT_DisplayColumnIds]: Partial<MRT_ColumnDef>;
424
424
  }>;
425
+ columnFilterModeOptions?: (MRT_FilterOption | string)[] | null;
425
426
  columns: MRT_ColumnDef<TData>[];
426
427
  data: TData[];
427
428
  editingMode?: 'table' | 'row' | 'cell';
@@ -449,7 +450,6 @@ export type MaterialReactTableProps<TData extends Record<string, any> = {}> =
449
450
  enableToolbarBottom?: boolean;
450
451
  enableToolbarInternalActions?: boolean;
451
452
  enableToolbarTop?: boolean;
452
- enabledColumnFilterOptions?: (MRT_FilterOption | string)[] | null;
453
453
  enabledGlobalFilterOptions?: (MRT_FilterOption | string)[] | null;
454
454
  expandRowsFn?: (dataRow: TData) => TData[];
455
455
  icons?: Partial<MRT_Icons>;
@@ -779,7 +779,9 @@ export type MaterialReactTableProps<TData extends Record<string, any> = {}> =
779
779
  selectAllMode?: 'all' | 'page';
780
780
  state?: Partial<MRT_TableState<TData>>;
781
781
  tableId?: string;
782
- virtualizerProps?: Partial<VirtualizerOptions<HTMLDivElement>>;
782
+ virtualizerProps?: Partial<
783
+ VirtualizerOptions<HTMLDivElement, HTMLTableRowElement>
784
+ >;
783
785
  };
784
786
 
785
787
  export default <TData extends Record<string, any> = {}>({
@@ -788,7 +790,7 @@ export default <TData extends Record<string, any> = {}>({
788
790
  defaultColumn = { minSize: 40, maxSize: 1000, size: 180 },
789
791
  editingMode = 'row',
790
792
  enableColumnActions = true,
791
- enableColumnFilterChangeMode = true,
793
+ enableColumnFilterChangeMode = false,
792
794
  enableColumnFilters = true,
793
795
  enableColumnOrdering = false,
794
796
  enableColumnResizing = false,
@@ -797,7 +799,7 @@ export default <TData extends Record<string, any> = {}>({
797
799
  enableFilters = true,
798
800
  enableFullScreenToggle = true,
799
801
  enableGlobalFilter = true,
800
- enableGlobalFilterChangeMode = true,
802
+ enableGlobalFilterChangeMode = false,
801
803
  enableGlobalFilterRankedResults = true,
802
804
  enableGrouping = false,
803
805
  enableHiding = true,
@@ -1,5 +1,5 @@
1
1
  import React, { FC, RefObject, useMemo } from 'react';
2
- import { useVirtual } from 'react-virtual';
2
+ import { useVirtualizer, Virtualizer } from '@tanstack/react-virtual';
3
3
  import { TableBody } from '@mui/material';
4
4
  import { MRT_TableBodyRow } from './MRT_TableBodyRow';
5
5
  import { rankGlobalFuzzy } from '../sortingFns';
@@ -60,28 +60,27 @@ export const MRT_TableBody: FC<Props> = ({ table, tableContainerRef }) => {
60
60
  globalFilter,
61
61
  ]);
62
62
 
63
- const rowVirtualizer = enableRowVirtualization
64
- ? useVirtual({
65
- // estimateSize: () => (density === 'compact' ? 25 : 50),
63
+ const rowVirtualizer: Virtualizer = enableRowVirtualization
64
+ ? useVirtualizer({
65
+ estimateSize: () => (density === 'compact' ? 25 : 50),
66
66
  overscan: density === 'compact' ? 30 : 10,
67
- parentRef: tableContainerRef,
68
- size: rows.length,
67
+ getScrollElement: () => tableContainerRef.current as HTMLDivElement,
68
+ count: rows.length,
69
69
  ...virtualizerProps,
70
70
  })
71
71
  : ({} as any);
72
72
 
73
73
  const virtualRows = enableRowVirtualization
74
- ? rowVirtualizer.virtualItems
74
+ ? rowVirtualizer.getVirtualItems()
75
75
  : [];
76
76
 
77
77
  let paddingTop = 0;
78
78
  let paddingBottom = 0;
79
79
  if (enableRowVirtualization) {
80
- paddingTop = virtualRows.length > 0 ? virtualRows[0].start : 0;
81
- paddingBottom =
82
- virtualRows.length > 0
83
- ? rowVirtualizer.totalSize - virtualRows[virtualRows.length - 1].end
84
- : 0;
80
+ paddingTop = !!virtualRows.length ? virtualRows[0].start : 0;
81
+ paddingBottom = !!virtualRows.length
82
+ ? rowVirtualizer.getTotalSize() - virtualRows[virtualRows.length - 1].end
83
+ : 0;
85
84
  }
86
85
 
87
86
  return (
@@ -91,6 +90,7 @@ export const MRT_TableBody: FC<Props> = ({ table, tableContainerRef }) => {
91
90
  <td style={{ height: `${paddingTop}px` }} />
92
91
  </tr>
93
92
  )}
93
+ {/* @ts-ignore */}
94
94
  {(enableRowVirtualization ? virtualRows : rows).map(
95
95
  (rowOrVirtualRow: any, rowIndex: number) => {
96
96
  const row = enableRowVirtualization
@@ -35,6 +35,7 @@ export const MRT_TableBodyCell: FC<Props> = ({
35
35
  enableClickToCopy,
36
36
  enableColumnOrdering,
37
37
  enableEditing,
38
+ enablePagination,
38
39
  enableRowNumbers,
39
40
  muiTableBodyCellProps,
40
41
  muiTableBodyCellSkeletonProps,
@@ -147,7 +148,12 @@ export const MRT_TableBodyCell: FC<Props> = ({
147
148
  borderLeft: draggingBorder,
148
149
  borderRight: draggingBorder,
149
150
  borderBottom:
150
- row.index === table.getRowModel().rows.length - 1
151
+ row.index ===
152
+ (enablePagination
153
+ ? table.getRowModel()
154
+ : table.getPrePaginationRowModel()
155
+ ).rows.length -
156
+ 1
151
157
  ? draggingBorder
152
158
  : undefined,
153
159
  }
@@ -43,6 +43,7 @@ export const MRT_ExpandAllButton: FC<Props> = ({ table }) => {
43
43
  sx={{
44
44
  height: density === 'compact' ? '1.75rem' : '2.25rem',
45
45
  width: density === 'compact' ? '1.75rem' : '2.25rem',
46
+ mt: density !== 'compact' ? '-0.25rem' : undefined,
46
47
  ...iconButtonProps?.sx,
47
48
  }}
48
49
  >
@@ -128,12 +128,10 @@ export const MRT_TableHeadCell: FC<Props> = ({ header, table }) => {
128
128
  : 1,
129
129
  p:
130
130
  density === 'compact'
131
- ? columnDefType === 'display'
132
- ? '0 0.5rem'
133
- : '0.5rem'
131
+ ? '0.5rem'
134
132
  : density === 'comfortable'
135
133
  ? columnDefType === 'display'
136
- ? '0.5rem 0.75rem'
134
+ ? '0.75rem'
137
135
  : '1rem'
138
136
  : columnDefType === 'display'
139
137
  ? '1rem 1.25rem'
@@ -33,7 +33,7 @@ export const MRT_FilterTextField: FC<Props> = ({
33
33
  getState,
34
34
  options: {
35
35
  enableColumnFilterChangeMode,
36
- enabledColumnFilterOptions,
36
+ columnFilterModeOptions,
37
37
  icons: { FilterListIcon, CloseIcon },
38
38
  localization,
39
39
  muiTableHeadCellFilterTextFieldProps,
@@ -152,7 +152,7 @@ export const MRT_FilterTextField: FC<Props> = ({
152
152
  : '';
153
153
 
154
154
  const allowedColumnFilterOptions =
155
- columnDef?.enabledColumnFilterOptions ?? enabledColumnFilterOptions;
155
+ columnDef?.columnFilterModeOptions ?? columnFilterModeOptions;
156
156
 
157
157
  const showChangeModeButton =
158
158
  enableColumnFilterChangeMode &&
@@ -260,7 +260,6 @@ export const MRT_FilterTextField: FC<Props> = ({
260
260
  }}
261
261
  {...textFieldProps}
262
262
  sx={(theme) => ({
263
- m: '-0.25rem',
264
263
  p: 0,
265
264
  minWidth: !filterChipLabel ? '8rem' : 'auto',
266
265
  width: 'calc(100% + 0.5rem)',
@@ -59,9 +59,9 @@ export const MRT_SelectCheckbox: FC<Props> = ({ row, selectAll, table }) => {
59
59
  size={density === 'compact' ? 'small' : 'medium'}
60
60
  {...checkboxProps}
61
61
  sx={(theme) => ({
62
- height: density === 'compact' ? '1.5rem' : '2rem',
63
- width: density === 'compact' ? '1.5rem' : '2rem',
64
- m: '-1re.m',
62
+ height: density === 'compact' ? '1.75rem' : '2.5rem',
63
+ width: density === 'compact' ? '1.75rem' : '2.5rem',
64
+ m: density !== 'compact' ? '-0.4rem' : undefined,
65
65
  ...(checkboxProps?.sx instanceof Function
66
66
  ? checkboxProps.sx(theme)
67
67
  : (checkboxProps?.sx as any)),
@@ -41,7 +41,7 @@ export const MRT_ColumnActionMenu: FC<Props> = ({
41
41
  enableHiding,
42
42
  enablePinning,
43
43
  enableSorting,
44
- enabledColumnFilterOptions,
44
+ columnFilterModeOptions,
45
45
  icons: {
46
46
  ArrowRightIcon,
47
47
  ClearAllIcon,
@@ -145,7 +145,7 @@ export const MRT_ColumnActionMenu: FC<Props> = ({
145
145
  const isSelectFilter = !!columnDef.filterSelectOptions;
146
146
 
147
147
  const allowedColumnFilterOptions =
148
- columnDef?.enabledColumnFilterOptions ?? enabledColumnFilterOptions;
148
+ columnDef?.columnFilterModeOptions ?? columnFilterModeOptions;
149
149
 
150
150
  const showFilterModeSubMenu =
151
151
  enableColumnFilterChangeMode &&
@@ -21,7 +21,7 @@ export const MRT_FilterOptionMenu: FC<Props> = ({
21
21
  getState,
22
22
  options: {
23
23
  enabledGlobalFilterOptions,
24
- enabledColumnFilterOptions,
24
+ columnFilterModeOptions,
25
25
  localization,
26
26
  },
27
27
  setCurrentFilterFns,
@@ -32,7 +32,7 @@ export const MRT_FilterOptionMenu: FC<Props> = ({
32
32
  const { columnDef } = column ?? {};
33
33
 
34
34
  const allowedColumnFilterOptions =
35
- columnDef?.enabledColumnFilterOptions ?? enabledColumnFilterOptions;
35
+ columnDef?.columnFilterModeOptions ?? columnFilterModeOptions;
36
36
 
37
37
  const filterOptions = useMemo(
38
38
  () =>
@@ -31,10 +31,7 @@ export const MRT_ToolbarBottom: FC<Props> = ({ table }) => {
31
31
  ? muiTableToolbarBottomProps({ table })
32
32
  : muiTableToolbarBottomProps;
33
33
 
34
- const stackAlertBanner =
35
- isMobile ||
36
- (positionToolbarAlertBanner === 'bottom' &&
37
- !!renderToolbarBottomCustomActions);
34
+ const stackAlertBanner = isMobile || !!renderToolbarBottomCustomActions;
38
35
 
39
36
  return (
40
37
  <Toolbar
@@ -49,9 +49,7 @@ export const MRT_ToolbarTop: FC<Props> = ({ table }) => {
49
49
  : muiTableToolbarTopProps;
50
50
 
51
51
  const stackAlertBanner =
52
- isMobile ||
53
- (positionToolbarAlertBanner === 'top' &&
54
- (!!renderToolbarTopCustomActions || showGlobalFilter));
52
+ isMobile || !!renderToolbarTopCustomActions || showGlobalFilter;
55
53
 
56
54
  return (
57
55
  <Toolbar