material-react-table 0.5.8 → 0.5.9

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.
Files changed (57) hide show
  1. package/dist/MaterialReactTable.d.ts +1 -10
  2. package/dist/body/MRT_TableBodyCell.d.ts +1 -1
  3. package/dist/body/MRT_TableBodyRow.d.ts +1 -1
  4. package/dist/body/MRT_TableDetailPanel.d.ts +1 -1
  5. package/dist/buttons/MRT_EditActionButtons.d.ts +1 -1
  6. package/dist/buttons/MRT_ExpandButton.d.ts +1 -1
  7. package/dist/buttons/MRT_ToggleColumnActionMenuButton.d.ts +1 -1
  8. package/dist/buttons/MRT_ToggleRowActionMenuButton.d.ts +1 -1
  9. package/dist/enums.d.ts +12 -0
  10. package/dist/filtersFNs.d.ts +16 -0
  11. package/dist/footer/MRT_TableFooterCell.d.ts +1 -1
  12. package/dist/footer/MRT_TableFooterRow.d.ts +1 -1
  13. package/dist/head/MRT_TableHeadCell.d.ts +1 -1
  14. package/dist/head/MRT_TableHeadRow.d.ts +1 -1
  15. package/dist/inputs/MRT_EditCellTextField.d.ts +1 -1
  16. package/dist/inputs/MRT_FilterTextField.d.ts +1 -1
  17. package/dist/inputs/MRT_SelectCheckbox.d.ts +1 -1
  18. package/dist/localization.d.ts +3 -1
  19. package/dist/material-react-table.cjs.development.js +111 -37
  20. package/dist/material-react-table.cjs.development.js.map +1 -1
  21. package/dist/material-react-table.cjs.production.min.js +1 -1
  22. package/dist/material-react-table.cjs.production.min.js.map +1 -1
  23. package/dist/material-react-table.esm.js +100 -28
  24. package/dist/material-react-table.esm.js.map +1 -1
  25. package/dist/menus/MRT_ColumnActionMenu.d.ts +1 -1
  26. package/dist/menus/MRT_FilterTypeMenu.d.ts +1 -1
  27. package/dist/menus/MRT_RowActionMenu.d.ts +1 -1
  28. package/dist/menus/MRT_ShowHideColumnsMenu.d.ts +1 -1
  29. package/dist/useMRT.d.ts +1 -1
  30. package/package.json +1 -1
  31. package/src/MaterialReactTable.tsx +1 -11
  32. package/src/body/MRT_TableBody.tsx +1 -1
  33. package/src/body/MRT_TableBodyCell.tsx +1 -1
  34. package/src/body/MRT_TableBodyRow.tsx +1 -1
  35. package/src/body/MRT_TableDetailPanel.tsx +1 -1
  36. package/src/buttons/MRT_EditActionButtons.tsx +1 -1
  37. package/src/buttons/MRT_ExpandButton.tsx +1 -1
  38. package/src/buttons/MRT_ShowHideColumnsButton.tsx +1 -1
  39. package/src/buttons/MRT_ToggleColumnActionMenuButton.tsx +2 -1
  40. package/src/buttons/MRT_ToggleRowActionMenuButton.tsx +1 -1
  41. package/src/enums.ts +12 -0
  42. package/src/filtersFNs.ts +30 -0
  43. package/src/footer/MRT_TableFooter.tsx +1 -1
  44. package/src/footer/MRT_TableFooterCell.tsx +1 -1
  45. package/src/footer/MRT_TableFooterRow.tsx +1 -1
  46. package/src/head/MRT_TableHead.tsx +1 -1
  47. package/src/head/MRT_TableHeadCell.tsx +1 -1
  48. package/src/head/MRT_TableHeadRow.tsx +1 -1
  49. package/src/inputs/MRT_EditCellTextField.tsx +1 -1
  50. package/src/inputs/MRT_FilterTextField.tsx +2 -2
  51. package/src/inputs/MRT_SelectCheckbox.tsx +1 -1
  52. package/src/localization.ts +6 -2
  53. package/src/menus/MRT_ColumnActionMenu.tsx +1 -1
  54. package/src/menus/MRT_FilterTypeMenu.tsx +37 -3
  55. package/src/menus/MRT_RowActionMenu.tsx +1 -1
  56. package/src/menus/MRT_ShowHideColumnsMenu.tsx +1 -1
  57. package/src/useMRT.tsx +25 -8
@@ -1,5 +1,5 @@
1
1
  import { FC } from 'react';
2
- import { MRT_HeaderGroup } from '..';
2
+ import type { MRT_HeaderGroup } from '..';
3
3
  export declare const commonMenuItemStyles: {
4
4
  py: string;
5
5
  my: number;
@@ -1,5 +1,5 @@
1
1
  import { FC } from 'react';
2
- import { MRT_HeaderGroup } from '..';
2
+ import type { MRT_HeaderGroup } from '..';
3
3
  interface Props {
4
4
  anchorEl: HTMLElement | null;
5
5
  column: MRT_HeaderGroup;
@@ -1,5 +1,5 @@
1
1
  import { FC } from 'react';
2
- import { MRT_Row } from '..';
2
+ import type { MRT_Row } from '..';
3
3
  interface Props {
4
4
  anchorEl: HTMLElement | null;
5
5
  row: MRT_Row;
@@ -1,5 +1,5 @@
1
1
  import { FC } from 'react';
2
- import { MRT_ColumnInstance } from '..';
2
+ import type { MRT_ColumnInstance } from '..';
3
3
  interface Props {
4
4
  column: MRT_ColumnInstance;
5
5
  }
package/dist/useMRT.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import React, { PropsWithChildren, Dispatch, SetStateAction } from 'react';
2
- import { MRT_FilterType, MRT_Row, MRT_TableInstance } from '.';
2
+ import type { MRT_FilterType, MRT_Row, MRT_TableInstance } from '.';
3
3
  import { MRT_Icons } from './icons';
4
4
  import { MRT_Localization } from './localization';
5
5
  import { MaterialReactTableProps } from './MaterialReactTable';
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.5.8",
2
+ "version": "0.5.9",
3
3
  "license": "MIT",
4
4
  "name": "material-react-table",
5
5
  "description": "A fully featured Material-UI implementation of react-table, inspired by material-table and the mui DataGrid, written from the ground up in TypeScript.",
@@ -77,6 +77,7 @@ import { MaterialReactTableProvider } from './useMRT';
77
77
  import { MRT_TableContainer } from './table/MRT_TableContainer';
78
78
  import { MRT_Localization, MRT_DefaultLocalization_EN } from './localization';
79
79
  import { MRT_Default_Icons, MRT_Icons } from './icons';
80
+ import { MRT_FILTER_TYPE } from './enums';
80
81
 
81
82
  export type MRT_TableOptions<D extends {} = {}> = TableOptions<D> &
82
83
  UseExpandedOptions<D> &
@@ -186,17 +187,6 @@ export type MRT_Cell<D extends {} = {}, _V = any> = Cell<D> &
186
187
  UseGroupByCellProps<D> &
187
188
  UseRowStateCellProps<D> & {};
188
189
 
189
- export enum MRT_FILTER_TYPE {
190
- CONTAINS = 'contains',
191
- EMPTY = 'empty',
192
- ENDS_WITH = 'endsWith',
193
- EQUALS = 'equals',
194
- FUZZY = 'fuzzy',
195
- NOT_EMPTY = 'notEmpty',
196
- NOT_EQUALS = 'notEquals',
197
- STARTS_WITH = 'startsWith',
198
- }
199
-
200
190
  export type MRT_FilterType = MRT_FILTER_TYPE | Function;
201
191
 
202
192
  export type MRT_TableState<D extends {} = {}> = TableState<D> &
@@ -2,7 +2,7 @@ import React, { FC } from 'react';
2
2
  import { TableBody } from '@mui/material';
3
3
  import { MRT_TableBodyRow } from './MRT_TableBodyRow';
4
4
  import { useMRT } from '../useMRT';
5
- import { MRT_Row } from '..';
5
+ import type { MRT_Row } from '..';
6
6
 
7
7
  interface Props {}
8
8
 
@@ -2,7 +2,7 @@ import React, { FC, MouseEvent } from 'react';
2
2
  import { Skeleton, TableCell, TableCellProps } from '@mui/material';
3
3
  import { useMRT } from '../useMRT';
4
4
  import { MRT_EditCellTextField } from '../inputs/MRT_EditCellTextField';
5
- import { MRT_Cell } from '..';
5
+ import type { MRT_Cell } from '..';
6
6
 
7
7
  export const commonTableBodyCellStyles = (densePadding: boolean) => ({
8
8
  p: densePadding ? '0.5rem' : '1rem',
@@ -9,7 +9,7 @@ import { MRT_TableDetailPanel } from './MRT_TableDetailPanel';
9
9
  import { MRT_ExpandButton } from '../buttons/MRT_ExpandButton';
10
10
  import { MRT_SelectCheckbox } from '../inputs/MRT_SelectCheckbox';
11
11
  import { MRT_ToggleRowActionMenuButton } from '../buttons/MRT_ToggleRowActionMenuButton';
12
- import { MRT_Cell, MRT_Row } from '..';
12
+ import type { MRT_Cell, MRT_Row } from '..';
13
13
 
14
14
  interface Props {
15
15
  row: MRT_Row;
@@ -1,7 +1,7 @@
1
1
  import React, { FC, MouseEvent } from 'react';
2
2
  import { Collapse, TableCell, TableRow } from '@mui/material';
3
3
  import { useMRT } from '../useMRT';
4
- import { MRT_Row } from '..';
4
+ import type { MRT_Row } from '..';
5
5
 
6
6
  interface Props {
7
7
  row: MRT_Row;
@@ -1,7 +1,7 @@
1
1
  import React, { FC } from 'react';
2
2
  import { Box, IconButton, Tooltip } from '@mui/material';
3
3
  import { useMRT } from '../useMRT';
4
- import { MRT_Row } from '..';
4
+ import type { MRT_Row } from '..';
5
5
 
6
6
  interface Props {
7
7
  row: MRT_Row;
@@ -1,7 +1,7 @@
1
1
  import React, { FC } from 'react';
2
2
  import { IconButton, TableCell } from '@mui/material';
3
3
  import { useMRT } from '../useMRT';
4
- import { MRT_Row } from '..';
4
+ import type { MRT_Row } from '..';
5
5
  import { commonTableBodyButtonCellStyles } from '../body/MRT_TableBodyCell';
6
6
 
7
7
  interface Props {
@@ -10,7 +10,7 @@ import {
10
10
  } from '@mui/material';
11
11
  import { useMRT } from '../useMRT';
12
12
  import { MRT_ShowHideColumnsMenu } from '../menus/MRT_ShowHideColumnsMenu';
13
- import { MRT_ColumnInstance } from '..';
13
+ import type { MRT_ColumnInstance } from '..';
14
14
 
15
15
  interface Props extends IconButtonProps {}
16
16
 
@@ -2,7 +2,7 @@ import React, { FC, MouseEvent, useState } from 'react';
2
2
  import { IconButton, Tooltip } from '@mui/material';
3
3
  import { useMRT } from '../useMRT';
4
4
  import { MRT_ColumnActionMenu } from '../menus/MRT_ColumnActionMenu';
5
- import { MRT_HeaderGroup } from '..';
5
+ import type { MRT_HeaderGroup } from '..';
6
6
 
7
7
  interface Props {
8
8
  column: MRT_HeaderGroup;
@@ -28,6 +28,7 @@ export const MRT_ToggleColumnActionMenuButton: FC<Props> = ({ column }) => {
28
28
  arrow
29
29
  enterDelay={1000}
30
30
  enterNextDelay={1000}
31
+ placement="top"
31
32
  title={localization.columnActionMenuButtonTitle}
32
33
  >
33
34
  <IconButton
@@ -3,7 +3,7 @@ import { IconButton, TableCell, Tooltip } from '@mui/material';
3
3
  import { useMRT } from '../useMRT';
4
4
  import { MRT_RowActionMenu } from '../menus/MRT_RowActionMenu';
5
5
  import { MRT_EditActionButtons } from './MRT_EditActionButtons';
6
- import { MRT_Row } from '..';
6
+ import type { MRT_Row } from '..';
7
7
  import { commonTableBodyButtonCellStyles } from '../body/MRT_TableBodyCell';
8
8
 
9
9
  const commonIconButtonStyles = {
package/src/enums.ts ADDED
@@ -0,0 +1,12 @@
1
+ export enum MRT_FILTER_TYPE {
2
+ CONTAINS = 'contains',
3
+ EMPTY = 'empty',
4
+ ENDS_WITH = 'endsWith',
5
+ EQUALS = 'equals',
6
+ FUZZY = 'fuzzy',
7
+ GREATER_THAN = 'greaterThan',
8
+ LESS_THAN = 'lessThan',
9
+ NOT_EMPTY = 'notEmpty',
10
+ NOT_EQUALS = 'notEquals',
11
+ STARTS_WITH = 'startsWith',
12
+ }
package/src/filtersFNs.ts CHANGED
@@ -96,6 +96,34 @@ export const notEqualsFilterFN = (
96
96
 
97
97
  notEqualsFilterFN.autoRemove = (val: any) => !val;
98
98
 
99
+ export const greaterThanFilterFN = (
100
+ rows: MRT_Row[],
101
+ id: string,
102
+ filterValue: string | number,
103
+ ) =>
104
+ rows.filter((row) =>
105
+ !isNaN(+filterValue) && !isNaN(+row.values[id])
106
+ ? +row.values[id] > +filterValue
107
+ : row.values[id].toString().toLowerCase().trim() >
108
+ filterValue.toString().toLowerCase().trim(),
109
+ );
110
+
111
+ greaterThanFilterFN.autoRemove = (val: any) => !val;
112
+
113
+ export const lessThanFilterFN = (
114
+ rows: MRT_Row[],
115
+ id: string,
116
+ filterValue: string | number,
117
+ ) =>
118
+ rows.filter((row) =>
119
+ !isNaN(+filterValue) && !isNaN(+row.values[id])
120
+ ? +row.values[id] < +filterValue
121
+ : row.values[id].toString().toLowerCase().trim() <
122
+ filterValue.toString().toLowerCase().trim(),
123
+ );
124
+
125
+ lessThanFilterFN.autoRemove = (val: any) => !val;
126
+
99
127
  export const emptyFilterFN = (
100
128
  rows: MRT_Row[],
101
129
  id: string,
@@ -116,6 +144,8 @@ export const defaultFilterFNs = {
116
144
  contains: containsFilterFN,
117
145
  empty: emptyFilterFN,
118
146
  endsWith: endsWithFilterFN,
147
+ greaterThan: greaterThanFilterFN,
148
+ lessThan: lessThanFilterFN,
119
149
  equals: equalsFilterFN,
120
150
  fuzzy: fuzzyFilterFN,
121
151
  notEmpty: notEmptyFilterFN,
@@ -2,7 +2,7 @@ import React, { FC } from 'react';
2
2
  import { TableFooter } from '@mui/material';
3
3
  import { MRT_TableFooterRow } from './MRT_TableFooterRow';
4
4
  import { useMRT } from '../useMRT';
5
- import { MRT_HeaderGroup } from '..';
5
+ import type { MRT_HeaderGroup } from '..';
6
6
 
7
7
  interface Props {}
8
8
 
@@ -1,7 +1,7 @@
1
1
  import React, { FC } from 'react';
2
2
  import { TableCell } from '@mui/material';
3
3
  import { useMRT } from '../useMRT';
4
- import { MRT_HeaderGroup } from '..';
4
+ import type { MRT_HeaderGroup } from '..';
5
5
 
6
6
  interface Props {
7
7
  column: MRT_HeaderGroup;
@@ -3,7 +3,7 @@ import { TableRow } from '@mui/material';
3
3
  import { MRT_TableFooterCell } from './MRT_TableFooterCell';
4
4
  import { MRT_TableSpacerCell } from '../table/MRT_TableSpacerCell';
5
5
  import { useMRT } from '../useMRT';
6
- import { MRT_HeaderGroup } from '..';
6
+ import type { MRT_HeaderGroup } from '..';
7
7
 
8
8
  interface Props {
9
9
  footerGroup: MRT_HeaderGroup;
@@ -2,7 +2,7 @@ import React, { FC } from 'react';
2
2
  import { TableHead } from '@mui/material';
3
3
  import { MRT_TableHeadRow } from './MRT_TableHeadRow';
4
4
  import { useMRT } from '../useMRT';
5
- import { MRT_HeaderGroup } from '..';
5
+ import type { MRT_HeaderGroup } from '..';
6
6
 
7
7
  interface Props {}
8
8
 
@@ -11,7 +11,7 @@ import {
11
11
  import { useMRT } from '../useMRT';
12
12
  import { MRT_FilterTextField } from '../inputs/MRT_FilterTextField';
13
13
  import { MRT_ToggleColumnActionMenuButton } from '../buttons/MRT_ToggleColumnActionMenuButton';
14
- import { MRT_HeaderGroup } from '..';
14
+ import type { MRT_HeaderGroup } from '..';
15
15
 
16
16
  export const commonTableHeadCellStyles = (
17
17
  densePadding: boolean,
@@ -9,7 +9,7 @@ import { MRT_SelectCheckbox } from '../inputs/MRT_SelectCheckbox';
9
9
  import { MRT_ExpandAllButton } from '../buttons/MRT_ExpandAllButton';
10
10
  import { MRT_TableSpacerCell } from '../table/MRT_TableSpacerCell';
11
11
  import { MRT_TableHeadCellActions } from './MRT_TableHeadCellActions';
12
- import { MRT_HeaderGroup } from '..';
12
+ import type { MRT_HeaderGroup } from '..';
13
13
 
14
14
  interface Props {
15
15
  headerGroup: MRT_HeaderGroup;
@@ -1,7 +1,7 @@
1
1
  import React, { ChangeEvent, FC } from 'react';
2
2
  import { TextField } from '@mui/material';
3
3
  import { useMRT } from '../useMRT';
4
- import { MRT_Cell } from '..';
4
+ import type { MRT_Cell } from '..';
5
5
 
6
6
  interface Props {
7
7
  cell: MRT_Cell;
@@ -10,8 +10,9 @@ import {
10
10
  } from '@mui/material';
11
11
  import { useAsyncDebounce } from 'react-table';
12
12
  import { useMRT } from '../useMRT';
13
- import { MRT_FILTER_TYPE, MRT_HeaderGroup } from '..';
13
+ import type { MRT_HeaderGroup } from '..';
14
14
  import { MRT_FilterTypeMenu } from '../menus/MRT_FilterTypeMenu';
15
+ import { MRT_FILTER_TYPE } from '../enums';
15
16
 
16
17
  interface Props {
17
18
  column: MRT_HeaderGroup;
@@ -128,7 +129,6 @@ export const MRT_FilterTextField: FC<Props> = ({ column }) => {
128
129
  <Tooltip arrow title={localization.changeFilterMode}>
129
130
  <span>
130
131
  <IconButton
131
- disabled={isCustomFilterType}
132
132
  onClick={handleFilterMenuOpen}
133
133
  size="small"
134
134
  sx={{ height: '1.75rem', width: '1.75rem' }}
@@ -1,7 +1,7 @@
1
1
  import React, { ChangeEvent, FC } from 'react';
2
2
  import { Checkbox, TableCell, Tooltip } from '@mui/material';
3
3
  import { useMRT } from '../useMRT';
4
- import { MRT_Row } from '..';
4
+ import type { MRT_Row } from '..';
5
5
  import { commonTableBodyButtonCellStyles } from '../body/MRT_TableBodyCell';
6
6
 
7
7
  interface Props {
@@ -1,5 +1,6 @@
1
1
  export interface MRT_Localization {
2
2
  actionsHeadColumnTitle: string;
3
+ changeFilterMode: string;
3
4
  columnActionMenuButtonTitle: string;
4
5
  columnActionMenuItemClearSort: string;
5
6
  columnActionMenuItemGroupBy: string;
@@ -17,6 +18,8 @@ export interface MRT_Localization {
17
18
  filterMenuItemEndsWith: string;
18
19
  filterMenuItemEquals: string;
19
20
  filterMenuItemFuzzy: string;
21
+ filterMenuItemGreaterThan: string;
22
+ filterMenuItemLessThan: string;
20
23
  filterMenuItemNotEmpty: string;
21
24
  filterMenuItemNotEquals: string;
22
25
  filterMenuItemStartsWith: string;
@@ -26,7 +29,6 @@ export interface MRT_Localization {
26
29
  filterTextFieldChipLabelNotEmpty: string;
27
30
  filterTextFieldClearButtonTitle: string;
28
31
  filterTextFieldPlaceholder: string;
29
- changeFilterMode: string;
30
32
  rowActionButtonCancel: string;
31
33
  rowActionButtonSave: string;
32
34
  rowActionMenuButtonTitle: string;
@@ -48,6 +50,7 @@ export interface MRT_Localization {
48
50
 
49
51
  export const MRT_DefaultLocalization_EN: MRT_Localization = {
50
52
  actionsHeadColumnTitle: 'Actions',
53
+ changeFilterMode: 'Change filter mode',
51
54
  columnActionMenuButtonTitle: 'Column Actions',
52
55
  columnActionMenuItemClearSort: 'Clear sort',
53
56
  columnActionMenuItemGroupBy: 'Group by {column}',
@@ -64,8 +67,9 @@ export const MRT_DefaultLocalization_EN: MRT_Localization = {
64
67
  filterMenuItemEmpty: 'Empty',
65
68
  filterMenuItemEndsWith: 'Ends With',
66
69
  filterMenuItemEquals: 'Equals',
67
- changeFilterMode: 'Change filter mode',
68
70
  filterMenuItemFuzzy: 'Fuzzy Match (Default)',
71
+ filterMenuItemGreaterThan: 'Greater Than',
72
+ filterMenuItemLessThan: 'Less Than',
69
73
  filterMenuItemNotEmpty: 'Not Empty',
70
74
  filterMenuItemNotEquals: 'Not Equals',
71
75
  filterMenuItemStartsWith: 'Starts With',
@@ -1,7 +1,7 @@
1
1
  import React, { FC, useState } from 'react';
2
2
  import { Box, IconButton, Menu, MenuItem } from '@mui/material';
3
3
  import { useMRT } from '../useMRT';
4
- import { MRT_HeaderGroup } from '..';
4
+ import type { MRT_HeaderGroup } from '..';
5
5
  import { MRT_FilterTypeMenu } from './MRT_FilterTypeMenu';
6
6
 
7
7
  export const commonMenuItemStyles = {
@@ -1,7 +1,20 @@
1
1
  import React, { FC, useMemo } from 'react';
2
2
  import { Menu, MenuItem } from '@mui/material';
3
3
  import { useMRT } from '../useMRT';
4
- import { MRT_FilterType, MRT_FILTER_TYPE, MRT_HeaderGroup } from '..';
4
+ import type { MRT_FilterType, MRT_HeaderGroup } from '..';
5
+ import { MRT_FILTER_TYPE } from '../enums';
6
+ import {
7
+ containsFilterFN,
8
+ emptyFilterFN,
9
+ endsWithFilterFN,
10
+ equalsFilterFN,
11
+ fuzzyFilterFN,
12
+ greaterThanFilterFN,
13
+ lessThanFilterFN,
14
+ notEmptyFilterFN,
15
+ notEqualsFilterFN,
16
+ startsWithFilterFN,
17
+ } from '../filtersFNs';
5
18
 
6
19
  const commonMenuItemStyles = {
7
20
  py: '6px',
@@ -28,47 +41,68 @@ export const MRT_FilterTypeMenu: FC<Props> = ({
28
41
  type: MRT_FILTER_TYPE;
29
42
  label: string;
30
43
  divider: boolean;
44
+ fn: Function;
31
45
  }[] = useMemo(
32
46
  () => [
33
47
  {
34
48
  type: MRT_FILTER_TYPE.FUZZY,
35
49
  label: localization.filterMenuItemFuzzy,
36
50
  divider: false,
51
+ fn: fuzzyFilterFN,
37
52
  },
38
53
  {
39
54
  type: MRT_FILTER_TYPE.CONTAINS,
40
55
  label: localization.filterMenuItemContains,
41
56
  divider: true,
57
+ fn: containsFilterFN,
42
58
  },
43
59
  {
44
60
  type: MRT_FILTER_TYPE.STARTS_WITH,
45
61
  label: localization.filterMenuItemStartsWith,
46
62
  divider: false,
63
+ fn: startsWithFilterFN,
47
64
  },
48
65
  {
49
66
  type: MRT_FILTER_TYPE.ENDS_WITH,
50
67
  label: localization.filterMenuItemEndsWith,
51
68
  divider: true,
69
+ fn: endsWithFilterFN,
52
70
  },
53
71
  {
54
72
  type: MRT_FILTER_TYPE.EQUALS,
55
73
  label: localization.filterMenuItemEquals,
56
74
  divider: false,
75
+ fn: equalsFilterFN,
57
76
  },
58
77
  {
59
78
  type: MRT_FILTER_TYPE.NOT_EQUALS,
60
79
  label: localization.filterMenuItemNotEquals,
61
80
  divider: true,
81
+ fn: notEqualsFilterFN,
82
+ },
83
+ {
84
+ type: MRT_FILTER_TYPE.GREATER_THAN,
85
+ label: localization.filterMenuItemGreaterThan,
86
+ divider: false,
87
+ fn: greaterThanFilterFN,
88
+ },
89
+ {
90
+ type: MRT_FILTER_TYPE.LESS_THAN,
91
+ label: localization.filterMenuItemLessThan,
92
+ divider: true,
93
+ fn: lessThanFilterFN,
62
94
  },
63
95
  {
64
96
  type: MRT_FILTER_TYPE.EMPTY,
65
97
  label: localization.filterMenuItemEmpty,
66
98
  divider: false,
99
+ fn: emptyFilterFN,
67
100
  },
68
101
  {
69
102
  type: MRT_FILTER_TYPE.NOT_EMPTY,
70
103
  label: localization.filterMenuItemNotEmpty,
71
104
  divider: false,
105
+ fn: notEmptyFilterFN,
72
106
  },
73
107
  ],
74
108
  [],
@@ -98,12 +132,12 @@ export const MRT_FilterTypeMenu: FC<Props> = ({
98
132
  dense: tableInstance.state.densePadding,
99
133
  }}
100
134
  >
101
- {filterTypes.map(({ type, label, divider }, index) => (
135
+ {filterTypes.map(({ type, label, divider, fn }, index) => (
102
136
  <MenuItem
103
137
  divider={divider}
104
138
  key={index}
105
139
  onClick={() => handleSelectFilterType(type)}
106
- selected={type === filterType}
140
+ selected={type === filterType || fn === filterType}
107
141
  sx={commonMenuItemStyles}
108
142
  value={type}
109
143
  >
@@ -1,7 +1,7 @@
1
1
  import React, { FC } from 'react';
2
2
  import { Menu, MenuItem } from '@mui/material';
3
3
  import { useMRT } from '../useMRT';
4
- import { MRT_Row } from '..';
4
+ import type { MRT_Row } from '..';
5
5
  import { commonMenuItemStyles } from './MRT_ColumnActionMenu';
6
6
 
7
7
  interface Props {
@@ -1,7 +1,7 @@
1
1
  import React, { FC } from 'react';
2
2
  import { FormControlLabel, MenuItem, Switch } from '@mui/material';
3
3
  import { ColumnInstance } from 'react-table';
4
- import { MRT_ColumnInstance } from '..';
4
+ import type { MRT_ColumnInstance } from '..';
5
5
  import { commonMenuItemStyles } from './MRT_ColumnActionMenu';
6
6
 
7
7
  interface Props {
package/src/useMRT.tsx CHANGED
@@ -21,7 +21,8 @@ import {
21
21
  useSortBy,
22
22
  useTable,
23
23
  } from 'react-table';
24
- import { MRT_FilterType, MRT_FILTER_TYPE, MRT_Row, MRT_TableInstance } from '.';
24
+ import type { MRT_FilterType, MRT_Row, MRT_TableInstance } from '.';
25
+ import { MRT_FILTER_TYPE } from './enums';
25
26
  import { defaultFilterFNs } from './filtersFNs';
26
27
  import { MRT_Icons } from './icons';
27
28
  import { MRT_Localization } from './localization';
@@ -91,19 +92,35 @@ export const MaterialReactTableProvider = <D extends {} = {}>(
91
92
  [props.filterTypes],
92
93
  );
93
94
 
94
- const [currentFilterTypes, setCurrentFilterTypes] = useState<{
95
- [key: string]: MRT_FilterType;
96
- }>(() =>
97
- Object.assign(
95
+ const getInitialFilterTypeState = () => {
96
+ let lowestLevelColumns: any[] = props.columns;
97
+ let currentCols: any[] = props.columns;
98
+ while (!!currentCols.length && currentCols.some((col) => col.columns)) {
99
+ const nextCols = currentCols
100
+ .filter((col) => !!col.columns)
101
+ .map((col) => col.columns)
102
+ .flat();
103
+ if (nextCols.every((col) => !col.columns)) {
104
+ lowestLevelColumns = [...lowestLevelColumns, ...nextCols];
105
+ }
106
+ currentCols = nextCols;
107
+ }
108
+ lowestLevelColumns = lowestLevelColumns.filter((col) => !col.columns);
109
+
110
+ return Object.assign(
98
111
  {},
99
- ...props.columns.map((c) => ({
112
+ ...lowestLevelColumns.map((c) => ({
100
113
  [c.accessor as string]:
101
114
  c.filter ??
102
115
  props?.initialState?.filters?.[c.accessor as any] ??
103
116
  (!!c.filterSelectOptions ? 'equals' : 'fuzzy'),
104
117
  })),
105
- ),
106
- );
118
+ );
119
+ };
120
+
121
+ const [currentFilterTypes, setCurrentFilterTypes] = useState<{
122
+ [key: string]: MRT_FilterType;
123
+ }>(() => getInitialFilterTypeState());
107
124
 
108
125
  const columns = useMemo(
109
126
  () =>