material-react-table 1.9.0 → 1.9.1
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/index.js +45 -14
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/types/body/MRT_TableBody.d.ts +1 -1
- package/dist/cjs/types/column.utils.d.ts +1 -1
- package/dist/cjs/types/filterFns.d.ts +1 -1
- package/dist/cjs/types/footer/MRT_TableFooterRow.d.ts +1 -1
- package/dist/cjs/types/sortingFns.d.ts +2 -2
- package/dist/esm/material-react-table.esm.js +45 -14
- package/dist/esm/material-react-table.esm.js.map +1 -1
- package/dist/esm/types/body/MRT_TableBody.d.ts +1 -1
- package/dist/esm/types/column.utils.d.ts +1 -1
- package/dist/esm/types/filterFns.d.ts +1 -1
- package/dist/esm/types/footer/MRT_TableFooterRow.d.ts +1 -1
- package/dist/esm/types/sortingFns.d.ts +2 -2
- package/package.json +1 -1
- package/src/MaterialReactTable.tsx +1 -1
- package/src/body/MRT_TableBody.tsx +2 -2
- package/src/body/MRT_TableBodyRow.tsx +4 -2
- package/src/column.utils.ts +1 -1
- package/src/filterFns.ts +1 -1
- package/src/footer/MRT_TableFooterRow.tsx +1 -1
- package/src/inputs/MRT_FilterTextField.tsx +1 -1
- package/src/menus/MRT_FilterOptionMenu.tsx +39 -15
- package/src/sortingFns.ts +3 -3
- package/src/table/MRT_Table.tsx +2 -2
- package/src/table/MRT_TableRoot.tsx +1 -1
@@ -1,5 +1,5 @@
|
|
1
1
|
import React from 'react';
|
2
|
-
import { VirtualItem, Virtualizer } from '@tanstack/react-virtual';
|
2
|
+
import { type VirtualItem, type Virtualizer } from '@tanstack/react-virtual';
|
3
3
|
import type { MRT_TableInstance } from '..';
|
4
4
|
interface Props {
|
5
5
|
columnVirtualizer?: Virtualizer<HTMLDivElement, HTMLTableCellElement>;
|
@@ -1,7 +1,7 @@
|
|
1
|
-
import type { Row } from '@tanstack/react-table';
|
2
1
|
import { MRT_AggregationFns } from './aggregationFns';
|
3
2
|
import { MRT_FilterFns } from './filterFns';
|
4
3
|
import { MRT_SortingFns } from './sortingFns';
|
4
|
+
import type { Row } from '@tanstack/react-table';
|
5
5
|
import type { TableCellProps } from '@mui/material/TableCell';
|
6
6
|
import type { Theme } from '@mui/material/styles';
|
7
7
|
import type { MaterialReactTableProps, MRT_Column, MRT_ColumnDef, MRT_ColumnOrderState, MRT_DefinedColumnDef, MRT_DisplayColumnIds, MRT_FilterOption, MRT_GroupingState, MRT_Header, MRT_TableInstance } from '.';
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import { RankingInfo } from '@tanstack/match-sorter-utils';
|
2
|
-
import { Row } from '@tanstack/react-table';
|
2
|
+
import { type Row } from '@tanstack/react-table';
|
3
3
|
export declare const MRT_FilterFns: {
|
4
4
|
between: {
|
5
5
|
<TData extends Record<string, any> = {}>(row: Row<TData>, id: string, filterValues: [string | number, string | number]): boolean;
|
@@ -1,5 +1,5 @@
|
|
1
|
-
import { Row } from '@tanstack/react-table';
|
2
|
-
import { MRT_Row } from '.';
|
1
|
+
import { type Row } from '@tanstack/react-table';
|
2
|
+
import type { MRT_Row } from '.';
|
3
3
|
export declare const MRT_SortingFns: {
|
4
4
|
fuzzy: <TData extends Record<string, any> = {}>(rowA: Row<TData>, rowB: Row<TData>, columnId: string) => number;
|
5
5
|
alphanumeric: import("@tanstack/react-table").SortingFn<any>;
|
package/package.json
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
import React, { memo, useMemo } from 'react';
|
2
2
|
import {
|
3
3
|
useVirtualizer,
|
4
|
-
VirtualItem,
|
5
|
-
Virtualizer,
|
4
|
+
type VirtualItem,
|
5
|
+
type Virtualizer,
|
6
6
|
} from '@tanstack/react-virtual';
|
7
7
|
import TableBody from '@mui/material/TableBody';
|
8
8
|
import Typography from '@mui/material/Typography';
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import React, { DragEvent, memo, useRef } from 'react';
|
2
2
|
import TableRow from '@mui/material/TableRow';
|
3
|
-
import { darken, lighten } from '@mui/material/styles';
|
3
|
+
import { alpha, darken, lighten } from '@mui/material/styles';
|
4
4
|
import { Memo_MRT_TableBodyCell, MRT_TableBodyCell } from './MRT_TableBodyCell';
|
5
5
|
import { MRT_TableDetailPanel } from './MRT_TableDetailPanel';
|
6
6
|
import type { VirtualItem, Virtualizer } from '@tanstack/react-virtual';
|
@@ -86,7 +86,9 @@ export const MRT_TableBodyRow = ({
|
|
86
86
|
'&:hover td': {
|
87
87
|
backgroundColor:
|
88
88
|
tableRowProps?.hover !== false
|
89
|
-
?
|
89
|
+
? row.getIsSelected()
|
90
|
+
? `${alpha(theme.palette.primary.main, 0.2)}`
|
91
|
+
: theme.palette.mode === 'dark'
|
90
92
|
? `${lighten(theme.palette.background.default, 0.12)}`
|
91
93
|
: `${darken(theme.palette.background.default, 0.05)}`
|
92
94
|
: undefined,
|
package/src/column.utils.ts
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
import type { Row } from '@tanstack/react-table';
|
2
1
|
import { MRT_AggregationFns } from './aggregationFns';
|
3
2
|
import { MRT_FilterFns } from './filterFns';
|
4
3
|
import { MRT_SortingFns } from './sortingFns';
|
5
4
|
import { alpha, lighten } from '@mui/material/styles';
|
5
|
+
import type { Row } from '@tanstack/react-table';
|
6
6
|
import type { TableCellProps } from '@mui/material/TableCell';
|
7
7
|
import type { Theme } from '@mui/material/styles';
|
8
8
|
import type {
|
package/src/filterFns.ts
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
import { rankItem, rankings, RankingInfo } from '@tanstack/match-sorter-utils';
|
2
|
-
import { filterFns, Row } from '@tanstack/react-table';
|
2
|
+
import { filterFns, type Row } from '@tanstack/react-table';
|
3
3
|
|
4
4
|
const fuzzy = <TData extends Record<string, any> = {}>(
|
5
5
|
row: Row<TData>,
|
@@ -2,7 +2,7 @@ import React from 'react';
|
|
2
2
|
import TableRow from '@mui/material/TableRow';
|
3
3
|
import { lighten } from '@mui/material/styles';
|
4
4
|
import { MRT_TableFooterCell } from './MRT_TableFooterCell';
|
5
|
-
import { VirtualItem } from '@tanstack/react-virtual';
|
5
|
+
import type { VirtualItem } from '@tanstack/react-virtual';
|
6
6
|
import type { MRT_Header, MRT_HeaderGroup, MRT_TableInstance } from '..';
|
7
7
|
|
8
8
|
interface Props {
|
@@ -149,7 +149,7 @@ export const MRT_FilterTextField = ({
|
|
149
149
|
} else if (isRangeFilter) {
|
150
150
|
setFilterValue('');
|
151
151
|
column.setFilterValue((old: [string | undefined, string | undefined]) => {
|
152
|
-
const newFilterValues = old
|
152
|
+
const newFilterValues = (Array.isArray(old) && old) || ['', ''];
|
153
153
|
newFilterValues[rangeFilterIndex as number] = undefined;
|
154
154
|
return newFilterValues;
|
155
155
|
});
|
@@ -99,6 +99,10 @@ export const mrtFilterOptions = (
|
|
99
99
|
},
|
100
100
|
];
|
101
101
|
|
102
|
+
const rangeModes = ['between', 'betweenInclusive', 'inNumberRange'];
|
103
|
+
const emptyModes = ['empty', 'notEmpty'];
|
104
|
+
const arrModes = ['arrIncludesSome', 'arrIncludesAll', 'arrIncludes'];
|
105
|
+
|
102
106
|
interface Props<TData extends Record<string, any> = {}> {
|
103
107
|
anchorEl: HTMLElement | null;
|
104
108
|
header?: MRT_Header<TData>;
|
@@ -150,46 +154,66 @@ export const MRT_FilterOptionMenu = <TData extends Record<string, any> = {}>({
|
|
150
154
|
);
|
151
155
|
|
152
156
|
const handleSelectFilterMode = (option: MRT_FilterOption) => {
|
153
|
-
|
157
|
+
const prevFilterMode = columnDef?._filterFn ?? '';
|
158
|
+
if (!header || !column) {
|
159
|
+
// global filter mode
|
160
|
+
setGlobalFilterFn(option);
|
161
|
+
} else if (option !== prevFilterMode) {
|
162
|
+
// column filter mode
|
154
163
|
setColumnFilterFns((prev: { [key: string]: any }) => ({
|
155
164
|
...prev,
|
156
165
|
[header.id]: option,
|
157
166
|
}));
|
158
|
-
|
159
|
-
|
167
|
+
|
168
|
+
// reset filter value and/or perform new filter render
|
169
|
+
if (emptyModes.includes(option)) {
|
170
|
+
// will now be empty/notEmpty filter mode
|
171
|
+
if (
|
172
|
+
currentFilterValue !== ' ' &&
|
173
|
+
!emptyModes.includes(prevFilterMode)
|
174
|
+
) {
|
175
|
+
column.setFilterValue(' ');
|
176
|
+
} else if (currentFilterValue) {
|
177
|
+
column.setFilterValue(currentFilterValue); // perform new filter render
|
178
|
+
}
|
160
179
|
} else if (
|
161
180
|
columnDef?.filterVariant === 'multi-select' ||
|
162
|
-
|
163
|
-
option as string,
|
164
|
-
)
|
181
|
+
arrModes.includes(option as string)
|
165
182
|
) {
|
183
|
+
// will now be array filter mode
|
166
184
|
if (
|
167
185
|
currentFilterValue instanceof String ||
|
168
186
|
(currentFilterValue as Array<any>)?.length
|
169
187
|
) {
|
170
188
|
column.setFilterValue([]);
|
171
189
|
setFilterValue?.([]);
|
190
|
+
} else if (currentFilterValue) {
|
191
|
+
column.setFilterValue(currentFilterValue); // perform new filter render
|
172
192
|
}
|
173
193
|
} else if (
|
174
194
|
columnDef?.filterVariant === 'range' ||
|
175
|
-
|
176
|
-
option as MRT_FilterOption,
|
177
|
-
)
|
195
|
+
rangeModes.includes(option as MRT_FilterOption)
|
178
196
|
) {
|
179
|
-
|
197
|
+
// will now be range filter mode
|
198
|
+
if (
|
199
|
+
!Array.isArray(currentFilterValue) ||
|
200
|
+
(!(currentFilterValue as Array<any>)?.every((v) => v === '') &&
|
201
|
+
!rangeModes.includes(prevFilterMode))
|
202
|
+
) {
|
180
203
|
column.setFilterValue(['', '']);
|
181
204
|
setFilterValue?.('');
|
205
|
+
} else {
|
206
|
+
column.setFilterValue(currentFilterValue); // perform new filter render
|
182
207
|
}
|
183
208
|
} else {
|
184
|
-
|
185
|
-
|
186
|
-
) {
|
209
|
+
// will now be single value filter mode
|
210
|
+
if (Array.isArray(currentFilterValue)) {
|
187
211
|
column.setFilterValue('');
|
188
212
|
setFilterValue?.('');
|
213
|
+
} else {
|
214
|
+
column.setFilterValue(currentFilterValue); // perform new filter render
|
189
215
|
}
|
190
216
|
}
|
191
|
-
} else {
|
192
|
-
setGlobalFilterFn(option);
|
193
217
|
}
|
194
218
|
setAnchorEl(null);
|
195
219
|
onSelect?.();
|
package/src/sortingFns.ts
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
import { compareItems, RankingInfo } from '@tanstack/match-sorter-utils';
|
2
|
-
import { Row, sortingFns } from '@tanstack/react-table';
|
3
|
-
import { MRT_Row } from '.';
|
1
|
+
import { compareItems, type RankingInfo } from '@tanstack/match-sorter-utils';
|
2
|
+
import { type Row, sortingFns } from '@tanstack/react-table';
|
3
|
+
import type { MRT_Row } from '.';
|
4
4
|
|
5
5
|
const fuzzy = <TData extends Record<string, any> = {}>(
|
6
6
|
rowA: Row<TData>,
|
package/src/table/MRT_Table.tsx
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
import React, { useCallback, useMemo } from 'react';
|
2
2
|
import {
|
3
3
|
defaultRangeExtractor,
|
4
|
-
Range,
|
5
4
|
useVirtualizer,
|
6
|
-
|
5
|
+
type Range,
|
6
|
+
type Virtualizer,
|
7
7
|
} from '@tanstack/react-virtual';
|
8
8
|
import Table from '@mui/material/Table';
|
9
9
|
import { MRT_TableHead } from '../head/MRT_TableHead';
|