material-react-table 0.5.2 → 0.5.5
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/MaterialReactTable.d.ts +10 -5
- package/dist/filtersFNs.d.ts +67 -0
- package/dist/icons.d.ts +3 -0
- package/dist/localization.d.ts +14 -1
- package/dist/material-react-table.cjs.development.js +448 -85
- package/dist/material-react-table.cjs.development.js.map +1 -1
- package/dist/material-react-table.cjs.production.min.js +1 -1
- package/dist/material-react-table.cjs.production.min.js.map +1 -1
- package/dist/material-react-table.esm.js +449 -86
- package/dist/material-react-table.esm.js.map +1 -1
- package/dist/menus/MRT_FilterTypeMenu.d.ts +10 -0
- package/dist/useMRT.d.ts +13 -9
- package/package.json +6 -2
- package/src/MaterialReactTable.tsx +25 -5
- package/src/body/MRT_TableBody.tsx +7 -2
- package/src/buttons/MRT_EditActionButtons.tsx +3 -1
- package/src/buttons/MRT_ShowHideColumnsButton.tsx +34 -31
- package/src/buttons/MRT_ToggleColumnActionMenuButton.tsx +4 -3
- package/src/buttons/MRT_ToggleFiltersButton.tsx +3 -1
- package/src/buttons/MRT_ToggleSearchButton.tsx +5 -2
- package/src/filtersFNs.ts +112 -0
- package/src/footer/MRT_TableFooter.tsx +6 -1
- package/src/footer/MRT_TableFooterCell.tsx +1 -1
- package/src/head/MRT_TableHeadCell.tsx +91 -44
- package/src/{icons.tsx → icons.ts} +9 -0
- package/src/index.tsx +0 -2
- package/src/inputs/MRT_FilterTextField.tsx +121 -52
- package/src/inputs/MRT_SearchTextField.tsx +2 -1
- package/src/inputs/MRT_SelectCheckbox.tsx +5 -7
- package/src/localization.ts +30 -4
- package/src/menus/MRT_ColumnActionMenu.tsx +145 -78
- package/src/menus/MRT_FilterTypeMenu.tsx +107 -0
- package/src/menus/MRT_RowActionMenu.tsx +20 -9
- package/src/menus/MRT_ShowHideColumnsMenu.tsx +1 -1
- package/src/table/MRT_Table.tsx +7 -2
- package/src/table/MRT_TableContainer.tsx +15 -2
- package/src/useMRT.tsx +67 -13
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { FC } from 'react';
|
|
2
|
+
import { MRT_HeaderGroup } from '..';
|
|
3
|
+
interface Props {
|
|
4
|
+
anchorEl: HTMLElement | null;
|
|
5
|
+
column: MRT_HeaderGroup;
|
|
6
|
+
setAnchorEl: (anchorEl: HTMLElement | null) => void;
|
|
7
|
+
onSelect?: () => void;
|
|
8
|
+
}
|
|
9
|
+
export declare const MRT_FilterTypeMenu: FC<Props>;
|
|
10
|
+
export {};
|
package/dist/useMRT.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import React, { PropsWithChildren } from 'react';
|
|
2
|
-
import { MRT_Row, MRT_TableInstance } from '.';
|
|
1
|
+
import React, { PropsWithChildren, Dispatch, SetStateAction } from 'react';
|
|
2
|
+
import { 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';
|
|
@@ -7,13 +7,17 @@ export declare type UseMRT<D extends {} = {}> = MaterialReactTableProps<D> & {
|
|
|
7
7
|
anyRowsCanExpand: boolean;
|
|
8
8
|
anyRowsExpanded: boolean;
|
|
9
9
|
icons: MRT_Icons;
|
|
10
|
+
idPrefix: string;
|
|
10
11
|
localization: MRT_Localization;
|
|
11
|
-
setCurrentEditingRow:
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
setCurrentEditingRow: Dispatch<SetStateAction<MRT_Row<D> | null>>;
|
|
13
|
+
setCurrentFilterTypes: Dispatch<SetStateAction<{
|
|
14
|
+
[key: string]: MRT_FilterType;
|
|
15
|
+
}>>;
|
|
16
|
+
setDensePadding: Dispatch<SetStateAction<boolean>>;
|
|
17
|
+
setFullScreen: Dispatch<SetStateAction<boolean>>;
|
|
18
|
+
setShowFilters: Dispatch<SetStateAction<boolean>>;
|
|
19
|
+
setShowSearch: Dispatch<SetStateAction<boolean>>;
|
|
16
20
|
tableInstance: MRT_TableInstance<D>;
|
|
17
21
|
};
|
|
18
|
-
export declare const MaterialReactTableProvider: <D extends {}>(props: React.PropsWithChildren<MaterialReactTableProps<D>>) => JSX.Element;
|
|
19
|
-
export declare const useMRT: <D extends {}>() => UseMRT<D>;
|
|
22
|
+
export declare const MaterialReactTableProvider: <D extends {} = {}>(props: React.PropsWithChildren<MaterialReactTableProps<D>>) => JSX.Element;
|
|
23
|
+
export declare const useMRT: <D extends {} = {}>() => UseMRT<D>;
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "0.5.
|
|
2
|
+
"version": "0.5.5",
|
|
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.",
|
|
@@ -75,7 +75,7 @@
|
|
|
75
75
|
"@storybook/react": "^6.4.19",
|
|
76
76
|
"@types/faker": "^6.6.8",
|
|
77
77
|
"@types/react": "^17.0.39",
|
|
78
|
-
"@types/react-dom": "^17.0.
|
|
78
|
+
"@types/react-dom": "^17.0.13",
|
|
79
79
|
"@types/react-table": "^7.7.9",
|
|
80
80
|
"babel-loader": "^8.2.3",
|
|
81
81
|
"husky": "^7.0.4",
|
|
@@ -93,9 +93,13 @@
|
|
|
93
93
|
},
|
|
94
94
|
"peerDependencies": {
|
|
95
95
|
"@emotion/react": ">=11",
|
|
96
|
+
"@emotion/styled": ">=11",
|
|
96
97
|
"@mui/icons-material": ">=5",
|
|
97
98
|
"@mui/material": ">=5",
|
|
98
99
|
"react": ">=16.8",
|
|
99
100
|
"react-table": ">=7"
|
|
101
|
+
},
|
|
102
|
+
"dependencies": {
|
|
103
|
+
"match-sorter": "^6.3.1"
|
|
100
104
|
}
|
|
101
105
|
}
|
|
@@ -181,6 +181,16 @@ export type MRT_Cell<D extends {} = {}, _V = any> = Cell<D> &
|
|
|
181
181
|
UseGroupByCellProps<D> &
|
|
182
182
|
UseRowStateCellProps<D> & {};
|
|
183
183
|
|
|
184
|
+
export type MRT_FilterType =
|
|
185
|
+
| 'contains'
|
|
186
|
+
| 'empty'
|
|
187
|
+
| 'endsWith'
|
|
188
|
+
| 'equals'
|
|
189
|
+
| 'fuzzy'
|
|
190
|
+
| 'notEmpty'
|
|
191
|
+
| 'notEquals'
|
|
192
|
+
| 'startsWith';
|
|
193
|
+
|
|
184
194
|
export type MRT_TableState<D extends {} = {}> = TableState<D> &
|
|
185
195
|
UseColumnOrderState<D> &
|
|
186
196
|
UseExpandedState<D> &
|
|
@@ -193,6 +203,7 @@ export type MRT_TableState<D extends {} = {}> = TableState<D> &
|
|
|
193
203
|
UseRowStateState<D> &
|
|
194
204
|
UseSortByState<D> & {
|
|
195
205
|
currentEditingRow: MRT_Row<D> | null;
|
|
206
|
+
currentFilterTypes: { [key: string]: MRT_FilterType };
|
|
196
207
|
densePadding: boolean;
|
|
197
208
|
fullScreen: boolean;
|
|
198
209
|
showFilters: boolean;
|
|
@@ -229,6 +240,7 @@ export type MaterialReactTableProps<D extends {} = {}> = UseTableOptions<D> &
|
|
|
229
240
|
hideToolbarInternalActions?: boolean;
|
|
230
241
|
hideToolbarTop?: boolean;
|
|
231
242
|
icons?: Partial<MRT_Icons>;
|
|
243
|
+
idPrefix?: string;
|
|
232
244
|
isFetching?: boolean;
|
|
233
245
|
isLoading?: boolean;
|
|
234
246
|
localization?: Partial<MRT_Localization>;
|
|
@@ -239,18 +251,22 @@ export type MaterialReactTableProps<D extends {} = {}> = UseTableOptions<D> &
|
|
|
239
251
|
muiTableBodyCellProps?:
|
|
240
252
|
| TableCellProps
|
|
241
253
|
| ((cell?: MRT_Cell<D>) => TableCellProps);
|
|
242
|
-
muiTableBodyProps?:
|
|
254
|
+
muiTableBodyProps?:
|
|
255
|
+
| TableBodyProps
|
|
256
|
+
| ((tableInstance: MRT_TableInstance<D>) => TableBodyProps);
|
|
243
257
|
muiTableBodyRowProps?: TableRowProps | ((row: Row<D>) => TableRowProps);
|
|
244
258
|
muiTableContainerProps?:
|
|
245
259
|
| TableContainerProps
|
|
246
|
-
| ((
|
|
260
|
+
| ((tableInstance: MRT_TableInstance<D>) => TableContainerProps);
|
|
247
261
|
muiTableDetailPanelProps?:
|
|
248
262
|
| TableCellProps
|
|
249
263
|
| ((row: Row<D>) => TableCellProps);
|
|
250
264
|
muiTableFooterCellProps?:
|
|
251
265
|
| TableCellProps
|
|
252
266
|
| ((column: Column<D>) => TableCellProps);
|
|
253
|
-
muiTableFooterProps?:
|
|
267
|
+
muiTableFooterProps?:
|
|
268
|
+
| TableFooterProps
|
|
269
|
+
| ((tableInstance: MRT_TableInstance<D>) => TableFooterProps);
|
|
254
270
|
muiTableFooterRowProps?:
|
|
255
271
|
| TableRowProps
|
|
256
272
|
| ((footerGroup: MRT_HeaderGroup<D>) => TableRowProps);
|
|
@@ -260,7 +276,9 @@ export type MaterialReactTableProps<D extends {} = {}> = UseTableOptions<D> &
|
|
|
260
276
|
muiTableHeadCellProps?:
|
|
261
277
|
| TableCellProps
|
|
262
278
|
| ((column: Column<D>) => TableCellProps);
|
|
263
|
-
muiTableHeadProps?:
|
|
279
|
+
muiTableHeadProps?:
|
|
280
|
+
| TableHeadProps
|
|
281
|
+
| ((tableInstance: MRT_TableInstance<D>) => TableHeadProps);
|
|
264
282
|
muiTableHeadRowProps?:
|
|
265
283
|
| TableRowProps
|
|
266
284
|
| ((row: MRT_HeaderGroup<D>) => TableRowProps);
|
|
@@ -269,7 +287,9 @@ export type MaterialReactTableProps<D extends {} = {}> = UseTableOptions<D> &
|
|
|
269
287
|
| ((
|
|
270
288
|
tableInstance: MRT_TableInstance<D>,
|
|
271
289
|
) => Partial<TablePaginationProps>);
|
|
272
|
-
muiTableProps?:
|
|
290
|
+
muiTableProps?:
|
|
291
|
+
| TableProps
|
|
292
|
+
| ((tableInstance: MRT_TableInstance<D>) => TableProps);
|
|
273
293
|
muiTableToolbarAlertBannerProps?:
|
|
274
294
|
| AlertProps
|
|
275
295
|
| ((tableInstance: MRT_TableInstance<D>) => AlertProps);
|
|
@@ -11,12 +11,17 @@ export const MRT_TableBody: FC<Props> = () => {
|
|
|
11
11
|
|
|
12
12
|
const rows = manualPagination ? tableInstance.rows : tableInstance.page;
|
|
13
13
|
|
|
14
|
+
const mTableBodyProps =
|
|
15
|
+
muiTableBodyProps instanceof Function
|
|
16
|
+
? muiTableBodyProps(tableInstance)
|
|
17
|
+
: muiTableBodyProps;
|
|
18
|
+
|
|
14
19
|
const tableBodyProps = {
|
|
15
|
-
...
|
|
20
|
+
...mTableBodyProps,
|
|
16
21
|
...tableInstance.getTableBodyProps(),
|
|
17
22
|
style: {
|
|
18
23
|
...tableInstance.getTableBodyProps().style,
|
|
19
|
-
...
|
|
24
|
+
...mTableBodyProps?.style,
|
|
20
25
|
},
|
|
21
26
|
};
|
|
22
27
|
|
|
@@ -13,7 +13,9 @@ export const MRT_EditActionButtons: FC<Props> = ({ row }) => {
|
|
|
13
13
|
localization,
|
|
14
14
|
onRowEditSubmit,
|
|
15
15
|
setCurrentEditingRow,
|
|
16
|
-
tableInstance: {
|
|
16
|
+
tableInstance: {
|
|
17
|
+
state: { currentEditingRow },
|
|
18
|
+
},
|
|
17
19
|
} = useMRT();
|
|
18
20
|
|
|
19
21
|
const handleCancel = () => {
|
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
Divider,
|
|
8
8
|
IconButtonProps,
|
|
9
9
|
Box,
|
|
10
|
+
MenuList,
|
|
10
11
|
} from '@mui/material';
|
|
11
12
|
import { useMRT } from '../useMRT';
|
|
12
13
|
import { MRT_ShowHideColumnsMenu } from '../menus/MRT_ShowHideColumnsMenu';
|
|
@@ -16,9 +17,9 @@ interface Props extends IconButtonProps {}
|
|
|
16
17
|
|
|
17
18
|
export const MRT_ShowHideColumnsButton: FC<Props> = ({ ...rest }) => {
|
|
18
19
|
const {
|
|
19
|
-
tableInstance,
|
|
20
|
-
localization,
|
|
21
20
|
icons: { ViewColumnIcon },
|
|
21
|
+
localization,
|
|
22
|
+
tableInstance,
|
|
22
23
|
} = useMRT();
|
|
23
24
|
|
|
24
25
|
const [anchorEl, setAnchorEl] = useState<null | HTMLElement>(null);
|
|
@@ -44,36 +45,38 @@ export const MRT_ShowHideColumnsButton: FC<Props> = ({ ...rest }) => {
|
|
|
44
45
|
open={!!anchorEl}
|
|
45
46
|
onClose={() => setAnchorEl(null)}
|
|
46
47
|
>
|
|
47
|
-
<
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
<Button
|
|
55
|
-
disabled={
|
|
56
|
-
!tableInstance.getToggleHideAllColumnsProps().checked &&
|
|
57
|
-
!tableInstance.getToggleHideAllColumnsProps().indeterminate
|
|
58
|
-
}
|
|
59
|
-
onClick={() => tableInstance.toggleHideAllColumns(true)}
|
|
60
|
-
>
|
|
61
|
-
{localization.columnShowHideMenuHideAll}
|
|
62
|
-
</Button>
|
|
63
|
-
<Button
|
|
64
|
-
disabled={tableInstance.getToggleHideAllColumnsProps().checked}
|
|
65
|
-
onClick={() => tableInstance.toggleHideAllColumns(false)}
|
|
48
|
+
<MenuList dense={tableInstance.state.densePadding} disablePadding>
|
|
49
|
+
<Box
|
|
50
|
+
sx={{
|
|
51
|
+
display: 'flex',
|
|
52
|
+
justifyContent: 'space-between',
|
|
53
|
+
p: '0 0.5rem 0.5rem 0.5rem',
|
|
54
|
+
}}
|
|
66
55
|
>
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
56
|
+
<Button
|
|
57
|
+
disabled={
|
|
58
|
+
!tableInstance.getToggleHideAllColumnsProps().checked &&
|
|
59
|
+
!tableInstance.getToggleHideAllColumnsProps().indeterminate
|
|
60
|
+
}
|
|
61
|
+
onClick={() => tableInstance.toggleHideAllColumns(true)}
|
|
62
|
+
>
|
|
63
|
+
{localization.columnShowHideMenuHideAll}
|
|
64
|
+
</Button>
|
|
65
|
+
<Button
|
|
66
|
+
disabled={tableInstance.getToggleHideAllColumnsProps().checked}
|
|
67
|
+
onClick={() => tableInstance.toggleHideAllColumns(false)}
|
|
68
|
+
>
|
|
69
|
+
{localization.columnShowHideMenuShowAll}
|
|
70
|
+
</Button>
|
|
71
|
+
</Box>
|
|
72
|
+
<Divider />
|
|
73
|
+
{tableInstance.columns.map((column: MRT_ColumnInstance, index) => (
|
|
74
|
+
<MRT_ShowHideColumnsMenu
|
|
75
|
+
key={`${index}-${column.id}`}
|
|
76
|
+
column={column}
|
|
77
|
+
/>
|
|
78
|
+
))}
|
|
79
|
+
</MenuList>
|
|
77
80
|
</Menu>
|
|
78
81
|
</>
|
|
79
82
|
);
|
|
@@ -35,11 +35,12 @@ export const MRT_ToggleColumnActionMenuButton: FC<Props> = ({ column }) => {
|
|
|
35
35
|
onClick={handleClick}
|
|
36
36
|
size="small"
|
|
37
37
|
sx={{
|
|
38
|
+
height: '2rem',
|
|
39
|
+
mr: '2px',
|
|
40
|
+
mt: '-0.2rem',
|
|
38
41
|
opacity: 0.5,
|
|
39
42
|
transition: 'opacity 0.2s',
|
|
40
|
-
|
|
41
|
-
height: '1.6rem',
|
|
42
|
-
width: '1.6rem',
|
|
43
|
+
width: '2rem',
|
|
43
44
|
'&:hover': {
|
|
44
45
|
opacity: 1,
|
|
45
46
|
},
|
|
@@ -9,7 +9,9 @@ export const MRT_ToggleFiltersButton: FC<Props> = ({ ...rest }) => {
|
|
|
9
9
|
icons: { FilterListIcon, FilterListOffIcon },
|
|
10
10
|
localization,
|
|
11
11
|
setShowFilters,
|
|
12
|
-
tableInstance: {
|
|
12
|
+
tableInstance: {
|
|
13
|
+
state: { showFilters },
|
|
14
|
+
},
|
|
13
15
|
} = useMRT();
|
|
14
16
|
|
|
15
17
|
return (
|
|
@@ -7,10 +7,13 @@ interface Props extends IconButtonProps {}
|
|
|
7
7
|
export const MRT_ToggleSearchButton: FC<Props> = ({ ...rest }) => {
|
|
8
8
|
const {
|
|
9
9
|
icons: { SearchIcon, SearchOffIcon },
|
|
10
|
+
idPrefix,
|
|
10
11
|
localization,
|
|
11
12
|
muiSearchTextFieldProps,
|
|
12
13
|
setShowSearch,
|
|
13
|
-
tableInstance: {
|
|
14
|
+
tableInstance: {
|
|
15
|
+
state: { showSearch },
|
|
16
|
+
},
|
|
14
17
|
} = useMRT();
|
|
15
18
|
|
|
16
19
|
const handleToggleSearch = () => {
|
|
@@ -19,7 +22,7 @@ export const MRT_ToggleSearchButton: FC<Props> = ({ ...rest }) => {
|
|
|
19
22
|
() =>
|
|
20
23
|
document
|
|
21
24
|
.getElementById(
|
|
22
|
-
muiSearchTextFieldProps?.id ?? `
|
|
25
|
+
muiSearchTextFieldProps?.id ?? `mrt-${idPrefix}-search-text-field`,
|
|
23
26
|
)
|
|
24
27
|
?.focus(),
|
|
25
28
|
200,
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { matchSorter } from 'match-sorter';
|
|
2
|
+
import { MRT_Row } from '.';
|
|
3
|
+
|
|
4
|
+
export const fuzzyFilterFN = (
|
|
5
|
+
rows: MRT_Row[],
|
|
6
|
+
id: string,
|
|
7
|
+
filterValue: string | number,
|
|
8
|
+
) =>
|
|
9
|
+
matchSorter(rows, filterValue.toString().trim(), {
|
|
10
|
+
keys: [`values.${id}`],
|
|
11
|
+
sorter: (rankedItems) => rankedItems,
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
fuzzyFilterFN.autoRemove = (val: any) => !val;
|
|
15
|
+
|
|
16
|
+
export const containsFilterFN = (
|
|
17
|
+
rows: MRT_Row[],
|
|
18
|
+
id: string,
|
|
19
|
+
filterValue: string | number,
|
|
20
|
+
) =>
|
|
21
|
+
rows.filter((row) =>
|
|
22
|
+
row.values[id]
|
|
23
|
+
.toString()
|
|
24
|
+
.toLowerCase()
|
|
25
|
+
.trim()
|
|
26
|
+
.includes(filterValue.toString().toLowerCase().trim()),
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
containsFilterFN.autoRemove = (val: any) => !val;
|
|
30
|
+
|
|
31
|
+
export const startsWithFilterFN = (
|
|
32
|
+
rows: MRT_Row[],
|
|
33
|
+
id: string,
|
|
34
|
+
filterValue: string | number,
|
|
35
|
+
) =>
|
|
36
|
+
rows.filter((row) =>
|
|
37
|
+
row.values[id]
|
|
38
|
+
.toString()
|
|
39
|
+
.toLowerCase()
|
|
40
|
+
.trim()
|
|
41
|
+
.startsWith(filterValue.toString().toLowerCase().trim()),
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
startsWithFilterFN.autoRemove = (val: any) => !val;
|
|
45
|
+
|
|
46
|
+
export const endsWithFilterFN = (
|
|
47
|
+
rows: MRT_Row[],
|
|
48
|
+
id: string,
|
|
49
|
+
filterValue: string | number,
|
|
50
|
+
) =>
|
|
51
|
+
rows.filter((row) =>
|
|
52
|
+
row.values[id]
|
|
53
|
+
.toString()
|
|
54
|
+
.toLowerCase()
|
|
55
|
+
.trim()
|
|
56
|
+
.endsWith(filterValue.toString().toLowerCase().trim()),
|
|
57
|
+
);
|
|
58
|
+
|
|
59
|
+
endsWithFilterFN.autoRemove = (val: any) => !val;
|
|
60
|
+
|
|
61
|
+
export const equalsFilterFN = (
|
|
62
|
+
rows: MRT_Row[],
|
|
63
|
+
id: string,
|
|
64
|
+
filterValue: string | number,
|
|
65
|
+
) =>
|
|
66
|
+
rows.filter(
|
|
67
|
+
(row) =>
|
|
68
|
+
row.values[id].toString().toLowerCase().trim() ===
|
|
69
|
+
filterValue.toString().toLowerCase().trim(),
|
|
70
|
+
);
|
|
71
|
+
|
|
72
|
+
equalsFilterFN.autoRemove = (val: any) => !val;
|
|
73
|
+
|
|
74
|
+
export const notEqualsFilterFN = (
|
|
75
|
+
rows: MRT_Row[],
|
|
76
|
+
id: string,
|
|
77
|
+
filterValue: string | number,
|
|
78
|
+
) =>
|
|
79
|
+
rows.filter(
|
|
80
|
+
(row) =>
|
|
81
|
+
row.values[id].toString().toLowerCase().trim() !==
|
|
82
|
+
filterValue.toString().toLowerCase().trim(),
|
|
83
|
+
);
|
|
84
|
+
|
|
85
|
+
notEqualsFilterFN.autoRemove = (val: any) => !val;
|
|
86
|
+
|
|
87
|
+
export const emptyFilterFN = (
|
|
88
|
+
rows: MRT_Row[],
|
|
89
|
+
id: string,
|
|
90
|
+
_filterValue: string | number,
|
|
91
|
+
) => rows.filter((row) => !row.values[id].toString().toLowerCase().trim());
|
|
92
|
+
|
|
93
|
+
emptyFilterFN.autoRemove = (val: any) => !val;
|
|
94
|
+
|
|
95
|
+
export const notEmptyFilterFN = (
|
|
96
|
+
rows: MRT_Row[],
|
|
97
|
+
id: string,
|
|
98
|
+
_filterValue: string | number,
|
|
99
|
+
) => rows.filter((row) => !!row.values[id].toString().toLowerCase().trim());
|
|
100
|
+
|
|
101
|
+
notEmptyFilterFN.autoRemove = (val: any) => !val;
|
|
102
|
+
|
|
103
|
+
export const defaultFilterFNs = {
|
|
104
|
+
contains: containsFilterFN,
|
|
105
|
+
empty: emptyFilterFN,
|
|
106
|
+
endsWith: endsWithFilterFN,
|
|
107
|
+
equals: equalsFilterFN,
|
|
108
|
+
fuzzy: fuzzyFilterFN,
|
|
109
|
+
notEmpty: notEmptyFilterFN,
|
|
110
|
+
notEquals: notEqualsFilterFN,
|
|
111
|
+
startsWith: startsWithFilterFN,
|
|
112
|
+
};
|
|
@@ -9,8 +9,13 @@ interface Props {}
|
|
|
9
9
|
export const MRT_TableFooter: FC<Props> = () => {
|
|
10
10
|
const { muiTableFooterProps, tableInstance } = useMRT();
|
|
11
11
|
|
|
12
|
+
const tableFooterProps =
|
|
13
|
+
muiTableFooterProps instanceof Function
|
|
14
|
+
? muiTableFooterProps(tableInstance)
|
|
15
|
+
: muiTableFooterProps;
|
|
16
|
+
|
|
12
17
|
return (
|
|
13
|
-
<TableFooter {...
|
|
18
|
+
<TableFooter {...tableFooterProps}>
|
|
14
19
|
{tableInstance.footerGroups.map((footerGroup: MRT_HeaderGroup) => (
|
|
15
20
|
<MRT_TableFooterRow
|
|
16
21
|
key={footerGroup.getFooterGroupProps().key}
|
|
@@ -16,7 +16,7 @@ export const MRT_TableFooterCell: FC<Props> = ({ column }) => {
|
|
|
16
16
|
},
|
|
17
17
|
} = useMRT();
|
|
18
18
|
|
|
19
|
-
const isParentHeader =
|
|
19
|
+
const isParentHeader = !!column?.columns?.length;
|
|
20
20
|
|
|
21
21
|
const mTableFooterCellProps =
|
|
22
22
|
muiTableFooterCellProps instanceof Function
|
|
@@ -6,6 +6,7 @@ import {
|
|
|
6
6
|
Collapse,
|
|
7
7
|
Tooltip,
|
|
8
8
|
Box,
|
|
9
|
+
IconButton,
|
|
9
10
|
} from '@mui/material';
|
|
10
11
|
import { useMRT } from '../useMRT';
|
|
11
12
|
import { MRT_FilterTextField } from '../inputs/MRT_FilterTextField';
|
|
@@ -33,12 +34,14 @@ export const MRT_TableHeadCell: FC<Props> = ({ column }) => {
|
|
|
33
34
|
disableColumnActions,
|
|
34
35
|
disableFilters,
|
|
35
36
|
enableColumnResizing,
|
|
37
|
+
icons: { FilterAltIcon, FilterAltOff },
|
|
36
38
|
localization,
|
|
37
39
|
muiTableHeadCellProps,
|
|
40
|
+
setShowFilters,
|
|
38
41
|
tableInstance,
|
|
39
42
|
} = useMRT();
|
|
40
43
|
|
|
41
|
-
const isParentHeader =
|
|
44
|
+
const isParentHeader = !!column?.columns?.length;
|
|
42
45
|
|
|
43
46
|
const mTableHeadCellProps =
|
|
44
47
|
muiTableHeadCellProps instanceof Function
|
|
@@ -73,6 +76,25 @@ export const MRT_TableHeadCell: FC<Props> = ({ column }) => {
|
|
|
73
76
|
column.Header as string,
|
|
74
77
|
);
|
|
75
78
|
|
|
79
|
+
const filterTooltip = !!column.filterValue
|
|
80
|
+
? localization.filterApplied
|
|
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
|
+
)
|
|
94
|
+
: localization.toggleFilterButtonTitle;
|
|
95
|
+
|
|
96
|
+
const columnHeader = column.render('Header') as string;
|
|
97
|
+
|
|
76
98
|
return (
|
|
77
99
|
<TableCell
|
|
78
100
|
align={isParentHeader ? 'center' : 'left'}
|
|
@@ -86,59 +108,84 @@ export const MRT_TableHeadCell: FC<Props> = ({ column }) => {
|
|
|
86
108
|
}}
|
|
87
109
|
>
|
|
88
110
|
<Box
|
|
89
|
-
sx={{
|
|
111
|
+
sx={{
|
|
112
|
+
alignItems: 'flex-start',
|
|
113
|
+
display: 'flex',
|
|
114
|
+
justifyContent: isParentHeader ? 'center' : 'space-between',
|
|
115
|
+
width: '100%',
|
|
116
|
+
}}
|
|
90
117
|
>
|
|
91
118
|
<Box
|
|
119
|
+
{...column.getSortByToggleProps()}
|
|
92
120
|
sx={{
|
|
93
|
-
alignItems: '
|
|
121
|
+
alignItems: 'center',
|
|
94
122
|
display: 'flex',
|
|
95
|
-
|
|
96
|
-
|
|
123
|
+
flexWrap: 'nowrap',
|
|
124
|
+
whiteSpace: columnHeader.length < 15 ? 'nowrap' : 'normal',
|
|
97
125
|
}}
|
|
126
|
+
title={undefined}
|
|
98
127
|
>
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
>
|
|
118
|
-
{!disableColumnActions && !isParentHeader && (
|
|
119
|
-
<MRT_ToggleColumnActionMenuButton column={column} />
|
|
120
|
-
)}
|
|
121
|
-
{enableColumnResizing && !isParentHeader && (
|
|
122
|
-
<Divider
|
|
123
|
-
flexItem
|
|
124
|
-
orientation="vertical"
|
|
125
|
-
onDoubleClick={() => tableInstance.resetResizing()}
|
|
126
|
-
{...column.getResizerProps()}
|
|
128
|
+
{column.render('Header')}
|
|
129
|
+
{!isParentHeader && column.canSort && (
|
|
130
|
+
<Tooltip arrow title={sortTooltip}>
|
|
131
|
+
<TableSortLabel
|
|
132
|
+
aria-label={sortTooltip}
|
|
133
|
+
active={column.isSorted}
|
|
134
|
+
direction={column.isSortedDesc ? 'desc' : 'asc'}
|
|
135
|
+
/>
|
|
136
|
+
</Tooltip>
|
|
137
|
+
)}
|
|
138
|
+
{!isParentHeader && !!column.canFilter && (
|
|
139
|
+
<Tooltip arrow title={filterTooltip}>
|
|
140
|
+
<IconButton
|
|
141
|
+
onClick={(event) => {
|
|
142
|
+
event.stopPropagation();
|
|
143
|
+
setShowFilters(!tableInstance.state.showFilters);
|
|
144
|
+
}}
|
|
145
|
+
size="small"
|
|
127
146
|
sx={{
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
147
|
+
opacity: !!column.filterValue ? 0.8 : 0,
|
|
148
|
+
p: '2px',
|
|
149
|
+
m: 0,
|
|
150
|
+
transition: 'all 0.2s ease-in-out',
|
|
151
|
+
'&:hover': {
|
|
152
|
+
opacity: 0.8,
|
|
153
|
+
},
|
|
131
154
|
}}
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
155
|
+
>
|
|
156
|
+
{tableInstance.state.showFilters && !column.filterValue ? (
|
|
157
|
+
<FilterAltOff fontSize="small" />
|
|
158
|
+
) : (
|
|
159
|
+
<FilterAltIcon fontSize="small" />
|
|
160
|
+
)}
|
|
161
|
+
</IconButton>
|
|
162
|
+
</Tooltip>
|
|
163
|
+
)}
|
|
164
|
+
</Box>
|
|
165
|
+
<Box sx={{ alignItems: 'center', display: 'flex', flexWrap: 'nowrap' }}>
|
|
166
|
+
{!disableColumnActions && !isParentHeader && (
|
|
167
|
+
<MRT_ToggleColumnActionMenuButton column={column} />
|
|
168
|
+
)}
|
|
169
|
+
{enableColumnResizing && !isParentHeader && (
|
|
170
|
+
<Divider
|
|
171
|
+
flexItem
|
|
172
|
+
orientation="vertical"
|
|
173
|
+
onDoubleClick={() => tableInstance.resetResizing()}
|
|
174
|
+
{...column.getResizerProps()}
|
|
175
|
+
sx={{
|
|
176
|
+
borderRightWidth: '2px',
|
|
177
|
+
borderRadius: '2px',
|
|
178
|
+
maxHeight: '2rem',
|
|
179
|
+
}}
|
|
180
|
+
/>
|
|
181
|
+
)}
|
|
135
182
|
</Box>
|
|
136
|
-
{!disableFilters && column.canFilter && (
|
|
137
|
-
<Collapse in={tableInstance.state.showFilters}>
|
|
138
|
-
<MRT_FilterTextField column={column} />
|
|
139
|
-
</Collapse>
|
|
140
|
-
)}
|
|
141
183
|
</Box>
|
|
184
|
+
{!disableFilters && column.canFilter && (
|
|
185
|
+
<Collapse in={tableInstance.state.showFilters}>
|
|
186
|
+
<MRT_FilterTextField column={column} />
|
|
187
|
+
</Collapse>
|
|
188
|
+
)}
|
|
142
189
|
</TableCell>
|
|
143
190
|
);
|
|
144
191
|
};
|