material-react-table 1.0.0-beta.12 → 1.0.0-beta.13
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/cjs/MaterialReactTable.d.ts +11 -2
- package/dist/cjs/index.js +50 -9
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/inputs/MRT_FilterCheckbox.d.ts +8 -0
- package/dist/cjs/table/MRT_TableRoot.d.ts +4 -0
- package/dist/esm/MaterialReactTable.d.ts +11 -2
- package/dist/esm/inputs/MRT_FilterCheckbox.d.ts +8 -0
- package/dist/esm/material-react-table.esm.js +50 -9
- package/dist/esm/material-react-table.esm.js.map +1 -1
- package/dist/esm/table/MRT_TableRoot.d.ts +4 -0
- package/dist/index.d.ts +12 -3
- package/package.json +1 -1
- package/src/MaterialReactTable.tsx +21 -1
- package/src/column.utils.ts +5 -1
- package/src/head/MRT_TableHeadCellFilterContainer.tsx +7 -3
- package/src/inputs/MRT_FilterCheckbox.tsx +96 -0
- package/src/inputs/MRT_FilterTextField.tsx +13 -10
|
@@ -130,6 +130,10 @@ export declare const MRT_TableRoot: <TData extends Record<string, any> = {}>(pro
|
|
|
130
130
|
table: MRT_TableInstance<TData>;
|
|
131
131
|
column: MRT_Column<TData>;
|
|
132
132
|
}) => import("@mui/material").IconButtonProps<"button", {}>) | undefined;
|
|
133
|
+
muiTableHeadCellFilterCheckboxProps?: import("@mui/material").CheckboxProps | (({ column, table, }: {
|
|
134
|
+
column: MRT_Column<TData>;
|
|
135
|
+
table: MRT_TableInstance<TData>;
|
|
136
|
+
}) => import("@mui/material").CheckboxProps) | undefined;
|
|
133
137
|
muiTableHeadCellFilterTextFieldProps?: import("@mui/material").TextFieldProps | (({ table, column, rangeFilterIndex, }: {
|
|
134
138
|
table: MRT_TableInstance<TData>;
|
|
135
139
|
column: MRT_Column<TData>;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { MutableRefObject, Dispatch, SetStateAction, ReactNode } from 'react';
|
|
2
|
-
import { ButtonProps, TextFieldProps, TableCellProps, IconButtonProps, ToolbarProps, LinearProgressProps,
|
|
2
|
+
import { ButtonProps, TextFieldProps, TableCellProps, IconButtonProps, CheckboxProps, ToolbarProps, LinearProgressProps, SkeletonProps, TableBodyProps, TableRowProps, TableContainerProps, TableFooterProps, TableHeadProps, TablePaginationProps, PaperProps, TableProps, ChipProps, AlertProps } from '@mui/material';
|
|
3
3
|
import { Row, Table, TableState, ColumnDef, DeepKeys, Column, Header, HeaderGroup, Cell, SortingFn, FilterFn, TableOptions, OnChangeFn } from '@tanstack/react-table';
|
|
4
4
|
import { Options, VirtualItem } from 'react-virtual';
|
|
5
5
|
import * as _tanstack_table_core from '@tanstack/table-core';
|
|
@@ -296,9 +296,10 @@ declare type MRT_ColumnDef<TData extends Record<string, any> = {}> = Omit<Column
|
|
|
296
296
|
row: MRT_Row<TData>;
|
|
297
297
|
table: MRT_TableInstance<TData>;
|
|
298
298
|
}) => ReactNode;
|
|
299
|
-
Filter?: ({ column, header, table, }: {
|
|
299
|
+
Filter?: ({ column, header, rangeFilterIndex, table, }: {
|
|
300
300
|
column: MRT_Column<TData>;
|
|
301
301
|
header: MRT_Header<TData>;
|
|
302
|
+
rangeFilterIndex?: number;
|
|
302
303
|
table: MRT_TableInstance<TData>;
|
|
303
304
|
}) => ReactNode;
|
|
304
305
|
Footer?: ReactNode | (({ column, footer, table, }: {
|
|
@@ -355,7 +356,7 @@ declare type MRT_ColumnDef<TData extends Record<string, any> = {}> = Omit<Column
|
|
|
355
356
|
text: string;
|
|
356
357
|
value: any;
|
|
357
358
|
})[];
|
|
358
|
-
filterVariant?: 'text' | 'select' | 'multi-select' | 'range';
|
|
359
|
+
filterVariant?: 'text' | 'select' | 'multi-select' | 'range' | 'checkbox';
|
|
359
360
|
/**
|
|
360
361
|
* footer must be a string. If you want custom JSX to render the footer, you can also specify a `Footer` option. (Capital F)
|
|
361
362
|
*/
|
|
@@ -404,6 +405,10 @@ declare type MRT_ColumnDef<TData extends Record<string, any> = {}> = Omit<Column
|
|
|
404
405
|
table: MRT_TableInstance<TData>;
|
|
405
406
|
column: MRT_Column<TData>;
|
|
406
407
|
}) => IconButtonProps);
|
|
408
|
+
muiTableHeadCellFilterCheckboxProps?: CheckboxProps | (({ column, table, }: {
|
|
409
|
+
column: MRT_Column<TData>;
|
|
410
|
+
table: MRT_TableInstance<TData>;
|
|
411
|
+
}) => CheckboxProps);
|
|
407
412
|
muiTableHeadCellFilterTextFieldProps?: TextFieldProps | (({ table, column, rangeFilterIndex, }: {
|
|
408
413
|
table: MRT_TableInstance<TData>;
|
|
409
414
|
column: MRT_Column<TData>;
|
|
@@ -600,6 +605,10 @@ declare type MaterialReactTableProps<TData extends Record<string, any> = {}> = O
|
|
|
600
605
|
table: MRT_TableInstance<TData>;
|
|
601
606
|
column: MRT_Column<TData>;
|
|
602
607
|
}) => IconButtonProps);
|
|
608
|
+
muiTableHeadCellFilterCheckboxProps?: CheckboxProps | (({ column, table, }: {
|
|
609
|
+
column: MRT_Column<TData>;
|
|
610
|
+
table: MRT_TableInstance<TData>;
|
|
611
|
+
}) => CheckboxProps);
|
|
603
612
|
muiTableHeadCellFilterTextFieldProps?: TextFieldProps | (({ table, column, rangeFilterIndex, }: {
|
|
604
613
|
table: MRT_TableInstance<TData>;
|
|
605
614
|
column: MRT_Column<TData>;
|
package/package.json
CHANGED
|
@@ -275,10 +275,12 @@ export type MRT_ColumnDef<TData extends Record<string, any> = {}> = Omit<
|
|
|
275
275
|
Filter?: ({
|
|
276
276
|
column,
|
|
277
277
|
header,
|
|
278
|
+
rangeFilterIndex,
|
|
278
279
|
table,
|
|
279
280
|
}: {
|
|
280
281
|
column: MRT_Column<TData>;
|
|
281
282
|
header: MRT_Header<TData>;
|
|
283
|
+
rangeFilterIndex?: number;
|
|
282
284
|
table: MRT_TableInstance<TData>;
|
|
283
285
|
}) => ReactNode;
|
|
284
286
|
Footer?:
|
|
@@ -349,7 +351,7 @@ export type MRT_ColumnDef<TData extends Record<string, any> = {}> = Omit<
|
|
|
349
351
|
enableEditing?: boolean;
|
|
350
352
|
filterFn?: MRT_FilterFn<TData>;
|
|
351
353
|
filterSelectOptions?: (string | { text: string; value: any })[];
|
|
352
|
-
filterVariant?: 'text' | 'select' | 'multi-select' | 'range';
|
|
354
|
+
filterVariant?: 'text' | 'select' | 'multi-select' | 'range' | 'checkbox';
|
|
353
355
|
/**
|
|
354
356
|
* footer must be a string. If you want custom JSX to render the footer, you can also specify a `Footer` option. (Capital F)
|
|
355
357
|
*/
|
|
@@ -434,6 +436,15 @@ export type MRT_ColumnDef<TData extends Record<string, any> = {}> = Omit<
|
|
|
434
436
|
table: MRT_TableInstance<TData>;
|
|
435
437
|
column: MRT_Column<TData>;
|
|
436
438
|
}) => IconButtonProps);
|
|
439
|
+
muiTableHeadCellFilterCheckboxProps?:
|
|
440
|
+
| CheckboxProps
|
|
441
|
+
| (({
|
|
442
|
+
column,
|
|
443
|
+
table,
|
|
444
|
+
}: {
|
|
445
|
+
column: MRT_Column<TData>;
|
|
446
|
+
table: MRT_TableInstance<TData>;
|
|
447
|
+
}) => CheckboxProps);
|
|
437
448
|
muiTableHeadCellFilterTextFieldProps?:
|
|
438
449
|
| TextFieldProps
|
|
439
450
|
| (({
|
|
@@ -787,6 +798,15 @@ export type MaterialReactTableProps<TData extends Record<string, any> = {}> =
|
|
|
787
798
|
table: MRT_TableInstance<TData>;
|
|
788
799
|
column: MRT_Column<TData>;
|
|
789
800
|
}) => IconButtonProps);
|
|
801
|
+
muiTableHeadCellFilterCheckboxProps?:
|
|
802
|
+
| CheckboxProps
|
|
803
|
+
| (({
|
|
804
|
+
column,
|
|
805
|
+
table,
|
|
806
|
+
}: {
|
|
807
|
+
column: MRT_Column<TData>;
|
|
808
|
+
table: MRT_TableInstance<TData>;
|
|
809
|
+
}) => CheckboxProps);
|
|
790
810
|
muiTableHeadCellFilterTextFieldProps?:
|
|
791
811
|
| TextFieldProps
|
|
792
812
|
| (({
|
package/src/column.utils.ts
CHANGED
|
@@ -164,8 +164,12 @@ export const getDefaultColumnFilterFn = <
|
|
|
164
164
|
columnDef: MRT_ColumnDef<TData>,
|
|
165
165
|
): MRT_FilterOption => {
|
|
166
166
|
if (columnDef.filterVariant === 'multi-select') return 'arrIncludesSome';
|
|
167
|
-
if (columnDef.filterVariant === 'select') return 'equals';
|
|
168
167
|
if (columnDef.filterVariant === 'range') return 'betweenInclusive';
|
|
168
|
+
if (
|
|
169
|
+
columnDef.filterVariant === 'select' ||
|
|
170
|
+
columnDef.filterVariant === 'checkbox'
|
|
171
|
+
)
|
|
172
|
+
return 'equals';
|
|
169
173
|
return 'fuzzy';
|
|
170
174
|
};
|
|
171
175
|
|
|
@@ -3,6 +3,7 @@ import { Collapse } from '@mui/material';
|
|
|
3
3
|
import { MRT_FilterRangeFields } from '../inputs/MRT_FilterRangeFields';
|
|
4
4
|
import { MRT_FilterTextField } from '../inputs/MRT_FilterTextField';
|
|
5
5
|
import { MRT_Header, MRT_TableInstance } from '..';
|
|
6
|
+
import { MRT_FilterCheckbox } from '../inputs/MRT_FilterCheckbox';
|
|
6
7
|
|
|
7
8
|
interface Props {
|
|
8
9
|
header: MRT_Header;
|
|
@@ -20,9 +21,12 @@ export const MRT_TableHeadCellFilterContainer: FC<Props> = ({
|
|
|
20
21
|
|
|
21
22
|
return (
|
|
22
23
|
<Collapse in={showColumnFilters} mountOnEnter unmountOnExit>
|
|
23
|
-
{
|
|
24
|
-
|
|
25
|
-
)
|
|
24
|
+
{columnDef.filterVariant === 'checkbox' ? (
|
|
25
|
+
<MRT_FilterCheckbox column={column} table={table} />
|
|
26
|
+
) : columnDef.filterVariant === 'range' ||
|
|
27
|
+
['between', 'betweenInclusive', 'inNumberRange'].includes(
|
|
28
|
+
columnDef._filterFn,
|
|
29
|
+
) ? (
|
|
26
30
|
<MRT_FilterRangeFields header={header} table={table} />
|
|
27
31
|
) : (
|
|
28
32
|
<MRT_FilterTextField header={header} table={table} />
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import React, { FC } from 'react';
|
|
2
|
+
import {
|
|
3
|
+
Checkbox,
|
|
4
|
+
CheckboxProps,
|
|
5
|
+
FormControlLabel,
|
|
6
|
+
Tooltip,
|
|
7
|
+
} from '@mui/material';
|
|
8
|
+
import type { MRT_Column, MRT_TableInstance } from '..';
|
|
9
|
+
|
|
10
|
+
interface Props {
|
|
11
|
+
column: MRT_Column;
|
|
12
|
+
table: MRT_TableInstance;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export const MRT_FilterCheckbox: FC<Props> = ({ column, table }) => {
|
|
16
|
+
const {
|
|
17
|
+
getState,
|
|
18
|
+
options: { localization, muiTableHeadCellFilterCheckboxProps },
|
|
19
|
+
} = table;
|
|
20
|
+
const { density } = getState();
|
|
21
|
+
const { columnDef } = column;
|
|
22
|
+
|
|
23
|
+
const mTableHeadCellFilterCheckboxProps =
|
|
24
|
+
muiTableHeadCellFilterCheckboxProps instanceof Function
|
|
25
|
+
? muiTableHeadCellFilterCheckboxProps({
|
|
26
|
+
column,
|
|
27
|
+
table,
|
|
28
|
+
})
|
|
29
|
+
: muiTableHeadCellFilterCheckboxProps;
|
|
30
|
+
|
|
31
|
+
const mcTableHeadCellFilterCheckboxProps =
|
|
32
|
+
columnDef.muiTableHeadCellFilterCheckboxProps instanceof Function
|
|
33
|
+
? columnDef.muiTableHeadCellFilterCheckboxProps({
|
|
34
|
+
column,
|
|
35
|
+
table,
|
|
36
|
+
})
|
|
37
|
+
: columnDef.muiTableHeadCellFilterCheckboxProps;
|
|
38
|
+
|
|
39
|
+
const checkboxProps = {
|
|
40
|
+
...mTableHeadCellFilterCheckboxProps,
|
|
41
|
+
...mcTableHeadCellFilterCheckboxProps,
|
|
42
|
+
} as CheckboxProps;
|
|
43
|
+
|
|
44
|
+
const filterLabel = localization.filterByColumn?.replace(
|
|
45
|
+
'{column}',
|
|
46
|
+
columnDef.header,
|
|
47
|
+
);
|
|
48
|
+
|
|
49
|
+
return (
|
|
50
|
+
<Tooltip
|
|
51
|
+
arrow
|
|
52
|
+
enterDelay={1000}
|
|
53
|
+
enterNextDelay={1000}
|
|
54
|
+
title={checkboxProps?.title ?? filterLabel}
|
|
55
|
+
>
|
|
56
|
+
<FormControlLabel
|
|
57
|
+
control={
|
|
58
|
+
<Checkbox
|
|
59
|
+
checked={column.getFilterValue() === 'true'}
|
|
60
|
+
indeterminate={column.getFilterValue() === undefined}
|
|
61
|
+
color={
|
|
62
|
+
column.getFilterValue() === undefined ? 'default' : 'primary'
|
|
63
|
+
}
|
|
64
|
+
size={density === 'compact' ? 'small' : 'medium'}
|
|
65
|
+
{...checkboxProps}
|
|
66
|
+
onClick={(e) => {
|
|
67
|
+
e.stopPropagation();
|
|
68
|
+
checkboxProps?.onClick?.(e);
|
|
69
|
+
}}
|
|
70
|
+
onChange={(e, checked) => {
|
|
71
|
+
column.setFilterValue(
|
|
72
|
+
column.getFilterValue() === undefined
|
|
73
|
+
? 'true'
|
|
74
|
+
: column.getFilterValue() === 'true'
|
|
75
|
+
? 'false'
|
|
76
|
+
: undefined,
|
|
77
|
+
);
|
|
78
|
+
checkboxProps?.onChange?.(e, checked);
|
|
79
|
+
}}
|
|
80
|
+
sx={(theme) => ({
|
|
81
|
+
height: '2.5rem',
|
|
82
|
+
width: '2.5rem',
|
|
83
|
+
...(checkboxProps?.sx instanceof Function
|
|
84
|
+
? checkboxProps.sx(theme)
|
|
85
|
+
: (checkboxProps?.sx as any)),
|
|
86
|
+
})}
|
|
87
|
+
/>
|
|
88
|
+
}
|
|
89
|
+
disableTypography
|
|
90
|
+
label={checkboxProps.title ?? filterLabel}
|
|
91
|
+
sx={{ color: 'text.secondary', mt: '-4px', fontWeight: 'normal' }}
|
|
92
|
+
title={undefined}
|
|
93
|
+
/>
|
|
94
|
+
</Tooltip>
|
|
95
|
+
);
|
|
96
|
+
};
|
|
@@ -118,10 +118,12 @@ export const MRT_FilterTextField: FC<Props> = ({
|
|
|
118
118
|
(event: ChangeEvent<HTMLInputElement>) => {
|
|
119
119
|
let value =
|
|
120
120
|
textFieldProps.type === 'date'
|
|
121
|
-
?
|
|
121
|
+
? event.target.valueAsDate
|
|
122
|
+
: textFieldProps.type === 'number'
|
|
123
|
+
? event.target.valueAsNumber
|
|
122
124
|
: event.target.value;
|
|
123
125
|
if (isRangeFilter) {
|
|
124
|
-
column.setFilterValue((old:
|
|
126
|
+
column.setFilterValue((old: Array<string | Date | number | null>) => {
|
|
125
127
|
const newFilterValues = old ?? ['', ''];
|
|
126
128
|
newFilterValues[rangeFilterIndex as number] = value;
|
|
127
129
|
return newFilterValues;
|
|
@@ -177,7 +179,9 @@ export const MRT_FilterTextField: FC<Props> = ({
|
|
|
177
179
|
}, [column.getFilterValue()]);
|
|
178
180
|
|
|
179
181
|
if (columnDef.Filter) {
|
|
180
|
-
return
|
|
182
|
+
return (
|
|
183
|
+
<>{columnDef.Filter?.({ column, header, rangeFilterIndex, table })}</>
|
|
184
|
+
);
|
|
181
185
|
}
|
|
182
186
|
|
|
183
187
|
return (
|
|
@@ -210,7 +214,7 @@ export const MRT_FilterTextField: FC<Props> = ({
|
|
|
210
214
|
}
|
|
211
215
|
FormHelperTextProps={{
|
|
212
216
|
sx: {
|
|
213
|
-
fontSize: '0.
|
|
217
|
+
fontSize: '0.75rem',
|
|
214
218
|
lineHeight: '0.8rem',
|
|
215
219
|
whiteSpace: 'nowrap',
|
|
216
220
|
},
|
|
@@ -315,12 +319,11 @@ export const MRT_FilterTextField: FC<Props> = ({
|
|
|
315
319
|
}}
|
|
316
320
|
sx={(theme) => ({
|
|
317
321
|
p: 0,
|
|
318
|
-
minWidth:
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
: 'auto',
|
|
322
|
+
minWidth: isRangeFilter
|
|
323
|
+
? '100px'
|
|
324
|
+
: !filterChipLabel
|
|
325
|
+
? '120px'
|
|
326
|
+
: 'auto',
|
|
324
327
|
width: '100%',
|
|
325
328
|
'& .MuiSelect-icon': {
|
|
326
329
|
mr: '1.5rem',
|