material-react-table 0.5.6 → 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 +8 -2
  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 +20 -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 -0
  19. package/dist/material-react-table.cjs.development.js +234 -68
  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 +235 -69
  24. package/dist/material-react-table.esm.js.map +1 -1
  25. package/dist/menus/MRT_ColumnActionMenu.d.ts +12 -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 +3 -4
  31. package/src/MaterialReactTable.tsx +5 -9
  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 -2
  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 +42 -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 +7 -16
  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 +70 -16
  51. package/src/inputs/MRT_SelectCheckbox.tsx +1 -1
  52. package/src/localization.ts +6 -0
  53. package/src/menus/MRT_ColumnActionMenu.tsx +51 -43
  54. package/src/menus/MRT_FilterTypeMenu.tsx +56 -16
  55. package/src/menus/MRT_RowActionMenu.tsx +6 -8
  56. package/src/menus/MRT_ShowHideColumnsMenu.tsx +6 -2
  57. package/src/useMRT.tsx +36 -14
@@ -1,5 +1,16 @@
1
1
  import { FC } from 'react';
2
- import { MRT_HeaderGroup } from '..';
2
+ import type { MRT_HeaderGroup } from '..';
3
+ export declare const commonMenuItemStyles: {
4
+ py: string;
5
+ my: number;
6
+ justifyContent: string;
7
+ alignItems: string;
8
+ };
9
+ export declare const commonListItemStyles: {
10
+ display: string;
11
+ gap: string;
12
+ alignItems: string;
13
+ };
3
14
  interface Props {
4
15
  anchorEl: HTMLElement | null;
5
16
  column: MRT_HeaderGroup;
@@ -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.6",
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.",
@@ -28,7 +28,7 @@
28
28
  },
29
29
  "scripts": {
30
30
  "analyze": "size-limit --why",
31
- "build": "tsdx build && size-limit",
31
+ "build": "tsdx build && size-limit && rm -rf material-react-table-docs/node_modules/material-react-table/dist && cp -r dist material-react-table-docs/node_modules/material-react-table/ && cp -r src material-react-table-docs/node_modules/material-react-table/ && cp -r package.json material-react-table-docs/node_modules/material-react-table/package.json",
32
32
  "build-storybook": "build-storybook",
33
33
  "format": "prettier -w .",
34
34
  "lint": "tsdx lint",
@@ -36,8 +36,7 @@
36
36
  "size": "size-limit",
37
37
  "start": "tsdx watch",
38
38
  "storybook": "start-storybook -p 6006",
39
- "test": "tsdx test --passWithNoTests",
40
- "upgrade": "ncu -u && npm i"
39
+ "test": "tsdx test --passWithNoTests"
41
40
  },
42
41
  "husky": {
43
42
  "hooks": {
@@ -19,6 +19,7 @@ import {
19
19
  Cell,
20
20
  Column,
21
21
  ColumnInstance,
22
+ FilterType,
22
23
  // ColumnInterface,
23
24
  HeaderGroup,
24
25
  Row,
@@ -76,6 +77,7 @@ import { MaterialReactTableProvider } from './useMRT';
76
77
  import { MRT_TableContainer } from './table/MRT_TableContainer';
77
78
  import { MRT_Localization, MRT_DefaultLocalization_EN } from './localization';
78
79
  import { MRT_Default_Icons, MRT_Icons } from './icons';
80
+ import { MRT_FILTER_TYPE } from './enums';
79
81
 
80
82
  export type MRT_TableOptions<D extends {} = {}> = TableOptions<D> &
81
83
  UseExpandedOptions<D> &
@@ -132,6 +134,8 @@ export type MRT_ColumnInterface<D extends {} = {}> =
132
134
  Header?: string;
133
135
  disableFilters?: boolean;
134
136
  editable?: boolean;
137
+ filter?: MRT_FilterType | string | FilterType<D>;
138
+ filterSelectOptions?: (string | { text: string; value: string })[];
135
139
  muiTableBodyCellEditTextFieldProps?:
136
140
  | TextFieldProps
137
141
  | ((cell: MRT_Cell<D>) => TextFieldProps);
@@ -183,15 +187,7 @@ export type MRT_Cell<D extends {} = {}, _V = any> = Cell<D> &
183
187
  UseGroupByCellProps<D> &
184
188
  UseRowStateCellProps<D> & {};
185
189
 
186
- export type MRT_FilterType =
187
- | 'contains'
188
- | 'empty'
189
- | 'endsWith'
190
- | 'equals'
191
- | 'fuzzy'
192
- | 'notEmpty'
193
- | 'notEquals'
194
- | 'startsWith';
190
+ export type MRT_FilterType = MRT_FILTER_TYPE | Function;
195
191
 
196
192
  export type MRT_TableState<D extends {} = {}> = TableState<D> &
197
193
  UseColumnOrderState<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
 
@@ -45,7 +45,6 @@ export const MRT_ShowHideColumnsButton: FC<Props> = ({ ...rest }) => {
45
45
  onClose={() => setAnchorEl(null)}
46
46
  MenuListProps={{
47
47
  dense: tableInstance.state.densePadding,
48
- disablePadding: true,
49
48
  }}
50
49
  >
51
50
  <Box
@@ -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
@@ -1,6 +1,18 @@
1
1
  import { matchSorter } from 'match-sorter';
2
2
  import { MRT_Row } from '.';
3
3
 
4
+ export const fuzzySearchFN = (
5
+ rows: MRT_Row[],
6
+ columnIds: string[],
7
+ filterValue: string | number,
8
+ ) =>
9
+ matchSorter(rows, filterValue.toString().trim(), {
10
+ keys: columnIds.map((c) => `values.${c}`),
11
+ sorter: (rankedItems) => rankedItems,
12
+ });
13
+
14
+ fuzzySearchFN.autoRemove = (val: any) => !val;
15
+
4
16
  export const fuzzyFilterFN = (
5
17
  rows: MRT_Row[],
6
18
  id: string,
@@ -84,6 +96,34 @@ export const notEqualsFilterFN = (
84
96
 
85
97
  notEqualsFilterFN.autoRemove = (val: any) => !val;
86
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
+
87
127
  export const emptyFilterFN = (
88
128
  rows: MRT_Row[],
89
129
  id: string,
@@ -104,6 +144,8 @@ export const defaultFilterFNs = {
104
144
  contains: containsFilterFN,
105
145
  empty: emptyFilterFN,
106
146
  endsWith: endsWithFilterFN,
147
+ greaterThan: greaterThanFilterFN,
148
+ lessThan: lessThanFilterFN,
107
149
  equals: equalsFilterFN,
108
150
  fuzzy: fuzzyFilterFN,
109
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,
@@ -79,18 +79,7 @@ export const MRT_TableHeadCell: FC<Props> = ({ column }) => {
79
79
  const filterTooltip = !!column.filterValue
80
80
  ? localization.filterApplied
81
81
  .replace('{column}', String(column.Header))
82
- .replace(
83
- '{filterType}',
84
- // @ts-ignore
85
- localization[
86
- `filterMenuItem${
87
- tableInstance.state.currentFilterTypes[column.id]
88
- .charAt(0)
89
- .toUpperCase() +
90
- tableInstance.state.currentFilterTypes[column.id].slice(1)
91
- }`
92
- ],
93
- )
82
+ .replace('{filterType}', column.filterValue)
94
83
  : localization.toggleFilterButtonTitle;
95
84
 
96
85
  const columnHeader = column.render('Header') as string;
@@ -127,7 +116,7 @@ export const MRT_TableHeadCell: FC<Props> = ({ column }) => {
127
116
  >
128
117
  {column.render('Header')}
129
118
  {!isParentHeader && column.canSort && (
130
- <Tooltip arrow title={sortTooltip}>
119
+ <Tooltip arrow placement="top" title={sortTooltip}>
131
120
  <TableSortLabel
132
121
  aria-label={sortTooltip}
133
122
  active={column.isSorted}
@@ -136,19 +125,21 @@ export const MRT_TableHeadCell: FC<Props> = ({ column }) => {
136
125
  </Tooltip>
137
126
  )}
138
127
  {!isParentHeader && !!column.canFilter && (
139
- <Tooltip arrow title={filterTooltip}>
128
+ <Tooltip arrow placement="top" title={filterTooltip}>
140
129
  <IconButton
130
+ disableRipple
141
131
  onClick={(event) => {
142
132
  event.stopPropagation();
143
133
  setShowFilters(!tableInstance.state.showFilters);
144
134
  }}
145
135
  size="small"
146
136
  sx={{
137
+ m: 0,
147
138
  opacity: !!column.filterValue ? 0.8 : 0,
148
139
  p: '2px',
149
- m: 0,
150
140
  transition: 'all 0.2s ease-in-out',
151
141
  '&:hover': {
142
+ backgroundColor: 'transparent',
152
143
  opacity: 0.8,
153
144
  },
154
145
  }}
@@ -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;
@@ -3,14 +3,16 @@ import {
3
3
  Chip,
4
4
  IconButton,
5
5
  InputAdornment,
6
+ MenuItem,
6
7
  TextField,
7
8
  TextFieldProps,
8
9
  Tooltip,
9
10
  } from '@mui/material';
10
11
  import { useAsyncDebounce } from 'react-table';
11
12
  import { useMRT } from '../useMRT';
12
- import { MRT_HeaderGroup } from '..';
13
+ import type { MRT_HeaderGroup } from '..';
13
14
  import { MRT_FilterTypeMenu } from '../menus/MRT_FilterTypeMenu';
15
+ import { MRT_FILTER_TYPE } from '../enums';
14
16
 
15
17
  interface Props {
16
18
  column: MRT_HeaderGroup;
@@ -65,7 +67,10 @@ export const MRT_FilterTextField: FC<Props> = ({ column }) => {
65
67
  const handleClearFilterChip = () => {
66
68
  setFilterValue('');
67
69
  column.setFilter(undefined);
68
- setCurrentFilterTypes((prev) => ({ ...prev, [column.id]: 'fuzzy' }));
70
+ setCurrentFilterTypes((prev) => ({
71
+ ...prev,
72
+ [column.id]: MRT_FILTER_TYPE.FUZZY,
73
+ }));
69
74
  };
70
75
 
71
76
  if (column.Filter) {
@@ -73,7 +78,13 @@ export const MRT_FilterTextField: FC<Props> = ({ column }) => {
73
78
  }
74
79
 
75
80
  const filterType = tableInstance.state.currentFilterTypes[column.id];
76
- const filterChipLabel = ['empty', 'notEmpty'].includes(filterType);
81
+ const isCustomFilterType = filterType instanceof Function;
82
+ const isSelectFilter = !!column.filterSelectOptions;
83
+ const filterChipLabel =
84
+ !isCustomFilterType &&
85
+ [MRT_FILTER_TYPE.EMPTY, MRT_FILTER_TYPE.NOT_EMPTY].includes(
86
+ filterType as MRT_FILTER_TYPE,
87
+ );
77
88
  const filterPlaceholder = localization.filterTextFieldPlaceholder?.replace(
78
89
  '{column}',
79
90
  String(column.Header),
@@ -92,26 +103,39 @@ export const MRT_FilterTextField: FC<Props> = ({ column }) => {
92
103
  },
93
104
  title: filterPlaceholder,
94
105
  }}
106
+ label={isSelectFilter && !filterValue ? filterPlaceholder : undefined}
107
+ InputLabelProps={{
108
+ shrink: false,
109
+ sx: {
110
+ maxWidth: 'calc(100% - 2.5rem)',
111
+ },
112
+ title: filterPlaceholder,
113
+ }}
95
114
  margin="none"
96
- placeholder={filterChipLabel ? '' : filterPlaceholder}
115
+ placeholder={
116
+ filterChipLabel || isSelectFilter ? undefined : filterPlaceholder
117
+ }
97
118
  onChange={(e: ChangeEvent<HTMLInputElement>) => {
98
119
  setFilterValue(e.target.value);
99
120
  handleChange(e.target.value);
100
121
  }}
101
122
  onClick={(e) => e.stopPropagation()}
123
+ select={isSelectFilter}
102
124
  value={filterValue ?? ''}
103
125
  variant="standard"
104
126
  InputProps={{
105
- startAdornment: (
127
+ startAdornment: !isSelectFilter && (
106
128
  <InputAdornment position="start">
107
- <Tooltip arrow title="Change Filter Mode">
108
- <IconButton
109
- onClick={handleFilterMenuOpen}
110
- size="small"
111
- sx={{ height: '1.75rem', width: '1.75rem' }}
112
- >
113
- <FilterListIcon />
114
- </IconButton>
129
+ <Tooltip arrow title={localization.changeFilterMode}>
130
+ <span>
131
+ <IconButton
132
+ onClick={handleFilterMenuOpen}
133
+ size="small"
134
+ sx={{ height: '1.75rem', width: '1.75rem' }}
135
+ >
136
+ <FilterListIcon />
137
+ </IconButton>
138
+ </span>
115
139
  </Tooltip>
116
140
  {filterChipLabel && (
117
141
  <Chip onDelete={handleClearFilterChip} label={filterType} />
@@ -122,16 +146,20 @@ export const MRT_FilterTextField: FC<Props> = ({ column }) => {
122
146
  <InputAdornment position="end">
123
147
  <Tooltip
124
148
  arrow
149
+ disableHoverListener={isSelectFilter}
125
150
  placement="right"
126
151
  title={localization.filterTextFieldClearButtonTitle ?? ''}
127
152
  >
128
153
  <span>
129
154
  <IconButton
130
155
  aria-label={localization.filterTextFieldClearButtonTitle}
131
- disabled={filterValue?.length === 0}
156
+ disabled={!filterValue?.length}
132
157
  onClick={handleClear}
133
158
  size="small"
134
- sx={{ height: '1.75rem', width: '1.75rem' }}
159
+ sx={{
160
+ height: '1.75rem',
161
+ width: '1.75rem',
162
+ }}
135
163
  >
136
164
  <CloseIcon fontSize="small" />
137
165
  </IconButton>
@@ -145,9 +173,35 @@ export const MRT_FilterTextField: FC<Props> = ({ column }) => {
145
173
  m: '0 -0.25rem',
146
174
  minWidth: !filterChipLabel ? '5rem' : 'auto',
147
175
  width: 'calc(100% + 0.5rem)',
176
+ mt: isSelectFilter && !filterValue ? '-1rem' : undefined,
177
+ '& .MuiSelect-icon': {
178
+ mr: '1.5rem',
179
+ },
148
180
  ...textFieldProps?.sx,
149
181
  }}
150
- />
182
+ >
183
+ {isSelectFilter && (
184
+ <MenuItem divider disabled={!filterValue} value="">
185
+ {localization.filterTextFieldClearButtonTitle}
186
+ </MenuItem>
187
+ )}
188
+ {column?.filterSelectOptions?.map((option) => {
189
+ let value;
190
+ let text;
191
+ if (typeof option === 'string') {
192
+ value = option;
193
+ text = option;
194
+ } else if (typeof option === 'object') {
195
+ value = option.value;
196
+ text = option.text;
197
+ }
198
+ return (
199
+ <MenuItem key={value} value={value}>
200
+ {text}
201
+ </MenuItem>
202
+ );
203
+ })}
204
+ </TextField>
151
205
  <MRT_FilterTypeMenu
152
206
  anchorEl={anchorEl}
153
207
  column={column}
@@ -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;
@@ -47,6 +50,7 @@ export interface MRT_Localization {
47
50
 
48
51
  export const MRT_DefaultLocalization_EN: MRT_Localization = {
49
52
  actionsHeadColumnTitle: 'Actions',
53
+ changeFilterMode: 'Change filter mode',
50
54
  columnActionMenuButtonTitle: 'Column Actions',
51
55
  columnActionMenuItemClearSort: 'Clear sort',
52
56
  columnActionMenuItemGroupBy: 'Group by {column}',
@@ -64,6 +68,8 @@ export const MRT_DefaultLocalization_EN: MRT_Localization = {
64
68
  filterMenuItemEndsWith: 'Ends With',
65
69
  filterMenuItemEquals: 'Equals',
66
70
  filterMenuItemFuzzy: 'Fuzzy Match (Default)',
71
+ filterMenuItemGreaterThan: 'Greater Than',
72
+ filterMenuItemLessThan: 'Less Than',
67
73
  filterMenuItemNotEmpty: 'Not Empty',
68
74
  filterMenuItemNotEquals: 'Not Equals',
69
75
  filterMenuItemStartsWith: 'Starts With',