material-react-table 0.14.4 → 0.15.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.
@@ -0,0 +1,5 @@
1
+ import type { MRT_Row } from '.';
2
+ export declare const MRT_SortingFns: {
3
+ fuzzy: (rowA: MRT_Row, rowB: MRT_Row, columnId: string) => number;
4
+ };
5
+ export declare const rankGlobalFuzzy: (rowA: MRT_Row, rowB: MRT_Row) => number;
package/dist/utils.d.ts CHANGED
@@ -7,7 +7,7 @@ export declare const createGroup: <D extends Record<string, any> = {}>(table: Ta
7
7
  export declare const createDataColumn: <D extends Record<string, any> = {}>(table: Table<D>, column: MRT_ColumnDef<D>, currentFilterFns: {
8
8
  [key: string]: import("@tanstack/react-table").FilterFnOption<import("@tanstack/react-table").TableGenerics>;
9
9
  }) => ColumnDef<D>;
10
- export declare const createDisplayColumn: <D extends Record<string, any> = {}>(table: Table<D>, column: Pick<MRT_ColumnDef<D>, "accessorFn" | "footer" | "columns" | "filterFn" | "id" | "accessorKey" | "meta" | "enableHiding" | "enablePinning" | "enableColumnFilter" | "enableGlobalFilter" | "sortingFn" | "sortDescFirst" | "enableSorting" | "enableMultiSort" | "invertSorting" | "sortUndefined" | "aggregationFn" | "enableGrouping" | "enableResizing" | "size" | "minSize" | "maxSize" | "AggregatedCell" | "Cell" | "Edit" | "Filter" | "Footer" | "Header" | "enableClickToCopy" | "enableColumnActions" | "enableColumnOrdering" | "enableEditing" | "enabledColumnFilterOptions" | "filterSelectOptions" | "muiTableBodyCellCopyButtonProps" | "muiTableBodyCellEditTextFieldProps" | "muiTableBodyCellProps" | "muiTableFooterCellProps" | "muiTableHeadCellColumnActionsButtonProps" | "muiTableHeadCellFilterTextFieldProps" | "muiTableHeadCellProps" | "onCellEditBlur" | "onCellEditChanged" | "onColumnFilterValueChanged" | "onColumnFilterValueChangedDebounced"> & {
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" | "enableColumnOrdering" | "enableEditing" | "enableColumnFilterChangeMode" | "enabledColumnFilterOptions" | "filterSelectOptions" | "muiTableBodyCellCopyButtonProps" | "muiTableBodyCellEditTextFieldProps" | "muiTableBodyCellProps" | "muiTableFooterCellProps" | "muiTableHeadCellColumnActionsButtonProps" | "muiTableHeadCellFilterTextFieldProps" | "muiTableHeadCellProps" | "onCellEditBlur" | "onCellEditChanged" | "onColumnFilterValueChanged" | "onColumnFilterValueChangedDebounced"> & {
11
11
  header?: string | undefined;
12
12
  }) => ColumnDef<D>;
13
13
  export declare const reorderColumn: (movingColumn: MRT_Column, receivingColumn: MRT_Column, columnOrder: ColumnOrderState, setColumnOrder: (updater: Updater<ColumnOrderState>) => void) => void;
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.14.4",
2
+ "version": "0.15.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.",
@@ -59,9 +59,9 @@
59
59
  "@babel/core": "^7.18.5",
60
60
  "@emotion/react": "^11.9.3",
61
61
  "@emotion/styled": "^11.9.3",
62
- "@faker-js/faker": "^6.3.1",
62
+ "@faker-js/faker": "^7.3.0",
63
63
  "@mui/icons-material": "^5.8.4",
64
- "@mui/material": "^5.8.4",
64
+ "@mui/material": "^5.8.5",
65
65
  "@size-limit/preset-small-lib": "^7.0.8",
66
66
  "@storybook/addon-a11y": "^6.5.9",
67
67
  "@storybook/addon-actions": "^6.5.9",
@@ -73,7 +73,7 @@
73
73
  "@types/react": "^18.0.14",
74
74
  "@types/react-dom": "^18.0.5",
75
75
  "babel-loader": "^8.2.5",
76
- "eslint": "^8.17.0",
76
+ "eslint": "^8.18.0",
77
77
  "eslint-plugin-react-hooks": "^4.6.0",
78
78
  "husky": "^8.0.1",
79
79
  "prettier": "^2.7.1",
@@ -87,7 +87,7 @@
87
87
  "storybook-dark-mode": "^1.1.0",
88
88
  "tsdx": "^0.14.1",
89
89
  "tslib": "^2.4.0",
90
- "typescript": "^4.7.3"
90
+ "typescript": "^4.7.4"
91
91
  },
92
92
  "peerDependencies": {
93
93
  "@emotion/react": ">=11",
@@ -38,6 +38,8 @@ import {
38
38
  Overwrite,
39
39
  ReactTableGenerics,
40
40
  Row,
41
+ SortingFn,
42
+ SortingFnOption,
41
43
  TableGenerics,
42
44
  TableInstance,
43
45
  TableState,
@@ -52,13 +54,12 @@ import { MRT_TableRoot } from './table/MRT_TableRoot';
52
54
  export type MRT_TableOptions<D extends Record<string, any> = {}> = Partial<
53
55
  Omit<
54
56
  UseTableInstanceOptions<ReactTableGenerics>,
55
- 'columns' | 'data' | 'initialState' | 'state' | 'expandRowsFn' | 'filterFns'
57
+ 'columns' | 'data' | 'initialState' | 'state' | 'expandRowsFn'
56
58
  >
57
59
  > & {
58
60
  columns: MRT_ColumnDef<D>[];
59
61
  data: D[];
60
62
  expandRowsFn?: (dataRow: D) => D[];
61
- filterFns?: MRT_FILTER_OPTION | FilterFn<D> | string | number | symbol;
62
63
  initialState?: Partial<MRT_TableState<D>>;
63
64
  state?: Partial<MRT_TableState<D>>;
64
65
  };
@@ -87,6 +88,7 @@ export type MRT_TableInstance<D extends Record<string, any> = {}> = Omit<
87
88
  | 'getFlatHeaders'
88
89
  | 'getLeftLeafColumns'
89
90
  | 'getPaginationRowModel'
91
+ | 'getPreFilteredRowModel'
90
92
  | 'getPrePaginationRowModel'
91
93
  | 'getRightLeafColumns'
92
94
  | 'getRowModel'
@@ -103,6 +105,7 @@ export type MRT_TableInstance<D extends Record<string, any> = {}> = Omit<
103
105
  getFlatHeaders: () => MRT_Header<D>[];
104
106
  getLeftLeafColumns: () => MRT_Column<D>[];
105
107
  getPaginationRowModel: () => MRT_RowModel<D>;
108
+ getPreFilteredRowModel: () => MRT_RowModel<D>;
106
109
  getPrePaginationRowModel: () => MRT_RowModel<D>;
107
110
  getRightLeafColumns: () => MRT_Column<D>[];
108
111
  getRowModel: () => MRT_RowModel<D>;
@@ -145,11 +148,12 @@ export type MRT_ColumnDef<D extends Record<string, any> = {}> = Omit<
145
148
  ColumnDef<D>,
146
149
  | 'accessorFn'
147
150
  | 'aggregatedCell'
148
- | 'header'
149
- | 'footer'
151
+ | 'cell'
150
152
  | 'columns'
151
153
  | 'filterFn'
152
- | 'cell'
154
+ | 'footer'
155
+ | 'header'
156
+ | 'sortingFn'
153
157
  > & {
154
158
  AggregatedCell?: ({
155
159
  cell,
@@ -203,6 +207,7 @@ export type MRT_ColumnDef<D extends Record<string, any> = {}> = Omit<
203
207
  enableColumnActions?: boolean;
204
208
  enableColumnOrdering?: boolean;
205
209
  enableEditing?: boolean;
210
+ enableColumnFilterChangeMode?: boolean;
206
211
  enabledColumnFilterOptions?: (MRT_FILTER_OPTION | string)[] | null;
207
212
  filterFn?: MRT_FilterFn;
208
213
  filterSelectOptions?: (string | { text: string; value: string })[];
@@ -312,6 +317,7 @@ export type MRT_ColumnDef<D extends Record<string, any> = {}> = Omit<
312
317
  filterValue: any;
313
318
  instance: MRT_TableInstance<D>;
314
319
  }) => void;
320
+ sortingFn?: MRT_SortingFn;
315
321
  };
316
322
 
317
323
  export type MRT_Column<D extends Record<string, any> = {}> = Omit<
@@ -357,6 +363,10 @@ export type MRT_Cell<D extends Record<string, any> = {}> = Omit<
357
363
  row: MRT_Row<D>;
358
364
  };
359
365
 
366
+ export type MRT_SortingOption = SortingFnOption<TableGenerics> | 'fuzzy';
367
+
368
+ export type MRT_SortingFn = SortingFn<TableGenerics> | MRT_SortingOption;
369
+
360
370
  export type MRT_FILTER_OPTION =
361
371
  | 'between'
362
372
  | 'contains'
@@ -373,23 +383,21 @@ export type MRT_FILTER_OPTION =
373
383
  | 'startsWith'
374
384
  | FilterFnOption<TableGenerics>;
375
385
 
376
- export type MRT_FilterFn =
377
- | FilterFn<TableGenerics>
378
- | MRT_FILTER_OPTION
379
- | number
380
- | string
381
- | symbol;
386
+ export type MRT_FilterFn = FilterFn<TableGenerics> | MRT_FILTER_OPTION;
382
387
 
383
388
  export type MaterialReactTableProps<D extends Record<string, any> = {}> =
384
389
  MRT_TableOptions<D> & {
385
390
  editingMode?: 'table' | 'row' | 'cell';
386
391
  enableClickToCopy?: boolean;
387
392
  enableColumnActions?: boolean;
393
+ enableColumnFilterChangeMode?: boolean;
388
394
  enableColumnOrdering?: boolean;
389
395
  enableDensityToggle?: boolean;
390
396
  enableEditing?: boolean;
391
397
  enableExpandAll?: boolean;
392
398
  enableFullScreenToggle?: boolean;
399
+ enableGlobalFilterChangeMode?: boolean;
400
+ enableGlobalFilterRankedResults?: boolean;
393
401
  enablePagination?: boolean;
394
402
  enablePersistentState?: boolean;
395
403
  enableRowActions?: boolean;
@@ -824,7 +832,7 @@ export type MaterialReactTableProps<D extends Record<string, any> = {}> =
824
832
  rowNumberMode?: 'original' | 'static';
825
833
  selectAllMode?: 'all' | 'page';
826
834
  tableId?: string;
827
- virtualizerProps?: VirtualizerOptions<HTMLDivElement>;
835
+ virtualizerProps?: Partial<VirtualizerOptions<HTMLDivElement>>;
828
836
  };
829
837
 
830
838
  export default <D extends Record<string, any> = {}>({
@@ -833,6 +841,7 @@ export default <D extends Record<string, any> = {}>({
833
841
  defaultColumn = { minSize: 40, maxSize: 1000, size: 180 },
834
842
  editingMode = 'row',
835
843
  enableColumnActions = true,
844
+ enableColumnFilterChangeMode = true,
836
845
  enableColumnFilters = true,
837
846
  enableColumnOrdering = false,
838
847
  enableColumnResizing = false,
@@ -841,9 +850,12 @@ export default <D extends Record<string, any> = {}>({
841
850
  enableFilters = true,
842
851
  enableFullScreenToggle = true,
843
852
  enableGlobalFilter = true,
853
+ enableGlobalFilterChangeMode = true,
854
+ enableGlobalFilterRankedResults = true,
844
855
  enableGrouping = false,
845
856
  enableHiding = true,
846
857
  enableMultiRowSelection = true,
858
+ enableMultiSort = true,
847
859
  enablePagination = true,
848
860
  enablePinning = false,
849
861
  enableRowSelection = false,
@@ -872,6 +884,7 @@ export default <D extends Record<string, any> = {}>({
872
884
  defaultColumn={defaultColumn}
873
885
  editingMode={editingMode}
874
886
  enableColumnActions={enableColumnActions}
887
+ enableColumnFilterChangeMode={enableColumnFilterChangeMode}
875
888
  enableColumnFilters={enableColumnFilters}
876
889
  enableColumnOrdering={enableColumnOrdering}
877
890
  enableColumnResizing={enableColumnResizing}
@@ -880,9 +893,12 @@ export default <D extends Record<string, any> = {}>({
880
893
  enableFilters={enableFilters}
881
894
  enableFullScreenToggle={enableFullScreenToggle}
882
895
  enableGlobalFilter={enableGlobalFilter}
896
+ enableGlobalFilterChangeMode={enableGlobalFilterChangeMode}
897
+ enableGlobalFilterRankedResults={enableGlobalFilterRankedResults}
883
898
  enableGrouping={enableGrouping}
884
899
  enableHiding={enableHiding}
885
900
  enableMultiRowSelection={enableMultiRowSelection}
901
+ enableMultiSort={enableMultiSort}
886
902
  enablePagination={enablePagination}
887
903
  enablePinning={enablePinning}
888
904
  enableRowSelection={enableRowSelection}
@@ -1,8 +1,9 @@
1
- import React, { FC, RefObject } from 'react';
1
+ import React, { FC, RefObject, useMemo } from 'react';
2
2
  import { useVirtual } from 'react-virtual';
3
3
  import { TableBody } from '@mui/material';
4
4
  import { MRT_TableBodyRow } from './MRT_TableBodyRow';
5
5
  import type { MRT_Row, MRT_TableInstance } from '..';
6
+ import { rankGlobalFuzzy } from '../sortingFns';
6
7
 
7
8
  interface Props {
8
9
  instance: MRT_TableInstance;
@@ -15,6 +16,7 @@ export const MRT_TableBody: FC<Props> = ({ instance, tableContainerRef }) => {
15
16
  getPrePaginationRowModel,
16
17
  getState,
17
18
  options: {
19
+ enableGlobalFilterRankedResults,
18
20
  enablePagination,
19
21
  enableRowVirtualization,
20
22
  muiTableBodyProps,
@@ -22,20 +24,38 @@ export const MRT_TableBody: FC<Props> = ({ instance, tableContainerRef }) => {
22
24
  },
23
25
  } = instance;
24
26
 
25
- const { density } = getState();
27
+ const { density, globalFilter, pagination } = getState();
26
28
 
27
29
  const tableBodyProps =
28
30
  muiTableBodyProps instanceof Function
29
31
  ? muiTableBodyProps({ instance })
30
32
  : muiTableBodyProps;
31
33
 
32
- const rows = enablePagination
33
- ? getPaginationRowModel().rows
34
- : getPrePaginationRowModel().rows;
34
+ const rows = useMemo(() => {
35
+ if (enableGlobalFilterRankedResults && globalFilter) {
36
+ const rankedRows = getPrePaginationRowModel().rows.sort((a, b) =>
37
+ rankGlobalFuzzy(a, b),
38
+ );
39
+ if (enablePagination) {
40
+ return rankedRows.slice(0, pagination.pageSize);
41
+ }
42
+ return rankedRows;
43
+ }
44
+
45
+ return enablePagination
46
+ ? getPaginationRowModel().rows
47
+ : getPrePaginationRowModel().rows;
48
+ }, [
49
+ enableGlobalFilterRankedResults,
50
+ (enableGlobalFilterRankedResults && globalFilter) || !enablePagination
51
+ ? getPrePaginationRowModel().rows
52
+ : getPaginationRowModel().rows,
53
+ globalFilter,
54
+ ]);
35
55
 
36
56
  const rowVirtualizer = enableRowVirtualization
37
57
  ? useVirtual({
38
- overscan: density === 'compact' ? 15 : 5,
58
+ overscan: density === 'compact' ? 20 : 10,
39
59
  size: rows.length,
40
60
  parentRef: tableContainerRef,
41
61
  ...virtualizerProps,
@@ -35,26 +35,32 @@ export const MRT_ExpandAllButton: FC<Props> = ({ instance }) => {
35
35
  enterNextDelay={1000}
36
36
  title={localization.expandAll}
37
37
  >
38
- <IconButton
39
- aria-label={localization.expandAll}
40
- disabled={!getCanSomeRowsExpand() && !renderDetailPanel}
41
- onClick={() => toggleAllRowsExpanded(!getIsAllRowsExpanded())}
42
- {...iconButtonProps}
43
- sx={{
44
- height: density === 'compact' ? '1.75rem' : '2.25rem',
45
- width: density === 'compact' ? '1.75rem' : '2.25rem',
46
- ...iconButtonProps?.sx,
47
- }}
48
- >
49
- <KeyboardDoubleArrowDownIcon
50
- style={{
51
- transform: `rotate(${
52
- getIsAllRowsExpanded() ? -180 : getIsSomeRowsExpanded() ? -90 : 0
53
- }deg)`,
54
- transition: 'transform 0.2s',
38
+ <span>
39
+ <IconButton
40
+ aria-label={localization.expandAll}
41
+ disabled={!getCanSomeRowsExpand() && !renderDetailPanel}
42
+ onClick={() => toggleAllRowsExpanded(!getIsAllRowsExpanded())}
43
+ {...iconButtonProps}
44
+ sx={{
45
+ height: density === 'compact' ? '1.75rem' : '2.25rem',
46
+ width: density === 'compact' ? '1.75rem' : '2.25rem',
47
+ ...iconButtonProps?.sx,
55
48
  }}
56
- />
57
- </IconButton>
49
+ >
50
+ <KeyboardDoubleArrowDownIcon
51
+ style={{
52
+ transform: `rotate(${
53
+ getIsAllRowsExpanded()
54
+ ? -180
55
+ : getIsSomeRowsExpanded()
56
+ ? -90
57
+ : 0
58
+ }deg)`,
59
+ transition: 'transform 0.2s',
60
+ }}
61
+ />
62
+ </IconButton>
63
+ </span>
58
64
  </Tooltip>
59
65
  );
60
66
  };
@@ -38,30 +38,32 @@ export const MRT_ExpandButton: FC<Props> = ({ row, instance }) => {
38
38
  enterNextDelay={1000}
39
39
  title={localization.expand}
40
40
  >
41
- <IconButton
42
- aria-label={localization.expand}
43
- disabled={!row.getCanExpand() && !renderDetailPanel}
44
- onClick={handleToggleExpand}
45
- {...iconButtonProps}
46
- sx={{
47
- height: density === 'compact' ? '1.75rem' : '2.25rem',
48
- width: density === 'compact' ? '1.75rem' : '2.25rem',
49
- ...iconButtonProps?.sx,
50
- }}
51
- >
52
- <ExpandMoreIcon
53
- style={{
54
- transform: `rotate(${
55
- !row.getCanExpand() && !renderDetailPanel
56
- ? -90
57
- : row.getIsExpanded()
58
- ? -180
59
- : 0
60
- }deg)`,
61
- transition: 'transform 0.2s',
41
+ <span>
42
+ <IconButton
43
+ aria-label={localization.expand}
44
+ disabled={!row.getCanExpand() && !renderDetailPanel}
45
+ onClick={handleToggleExpand}
46
+ {...iconButtonProps}
47
+ sx={{
48
+ height: density === 'compact' ? '1.75rem' : '2.25rem',
49
+ width: density === 'compact' ? '1.75rem' : '2.25rem',
50
+ ...iconButtonProps?.sx,
62
51
  }}
63
- />
64
- </IconButton>
52
+ >
53
+ <ExpandMoreIcon
54
+ style={{
55
+ transform: `rotate(${
56
+ !row.getCanExpand() && !renderDetailPanel
57
+ ? -90
58
+ : row.getIsExpanded()
59
+ ? -180
60
+ : 0
61
+ }deg)`,
62
+ transition: 'transform 0.2s',
63
+ }}
64
+ />
65
+ </IconButton>
66
+ </span>
65
67
  </Tooltip>
66
68
  );
67
69
  };
@@ -133,7 +133,7 @@ export const notEmpty = (
133
133
 
134
134
  notEmpty.autoRemove = (val: any) => !val;
135
135
 
136
- export const defaultFilterFNs = {
136
+ export const MRT_FilterFns = {
137
137
  between,
138
138
  contains,
139
139
  empty,
@@ -32,6 +32,7 @@ export const MRT_FilterTextField: FC<Props> = ({
32
32
  const {
33
33
  getState,
34
34
  options: {
35
+ enableColumnFilterChangeMode,
35
36
  enabledColumnFilterOptions,
36
37
  icons: { FilterListIcon, CloseIcon },
37
38
  localization,
@@ -176,6 +177,10 @@ export const MRT_FilterTextField: FC<Props> = ({
176
177
  const allowedColumnFilterOptions =
177
178
  columnDef?.enabledColumnFilterOptions ?? enabledColumnFilterOptions;
178
179
 
180
+ const allowColumnChangeMode =
181
+ enableColumnFilterChangeMode &&
182
+ columnDef.enableColumnFilterChangeMode !== false;
183
+
179
184
  return (
180
185
  <>
181
186
  <TextField
@@ -190,6 +195,7 @@ export const MRT_FilterTextField: FC<Props> = ({
190
195
  title: filterPlaceholder,
191
196
  }}
192
197
  helperText={
198
+ allowColumnChangeMode &&
193
199
  !inputIndex &&
194
200
  (allowedColumnFilterOptions === undefined ||
195
201
  (allowedColumnFilterOptions?.length ?? 0) > 0) ? (
@@ -224,7 +230,6 @@ export const MRT_FilterTextField: FC<Props> = ({
224
230
  whiteSpace: 'nowrap',
225
231
  },
226
232
  }}
227
- label={isSelectFilter && !filterValue ? filterPlaceholder : undefined}
228
233
  margin="none"
229
234
  placeholder={
230
235
  filterChipLabel || isSelectFilter ? undefined : filterPlaceholder
@@ -235,10 +240,12 @@ export const MRT_FilterTextField: FC<Props> = ({
235
240
  value={filterValue ?? ''}
236
241
  variant="standard"
237
242
  InputProps={{
238
- startAdornment: !isSelectFilter &&
243
+ startAdornment:
244
+ allowColumnChangeMode &&
245
+ !isSelectFilter &&
239
246
  !inputIndex &&
240
247
  (allowedColumnFilterOptions === undefined ||
241
- (allowedColumnFilterOptions?.length ?? 0) > 0) && (
248
+ !!allowedColumnFilterOptions?.length) ? (
242
249
  <InputAdornment position="start">
243
250
  <Tooltip arrow title={localization.changeFilterMode}>
244
251
  <span>
@@ -259,6 +266,8 @@ export const MRT_FilterTextField: FC<Props> = ({
259
266
  />
260
267
  )}
261
268
  </InputAdornment>
269
+ ) : (
270
+ <FilterListIcon />
262
271
  ),
263
272
  endAdornment: !filterChipLabel && (
264
273
  <InputAdornment position="end">
@@ -292,7 +301,6 @@ export const MRT_FilterTextField: FC<Props> = ({
292
301
  p: 0,
293
302
  minWidth: !filterChipLabel ? '8rem' : 'auto',
294
303
  width: 'calc(100% + 0.5rem)',
295
- mt: isSelectFilter && !filterValue ? '-1rem' : undefined,
296
304
  '& .MuiSelect-icon': {
297
305
  mr: '1.5rem',
298
306
  },
@@ -20,17 +20,18 @@ interface Props {
20
20
  instance: MRT_TableInstance;
21
21
  }
22
22
 
23
- export const MRT_SearchTextField: FC<Props> = ({ instance }) => {
23
+ export const MRT_GlobalFilterTextField: FC<Props> = ({ instance }) => {
24
24
  const {
25
25
  getState,
26
26
  setGlobalFilter,
27
27
  options: {
28
+ enableGlobalFilterChangeMode,
28
29
  icons: { SearchIcon, CloseIcon },
29
- tableId,
30
30
  localization,
31
31
  muiSearchTextFieldProps,
32
32
  onGlobalFilterValueChanged,
33
33
  onGlobalFilterValueChangedDebounced,
34
+ tableId,
34
35
  },
35
36
  } = instance;
36
37
 
@@ -76,7 +77,7 @@ export const MRT_SearchTextField: FC<Props> = ({ instance }) => {
76
77
  value={searchValue ?? ''}
77
78
  variant="standard"
78
79
  InputProps={{
79
- startAdornment: (
80
+ startAdornment: enableGlobalFilterChangeMode ? (
80
81
  <InputAdornment position="start">
81
82
  <Tooltip arrow title={localization.changeSearchMode}>
82
83
  <IconButton
@@ -89,18 +90,23 @@ export const MRT_SearchTextField: FC<Props> = ({ instance }) => {
89
90
  </IconButton>
90
91
  </Tooltip>
91
92
  </InputAdornment>
93
+ ) : (
94
+ <SearchIcon />
92
95
  ),
93
96
  endAdornment: (
94
97
  <InputAdornment position="end">
95
- <IconButton
96
- aria-label={localization.clearSearch}
97
- disabled={searchValue?.length === 0}
98
- onClick={handleClear}
99
- size="small"
100
- title={localization.clearSearch}
101
- >
102
- <CloseIcon />
103
- </IconButton>
98
+ <Tooltip arrow title={localization.clearSearch ?? ''}>
99
+ <span>
100
+ <IconButton
101
+ aria-label={localization.clearSearch}
102
+ disabled={!searchValue?.length}
103
+ onClick={handleClear}
104
+ size="small"
105
+ >
106
+ <CloseIcon />
107
+ </IconButton>
108
+ </span>
109
+ </Tooltip>
104
110
  </InputAdornment>
105
111
  ),
106
112
  }}
@@ -18,7 +18,7 @@ import {
18
18
  notEmpty,
19
19
  notEquals,
20
20
  startsWith,
21
- } from '../filtersFNs';
21
+ } from '../filtersFns';
22
22
 
23
23
  const commonMenuItemStyles = {
24
24
  py: '6px',
@@ -0,0 +1,25 @@
1
+ import { compareItems, RankingInfo } from '@tanstack/match-sorter-utils';
2
+ import { Row, sortingFns } from '@tanstack/react-table';
3
+ import type { MRT_Row } from '.';
4
+
5
+ const fuzzy = (rowA: MRT_Row, rowB: MRT_Row, columnId: string) => {
6
+ let dir = 0;
7
+ if (rowA.columnFiltersMeta[columnId]) {
8
+ dir = compareItems(
9
+ rowA.columnFiltersMeta[columnId]! as RankingInfo,
10
+ rowB.columnFiltersMeta[columnId]! as RankingInfo,
11
+ );
12
+ }
13
+ // Provide a fallback for when the item ranks are equal
14
+ return dir === 0
15
+ ? sortingFns.alphanumeric(rowA as Row<any>, rowB as Row<any>, columnId)
16
+ : dir;
17
+ };
18
+
19
+ export const MRT_SortingFns = {
20
+ fuzzy,
21
+ };
22
+
23
+ export const rankGlobalFuzzy = (rowA: MRT_Row, rowB: MRT_Row) =>
24
+ Math.max(...Object.values(rowB.columnFiltersMeta).map((v: any) => v.rank)) -
25
+ Math.max(...Object.values(rowA.columnFiltersMeta).map((v: any) => v.rank));
@@ -1,18 +1,20 @@
1
1
  import React, { useEffect, useMemo, useState } from 'react';
2
2
  import {
3
3
  FilterFn,
4
+ ReactTableGenerics,
5
+ Table,
6
+ TableState,
4
7
  createTable,
8
+ filterFns,
9
+ getCoreRowModel,
5
10
  getExpandedRowModel,
6
- getPaginationRowModel,
7
- useTableInstance,
11
+ getFacetedRowModel,
12
+ getFilteredRowModel,
8
13
  getGroupedRowModel,
14
+ getPaginationRowModel,
9
15
  getSortedRowModel,
10
- getCoreRowModel,
11
- getFilteredRowModel,
12
- ReactTableGenerics,
13
- getFacetedRowModel,
14
- TableState,
15
- Table,
16
+ useTableInstance,
17
+ sortingFns,
16
18
  } from '@tanstack/react-table';
17
19
  import {
18
20
  MRT_Cell,
@@ -29,6 +31,7 @@ import { MRT_ToggleRowActionMenuButton } from '../buttons/MRT_ToggleRowActionMen
29
31
  import { MRT_SelectCheckbox } from '../inputs/MRT_SelectCheckbox';
30
32
  import { MaterialReactTableProps } from '../MaterialReactTable';
31
33
  import { MRT_TablePaper } from './MRT_TablePaper';
34
+ import { Box, Dialog, Grow } from '@mui/material';
32
35
  import {
33
36
  createDataColumn,
34
37
  createDisplayColumn,
@@ -36,8 +39,8 @@ import {
36
39
  getAllLeafColumnDefs,
37
40
  getDefaultColumnOrderIds,
38
41
  } from '../utils';
39
- import { defaultFilterFNs } from '../filtersFNs';
40
- import { Box, Dialog, Grow } from '@mui/material';
42
+ import { MRT_FilterFns } from '../filtersFns';
43
+ import { MRT_SortingFns } from '../sortingFns';
41
44
 
42
45
  export const MRT_TableRoot = <D extends Record<string, any> = {}>(
43
46
  props: MaterialReactTableProps<D>,
@@ -123,8 +126,7 @@ export const MRT_TableRoot = <D extends Record<string, any> = {}>(
123
126
  () =>
124
127
  // @ts-ignore
125
128
  createTable().setOptions({
126
- //@ts-ignore
127
- filterFns: defaultFilterFNs,
129
+ filterFns: { ...filterFns, ...MRT_FilterFns, ...props.filterFns },
128
130
  getCoreRowModel: getCoreRowModel(),
129
131
  getExpandedRowModel: getExpandedRowModel(),
130
132
  getFacetedRowModel: getFacetedRowModel(),
@@ -132,8 +134,7 @@ export const MRT_TableRoot = <D extends Record<string, any> = {}>(
132
134
  getGroupedRowModel: getGroupedRowModel(),
133
135
  getPaginationRowModel: getPaginationRowModel(),
134
136
  getSortedRowModel: getSortedRowModel(),
135
- getSubRows: (row) => (row as MRT_Row)?.subRows,
136
- tableId,
137
+ sortingFns: { ...sortingFns, ...MRT_SortingFns, ...props.sortingFns },
137
138
  }) as Table<D>,
138
139
  [],
139
140
  );
@@ -252,6 +253,7 @@ export const MRT_TableRoot = <D extends Record<string, any> = {}>(
252
253
  //@ts-ignore
253
254
  columns,
254
255
  data,
256
+ getSubRows: (row) => (row as MRT_Row)?.subRows,
255
257
  //@ts-ignore
256
258
  globalFilterFn: currentGlobalFilterFn,
257
259
  initialState,
@@ -267,6 +269,7 @@ export const MRT_TableRoot = <D extends Record<string, any> = {}>(
267
269
  showGlobalFilter,
268
270
  ...props.state,
269
271
  } as TableState,
272
+ tableId,
270
273
  }),
271
274
  setCurrentEditingCell:
272
275
  props.onCurrentEditingCellChange ?? setCurrentEditingCell,
@@ -6,7 +6,7 @@ import { MRT_ToggleDensePaddingButton } from '../buttons/MRT_ToggleDensePaddingB
6
6
  import { MRT_ToggleFiltersButton } from '../buttons/MRT_ToggleFiltersButton';
7
7
  import { MRT_ToggleGlobalFilterButton } from '../buttons/MRT_ToggleGlobalFilterButton';
8
8
  import { MRT_TableInstance } from '..';
9
- import { MRT_SearchTextField } from '../inputs/MRT_SearchTextField';
9
+ import { MRT_GlobalFilterTextField } from '../inputs/MRT_GlobalFilterTextField';
10
10
 
11
11
  interface Props {
12
12
  instance: MRT_TableInstance;
@@ -44,7 +44,7 @@ export const MRT_ToolbarInternalButtons: FC<Props> = ({ instance }) => {
44
44
  }) ?? (
45
45
  <>
46
46
  {enableGlobalFilter && positionGlobalFilter === 'right' && (
47
- <MRT_SearchTextField instance={instance} />
47
+ <MRT_GlobalFilterTextField instance={instance} />
48
48
  )}
49
49
  {enableFilters && enableGlobalFilter && (
50
50
  <MRT_ToggleGlobalFilterButton instance={instance} />