@cutting/material-react-table 4.1.0 → 5.0.0-beta.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/index.d.ts +360 -333
- package/dist/index.js +919 -928
- package/dist/index.js.map +1 -1
- package/locales/ar/package.json +2 -2
- package/locales/az/package.json +2 -2
- package/locales/bg/package.json +2 -2
- package/locales/cs/package.json +2 -2
- package/locales/da/package.json +2 -2
- package/locales/de/package.json +2 -2
- package/locales/el/package.json +2 -2
- package/locales/en/package.json +2 -2
- package/locales/es/package.json +2 -2
- package/locales/et/package.json +2 -2
- package/locales/fa/package.json +2 -2
- package/locales/fi/package.json +2 -2
- package/locales/fr/package.json +2 -2
- package/locales/he/package.json +2 -2
- package/locales/hr/package.json +2 -2
- package/locales/hu/package.json +2 -2
- package/locales/hy/package.json +2 -2
- package/locales/id/package.json +2 -2
- package/locales/it/package.json +2 -2
- package/locales/ja/package.json +2 -2
- package/locales/ko/package.json +2 -2
- package/locales/nl/package.json +2 -2
- package/locales/no/package.json +2 -2
- package/locales/np/package.json +2 -2
- package/locales/pl/package.json +2 -2
- package/locales/pt/package.json +2 -2
- package/locales/pt-BR/package.json +2 -2
- package/locales/ro/package.json +2 -2
- package/locales/ru/package.json +2 -2
- package/locales/sk/package.json +2 -2
- package/locales/sr-Cyrl-RS/package.json +2 -2
- package/locales/sr-Latn-RS/package.json +2 -2
- package/locales/sv/package.json +2 -2
- package/locales/tr/package.json +2 -2
- package/locales/uk/package.json +2 -2
- package/locales/vi/package.json +2 -2
- package/locales/zh-Hans/package.json +2 -2
- package/locales/zh-Hant/package.json +2 -2
- package/package.json +46 -61
- package/src/components/body/MRT_TableBody.tsx +1 -2
- package/src/components/body/MRT_TableBodyCell.tsx +4 -5
- package/src/components/body/MRT_TableBodyCellValue.tsx +1 -2
- package/src/components/body/MRT_TableBodyRow.tsx +1 -2
- package/src/components/body/MRT_TableBodyRowGrabHandle.test.tsx +42 -0
- package/src/components/body/MRT_TableBodyRowPinButton.tsx +1 -2
- package/src/components/body/MRT_TableDetailPanel.test.tsx +40 -0
- package/src/components/body/MRT_TableDetailPanel.tsx +1 -2
- package/src/components/buttons/MRT_ColumnPinningButtons.test.tsx +69 -0
- package/src/components/buttons/MRT_ColumnPinningButtons.tsx +3 -3
- package/src/components/buttons/MRT_EditActionButtons.test.tsx +50 -0
- package/src/components/buttons/MRT_EditActionButtons.tsx +1 -3
- package/src/components/buttons/MRT_ExpandAllButton.tsx +1 -2
- package/src/components/buttons/MRT_ExpandButton.tsx +1 -2
- package/src/components/buttons/MRT_ToggleDensePaddingButton.test.tsx +38 -0
- package/src/components/buttons/MRT_ToggleDensePaddingButton.tsx +1 -2
- package/src/components/buttons/MRT_ToggleFiltersButton.test.tsx +38 -0
- package/src/components/buttons/MRT_ToggleFiltersButton.tsx +1 -2
- package/src/components/buttons/MRT_ToggleFullScreenButton.test.tsx +36 -0
- package/src/components/buttons/MRT_ToggleFullScreenButton.tsx +1 -2
- package/src/components/buttons/MRT_ToggleGlobalFilterButton.tsx +1 -2
- package/src/components/buttons/MRT_ToggleRowActionMenuButton.tsx +2 -3
- package/src/components/footer/MRT_TableFooter.tsx +1 -2
- package/src/components/footer/MRT_TableFooterCell.tsx +1 -2
- package/src/components/head/MRT_TableHead.tsx +1 -2
- package/src/components/head/MRT_TableHeadCell.tsx +9 -9
- package/src/components/head/MRT_TableHeadCellFilterContainer.tsx +1 -2
- package/src/components/head/MRT_TableHeadCellGrabHandle.test.tsx +61 -0
- package/src/components/head/MRT_TableHeadCellGrabHandle.tsx +4 -5
- package/src/components/head/MRT_TableHeadCellResizeHandle.test.tsx +45 -0
- package/src/components/head/MRT_TableHeadCellResizeHandle.tsx +4 -5
- package/src/components/head/MRT_TableHeadCellSortLabel.tsx +1 -2
- package/src/components/inputs/MRT_EditCellTextField.test.tsx +36 -0
- package/src/components/inputs/MRT_EditCellTextField.tsx +1 -3
- package/src/components/inputs/MRT_FilterCheckbox.tsx +1 -2
- package/src/components/inputs/MRT_FilterRangeSlider.tsx +2 -1
- package/src/components/inputs/MRT_FilterTextField.test.tsx +75 -0
- package/src/components/inputs/MRT_GlobalFilterTextField.tsx +1 -2
- package/src/components/inputs/MRT_SelectCheckbox.test.tsx +69 -0
- package/src/components/inputs/MRT_SelectCheckbox.tsx +1 -2
- package/src/components/menus/MRT_CellActionMenu.tsx +1 -2
- package/src/components/menus/MRT_ColumnActionMenu.tsx +12 -13
- package/src/components/menus/MRT_FilterOptionMenu.tsx +1 -2
- package/src/components/menus/MRT_RowActionMenu.tsx +1 -2
- package/src/components/menus/MRT_ShowHideColumnsMenu.tsx +1 -2
- package/src/components/menus/MRT_ShowHideColumnsMenuItems.tsx +4 -5
- package/src/components/modals/MRT_EditRowModal.test.tsx +54 -0
- package/src/components/modals/MRT_EditRowModal.tsx +1 -2
- package/src/components/table/MRT_Table.tsx +4 -5
- package/src/components/table/MRT_TableContainer.tsx +1 -2
- package/src/components/table/MRT_TablePaper.tsx +1 -2
- package/src/components/toolbar/MRT_BottomToolbar.tsx +2 -3
- package/src/components/toolbar/MRT_LinearProgressBar.tsx +1 -2
- package/src/components/toolbar/MRT_TablePagination.tsx +1 -2
- package/src/components/toolbar/MRT_ToolbarAlertBanner.tsx +3 -4
- package/src/components/toolbar/MRT_ToolbarDropZone.test.tsx +42 -0
- package/src/components/toolbar/MRT_ToolbarDropZone.tsx +1 -2
- package/src/components/toolbar/MRT_TopToolbar.tsx +1 -2
- package/src/fns/aggregationFns.test.tsx +57 -0
- package/src/fns/filterFns.test.tsx +156 -0
- package/src/fns/filterFns.ts +36 -22
- package/src/fns/sortingFns.ts +14 -5
- package/src/fns/tableFeatures.test.tsx +106 -0
- package/src/fns/tableFeatures.ts +103 -0
- package/src/hooks/display-columns/getMRT_RowExpandColumnDef.tsx +2 -2
- package/src/hooks/useMRT_ColumnVirtualizer.ts +6 -5
- package/src/hooks/useMRT_Effects.ts +3 -4
- package/src/hooks/useMRT_RowVirtualizer.ts +1 -2
- package/src/hooks/useMRT_Rows.ts +1 -2
- package/src/hooks/useMRT_TableInstance.ts +82 -63
- package/src/hooks/useMRT_TableOptions.ts +5 -37
- package/src/icons.ts +1 -1
- package/src/types.ts +162 -134
- package/src/utils/column.utils.ts +31 -24
- package/src/utils/row.utils.ts +7 -10
- package/src/utils/style.utils.ts +9 -10
- package/src/utils/tanstack.helpers.ts +2 -2
- package/dist/index.d.mts +0 -1925
- package/dist/index.mjs +0 -5409
- package/dist/index.mjs.map +0 -1
- package/locales/ar/index.d.ts +0 -3
- package/locales/ar/index.js +0 -98
- package/locales/az/index.d.ts +0 -3
- package/locales/az/index.js +0 -98
- package/locales/bg/index.d.ts +0 -3
- package/locales/bg/index.js +0 -98
- package/locales/cs/index.d.ts +0 -3
- package/locales/cs/index.js +0 -98
- package/locales/da/index.d.ts +0 -3
- package/locales/da/index.js +0 -98
- package/locales/de/index.d.ts +0 -3
- package/locales/de/index.js +0 -98
- package/locales/el/index.d.ts +0 -3
- package/locales/el/index.js +0 -98
- package/locales/en/index.d.ts +0 -3
- package/locales/en/index.js +0 -98
- package/locales/es/index.d.ts +0 -3
- package/locales/es/index.js +0 -98
- package/locales/et/index.d.ts +0 -3
- package/locales/et/index.js +0 -98
- package/locales/fa/index.d.ts +0 -3
- package/locales/fa/index.js +0 -98
- package/locales/fi/index.d.ts +0 -3
- package/locales/fi/index.js +0 -98
- package/locales/fr/index.d.ts +0 -3
- package/locales/fr/index.js +0 -98
- package/locales/he/index.d.ts +0 -3
- package/locales/he/index.js +0 -98
- package/locales/hr/index.d.ts +0 -3
- package/locales/hr/index.js +0 -98
- package/locales/hu/index.d.ts +0 -3
- package/locales/hu/index.js +0 -98
- package/locales/hy/index.d.ts +0 -3
- package/locales/hy/index.js +0 -98
- package/locales/id/index.d.ts +0 -3
- package/locales/id/index.js +0 -98
- package/locales/it/index.d.ts +0 -3
- package/locales/it/index.js +0 -98
- package/locales/ja/index.d.ts +0 -3
- package/locales/ja/index.js +0 -98
- package/locales/ko/index.d.ts +0 -3
- package/locales/ko/index.js +0 -98
- package/locales/nl/index.d.ts +0 -3
- package/locales/nl/index.js +0 -98
- package/locales/no/index.d.ts +0 -3
- package/locales/no/index.js +0 -98
- package/locales/np/index.d.ts +0 -3
- package/locales/np/index.js +0 -98
- package/locales/pl/index.d.ts +0 -3
- package/locales/pl/index.js +0 -98
- package/locales/pt/index.d.ts +0 -3
- package/locales/pt/index.js +0 -98
- package/locales/pt-BR/index.d.ts +0 -3
- package/locales/pt-BR/index.js +0 -98
- package/locales/ro/index.d.ts +0 -3
- package/locales/ro/index.js +0 -98
- package/locales/ru/index.d.ts +0 -3
- package/locales/ru/index.js +0 -98
- package/locales/sk/index.d.ts +0 -3
- package/locales/sk/index.js +0 -98
- package/locales/sr-Cyrl-RS/index.d.ts +0 -3
- package/locales/sr-Cyrl-RS/index.js +0 -98
- package/locales/sr-Latn-RS/index.d.ts +0 -3
- package/locales/sr-Latn-RS/index.js +0 -98
- package/locales/sv/index.d.ts +0 -3
- package/locales/sv/index.js +0 -98
- package/locales/tr/index.d.ts +0 -3
- package/locales/tr/index.js +0 -98
- package/locales/uk/index.d.ts +0 -3
- package/locales/uk/index.js +0 -98
- package/locales/vi/index.d.ts +0 -3
- package/locales/vi/index.js +0 -98
- package/locales/zh-Hans/index.d.ts +0 -3
- package/locales/zh-Hans/index.js +0 -98
- package/locales/zh-Hant/index.d.ts +0 -3
- package/locales/zh-Hant/index.js +0 -98
package/src/fns/filterFns.ts
CHANGED
|
@@ -1,17 +1,24 @@
|
|
|
1
|
+
import { rankings, rankItem } from '@tanstack/match-sorter-utils';
|
|
1
2
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
filterFn_arrIncludes,
|
|
4
|
+
filterFn_arrIncludesAll,
|
|
5
|
+
filterFn_arrIncludesSome,
|
|
6
|
+
filterFn_equalsString,
|
|
7
|
+
filterFn_equalsStringSensitive,
|
|
8
|
+
filterFn_includesString,
|
|
9
|
+
filterFn_includesStringSensitive,
|
|
10
|
+
filterFn_inNumberRange,
|
|
11
|
+
type FilterMeta,
|
|
12
|
+
type Row,
|
|
13
|
+
} from '@tanstack/react-table';
|
|
7
14
|
|
|
8
15
|
import { type MRT_RowData } from '../types';
|
|
9
16
|
|
|
10
17
|
const fuzzy = <TData extends MRT_RowData>(
|
|
11
|
-
row: Row<TData>,
|
|
18
|
+
row: Row<any, TData>,
|
|
12
19
|
columnId: string,
|
|
13
20
|
filterValue: number | string,
|
|
14
|
-
addMeta
|
|
21
|
+
addMeta?: (meta: FilterMeta) => void,
|
|
15
22
|
): boolean => {
|
|
16
23
|
const itemRank = rankItem(
|
|
17
24
|
row.getValue<null | number | string>(columnId),
|
|
@@ -20,14 +27,14 @@ const fuzzy = <TData extends MRT_RowData>(
|
|
|
20
27
|
threshold: rankings.MATCHES,
|
|
21
28
|
},
|
|
22
29
|
);
|
|
23
|
-
addMeta(itemRank);
|
|
30
|
+
addMeta?.(itemRank);
|
|
24
31
|
return itemRank.passed;
|
|
25
32
|
};
|
|
26
33
|
|
|
27
34
|
fuzzy.autoRemove = (val: any) => !val;
|
|
28
35
|
|
|
29
36
|
const contains = <TData extends MRT_RowData>(
|
|
30
|
-
row: Row<TData>,
|
|
37
|
+
row: Row<any, TData>,
|
|
31
38
|
id: string,
|
|
32
39
|
filterValue: number | string,
|
|
33
40
|
): boolean =>
|
|
@@ -41,7 +48,7 @@ const contains = <TData extends MRT_RowData>(
|
|
|
41
48
|
contains.autoRemove = (val: any) => !val;
|
|
42
49
|
|
|
43
50
|
const startsWith = <TData extends MRT_RowData>(
|
|
44
|
-
row: Row<TData>,
|
|
51
|
+
row: Row<any, TData>,
|
|
45
52
|
id: string,
|
|
46
53
|
filterValue: number | string,
|
|
47
54
|
): boolean =>
|
|
@@ -55,7 +62,7 @@ const startsWith = <TData extends MRT_RowData>(
|
|
|
55
62
|
startsWith.autoRemove = (val: any) => !val;
|
|
56
63
|
|
|
57
64
|
const endsWith = <TData extends MRT_RowData>(
|
|
58
|
-
row: Row<TData>,
|
|
65
|
+
row: Row<any, TData>,
|
|
59
66
|
id: string,
|
|
60
67
|
filterValue: number | string,
|
|
61
68
|
): boolean =>
|
|
@@ -69,7 +76,7 @@ const endsWith = <TData extends MRT_RowData>(
|
|
|
69
76
|
endsWith.autoRemove = (val: any) => !val;
|
|
70
77
|
|
|
71
78
|
const equals = <TData extends MRT_RowData>(
|
|
72
|
-
row: Row<TData>,
|
|
79
|
+
row: Row<any, TData>,
|
|
73
80
|
id: string,
|
|
74
81
|
filterValue: number | string,
|
|
75
82
|
): boolean =>
|
|
@@ -79,7 +86,7 @@ const equals = <TData extends MRT_RowData>(
|
|
|
79
86
|
equals.autoRemove = (val: any) => !val;
|
|
80
87
|
|
|
81
88
|
const notEquals = <TData extends MRT_RowData>(
|
|
82
|
-
row: Row<TData>,
|
|
89
|
+
row: Row<any, TData>,
|
|
83
90
|
id: string,
|
|
84
91
|
filterValue: number | string,
|
|
85
92
|
): boolean =>
|
|
@@ -89,7 +96,7 @@ const notEquals = <TData extends MRT_RowData>(
|
|
|
89
96
|
notEquals.autoRemove = (val: any) => !val;
|
|
90
97
|
|
|
91
98
|
const greaterThan = <TData extends MRT_RowData>(
|
|
92
|
-
row: Row<TData>,
|
|
99
|
+
row: Row<any, TData>,
|
|
93
100
|
id: string,
|
|
94
101
|
filterValue: number | string,
|
|
95
102
|
): boolean =>
|
|
@@ -103,7 +110,7 @@ const greaterThan = <TData extends MRT_RowData>(
|
|
|
103
110
|
greaterThan.autoRemove = (val: any) => !val;
|
|
104
111
|
|
|
105
112
|
const greaterThanOrEqualTo = <TData extends MRT_RowData>(
|
|
106
|
-
row: Row<TData>,
|
|
113
|
+
row: Row<any, TData>,
|
|
107
114
|
id: string,
|
|
108
115
|
filterValue: number | string,
|
|
109
116
|
): boolean => equals(row, id, filterValue) || greaterThan(row, id, filterValue);
|
|
@@ -111,7 +118,7 @@ const greaterThanOrEqualTo = <TData extends MRT_RowData>(
|
|
|
111
118
|
greaterThanOrEqualTo.autoRemove = (val: any) => !val;
|
|
112
119
|
|
|
113
120
|
const lessThan = <TData extends MRT_RowData>(
|
|
114
|
-
row: Row<TData>,
|
|
121
|
+
row: Row<any, TData>,
|
|
115
122
|
id: string,
|
|
116
123
|
filterValue: number | string,
|
|
117
124
|
): boolean =>
|
|
@@ -125,7 +132,7 @@ const lessThan = <TData extends MRT_RowData>(
|
|
|
125
132
|
lessThan.autoRemove = (val: any) => !val;
|
|
126
133
|
|
|
127
134
|
const lessThanOrEqualTo = <TData extends MRT_RowData>(
|
|
128
|
-
row: Row<TData>,
|
|
135
|
+
row: Row<any, TData>,
|
|
129
136
|
id: string,
|
|
130
137
|
filterValue: number | string,
|
|
131
138
|
): boolean => equals(row, id, filterValue) || lessThan(row, id, filterValue);
|
|
@@ -133,7 +140,7 @@ const lessThanOrEqualTo = <TData extends MRT_RowData>(
|
|
|
133
140
|
lessThanOrEqualTo.autoRemove = (val: any) => !val;
|
|
134
141
|
|
|
135
142
|
const between = <TData extends MRT_RowData>(
|
|
136
|
-
row: Row<TData>,
|
|
143
|
+
row: Row<any, TData>,
|
|
137
144
|
id: string,
|
|
138
145
|
filterValues: [number | string, number | string],
|
|
139
146
|
): boolean =>
|
|
@@ -148,7 +155,7 @@ const between = <TData extends MRT_RowData>(
|
|
|
148
155
|
between.autoRemove = (val: any) => !val;
|
|
149
156
|
|
|
150
157
|
const betweenInclusive = <TData extends MRT_RowData>(
|
|
151
|
-
row: Row<TData>,
|
|
158
|
+
row: Row<any, TData>,
|
|
152
159
|
id: string,
|
|
153
160
|
filterValues: [number | string, number | string],
|
|
154
161
|
): boolean =>
|
|
@@ -163,7 +170,7 @@ const betweenInclusive = <TData extends MRT_RowData>(
|
|
|
163
170
|
betweenInclusive.autoRemove = (val: any) => !val;
|
|
164
171
|
|
|
165
172
|
const empty = <TData extends MRT_RowData>(
|
|
166
|
-
row: Row<TData>,
|
|
173
|
+
row: Row<any, TData>,
|
|
167
174
|
id: string,
|
|
168
175
|
_filterValue: number | string,
|
|
169
176
|
): boolean => !row.getValue<null | number | string>(id)?.toString().trim();
|
|
@@ -171,7 +178,7 @@ const empty = <TData extends MRT_RowData>(
|
|
|
171
178
|
empty.autoRemove = (val: any) => !val;
|
|
172
179
|
|
|
173
180
|
const notEmpty = <TData extends MRT_RowData>(
|
|
174
|
-
row: Row<TData>,
|
|
181
|
+
row: Row<any, TData>,
|
|
175
182
|
id: string,
|
|
176
183
|
_filterValue: number | string,
|
|
177
184
|
): boolean => !!row.getValue<null | number | string>(id)?.toString().trim();
|
|
@@ -179,16 +186,23 @@ const notEmpty = <TData extends MRT_RowData>(
|
|
|
179
186
|
notEmpty.autoRemove = (val: any) => !val;
|
|
180
187
|
|
|
181
188
|
export const MRT_FilterFns = {
|
|
182
|
-
|
|
189
|
+
arrIncludes: filterFn_arrIncludes,
|
|
190
|
+
arrIncludesAll: filterFn_arrIncludesAll,
|
|
191
|
+
arrIncludesSome: filterFn_arrIncludesSome,
|
|
183
192
|
between,
|
|
184
193
|
betweenInclusive,
|
|
185
194
|
contains,
|
|
186
195
|
empty,
|
|
187
196
|
endsWith,
|
|
188
197
|
equals,
|
|
198
|
+
equalsString: filterFn_equalsString,
|
|
199
|
+
equalsStringSensitive: filterFn_equalsStringSensitive,
|
|
189
200
|
fuzzy,
|
|
190
201
|
greaterThan,
|
|
191
202
|
greaterThanOrEqualTo,
|
|
203
|
+
includesString: filterFn_includesString,
|
|
204
|
+
includesStringSensitive: filterFn_includesStringSensitive,
|
|
205
|
+
inNumberRange: filterFn_inNumberRange,
|
|
192
206
|
lessThan,
|
|
193
207
|
lessThanOrEqualTo,
|
|
194
208
|
notEmpty,
|
package/src/fns/sortingFns.ts
CHANGED
|
@@ -1,11 +1,17 @@
|
|
|
1
1
|
import { compareItems, type RankingInfo } from '@tanstack/match-sorter-utils';
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
sortFn_alphanumeric,
|
|
4
|
+
sortFn_basic,
|
|
5
|
+
sortFn_datetime,
|
|
6
|
+
sortFn_text,
|
|
7
|
+
} from '@tanstack/react-table';
|
|
8
|
+
import { type Row } from '@tanstack/react-table';
|
|
3
9
|
|
|
4
10
|
import { type MRT_Row, type MRT_RowData } from '../types';
|
|
5
11
|
|
|
6
12
|
const fuzzy = <TData extends MRT_RowData>(
|
|
7
|
-
rowA: Row<TData>,
|
|
8
|
-
rowB: Row<TData>,
|
|
13
|
+
rowA: Row<any, TData>,
|
|
14
|
+
rowB: Row<any, TData>,
|
|
9
15
|
columnId: string,
|
|
10
16
|
) => {
|
|
11
17
|
let dir = 0;
|
|
@@ -17,13 +23,16 @@ const fuzzy = <TData extends MRT_RowData>(
|
|
|
17
23
|
}
|
|
18
24
|
// Provide a fallback for when the item ranks are equal
|
|
19
25
|
return dir === 0
|
|
20
|
-
?
|
|
26
|
+
? sortFn_alphanumeric(rowA, rowB, columnId)
|
|
21
27
|
: dir;
|
|
22
28
|
};
|
|
23
29
|
|
|
24
30
|
export const MRT_SortingFns = {
|
|
25
|
-
|
|
31
|
+
alphanumeric: sortFn_alphanumeric,
|
|
32
|
+
basic: sortFn_basic,
|
|
33
|
+
datetime: sortFn_datetime,
|
|
26
34
|
fuzzy,
|
|
35
|
+
text: sortFn_text,
|
|
27
36
|
};
|
|
28
37
|
|
|
29
38
|
export const rankGlobalFuzzy = <TData extends MRT_RowData>(
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { render } from '@testing-library/react';
|
|
2
|
+
import { describe, expect, test } from 'vitest';
|
|
3
|
+
|
|
4
|
+
import { MaterialReactTable } from '../components/MaterialReactTable';
|
|
5
|
+
import { type MRT_ColumnDef } from '../types';
|
|
6
|
+
|
|
7
|
+
interface Person {
|
|
8
|
+
name: string;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const data: Person[] = [
|
|
12
|
+
{ name: 'Jonathan' },
|
|
13
|
+
{ name: 'Aaron' },
|
|
14
|
+
{ name: 'Sara' },
|
|
15
|
+
];
|
|
16
|
+
|
|
17
|
+
const columns: MRT_ColumnDef<Person>[] = [
|
|
18
|
+
{ accessorKey: 'name', header: 'Name' },
|
|
19
|
+
];
|
|
20
|
+
|
|
21
|
+
const renderedNames = (container: HTMLElement) =>
|
|
22
|
+
Array.from(container.querySelectorAll('tbody tr')).map(
|
|
23
|
+
(row) => row.textContent,
|
|
24
|
+
);
|
|
25
|
+
|
|
26
|
+
describe('server-side options suppress client-side row models', () => {
|
|
27
|
+
test('manualPagination renders the whole server page, ignoring pageSize', () => {
|
|
28
|
+
const { container } = render(
|
|
29
|
+
<MaterialReactTable
|
|
30
|
+
columns={columns}
|
|
31
|
+
data={data}
|
|
32
|
+
manualPagination
|
|
33
|
+
rowCount={300}
|
|
34
|
+
state={{ pagination: { pageIndex: 0, pageSize: 2 } }}
|
|
35
|
+
/>,
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
expect(renderedNames(container)).toEqual(['Jonathan', 'Aaron', 'Sara']);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
test('manualFiltering keeps every row when a global filter is set', () => {
|
|
42
|
+
const { container } = render(
|
|
43
|
+
<MaterialReactTable
|
|
44
|
+
columns={columns}
|
|
45
|
+
data={data}
|
|
46
|
+
manualFiltering
|
|
47
|
+
state={{ globalFilter: 'zzz' }}
|
|
48
|
+
/>,
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
expect(renderedNames(container)).toEqual(['Jonathan', 'Aaron', 'Sara']);
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
test('manualSorting preserves server order when a sort is set', () => {
|
|
55
|
+
const { container } = render(
|
|
56
|
+
<MaterialReactTable
|
|
57
|
+
columns={columns}
|
|
58
|
+
data={data}
|
|
59
|
+
enableSorting
|
|
60
|
+
manualSorting
|
|
61
|
+
state={{ sorting: [{ desc: false, id: 'name' }] }}
|
|
62
|
+
/>,
|
|
63
|
+
);
|
|
64
|
+
|
|
65
|
+
expect(renderedNames(container)).toEqual(['Jonathan', 'Aaron', 'Sara']);
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
describe('client-side row models stay active by default', () => {
|
|
70
|
+
test('pagination slices to pageSize', () => {
|
|
71
|
+
const { container } = render(
|
|
72
|
+
<MaterialReactTable
|
|
73
|
+
columns={columns}
|
|
74
|
+
data={data}
|
|
75
|
+
state={{ pagination: { pageIndex: 0, pageSize: 2 } }}
|
|
76
|
+
/>,
|
|
77
|
+
);
|
|
78
|
+
|
|
79
|
+
expect(renderedNames(container)).toEqual(['Jonathan', 'Aaron']);
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
test('global filter drops non-matching rows', () => {
|
|
83
|
+
const { container } = render(
|
|
84
|
+
<MaterialReactTable
|
|
85
|
+
columns={columns}
|
|
86
|
+
data={data}
|
|
87
|
+
state={{ globalFilter: 'zzz' }}
|
|
88
|
+
/>,
|
|
89
|
+
);
|
|
90
|
+
|
|
91
|
+
expect(renderedNames(container)).toEqual(['No results found']);
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
test('sorting reorders rows', () => {
|
|
95
|
+
const { container } = render(
|
|
96
|
+
<MaterialReactTable
|
|
97
|
+
columns={columns}
|
|
98
|
+
data={data}
|
|
99
|
+
enableSorting
|
|
100
|
+
state={{ sorting: [{ desc: false, id: 'name' }] }}
|
|
101
|
+
/>,
|
|
102
|
+
);
|
|
103
|
+
|
|
104
|
+
expect(renderedNames(container)).toEqual(['Aaron', 'Jonathan', 'Sara']);
|
|
105
|
+
});
|
|
106
|
+
});
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type AggregationFnDef,
|
|
3
|
+
cellSelectionFeature,
|
|
4
|
+
cellSpanningFeature,
|
|
5
|
+
columnFacetingFeature,
|
|
6
|
+
columnFilteringFeature,
|
|
7
|
+
columnGroupingFeature,
|
|
8
|
+
columnOrderingFeature,
|
|
9
|
+
columnPinningFeature,
|
|
10
|
+
columnResizingFeature,
|
|
11
|
+
columnSizingFeature,
|
|
12
|
+
columnVisibilityFeature,
|
|
13
|
+
createExpandedRowModel,
|
|
14
|
+
createFacetedMinMaxValues,
|
|
15
|
+
createFacetedRowModel,
|
|
16
|
+
createFacetedUniqueValues,
|
|
17
|
+
createFilteredRowModel,
|
|
18
|
+
createGroupedRowModel,
|
|
19
|
+
createPaginatedRowModel,
|
|
20
|
+
createSortedRowModel,
|
|
21
|
+
type FilterFn,
|
|
22
|
+
globalFilteringFeature,
|
|
23
|
+
rowAggregationFeature,
|
|
24
|
+
rowExpandingFeature,
|
|
25
|
+
rowPaginationFeature,
|
|
26
|
+
rowPinningFeature,
|
|
27
|
+
rowSelectionFeature,
|
|
28
|
+
rowSortingFeature,
|
|
29
|
+
type SortFn,
|
|
30
|
+
type StockFeatures,
|
|
31
|
+
type TableFeature,
|
|
32
|
+
tableFeatures,
|
|
33
|
+
} from '@tanstack/react-table';
|
|
34
|
+
|
|
35
|
+
import { MRT_AggregationFns } from './aggregationFns';
|
|
36
|
+
import { MRT_FilterFns } from './filterFns';
|
|
37
|
+
import { MRT_SortingFns } from './sortingFns';
|
|
38
|
+
|
|
39
|
+
const mrtFeature: TableFeature = {
|
|
40
|
+
getInitialState: (state) => ({
|
|
41
|
+
actionCell: null,
|
|
42
|
+
columnFilterFns: {},
|
|
43
|
+
creatingRow: null,
|
|
44
|
+
density: 'comfortable',
|
|
45
|
+
draggingColumn: null,
|
|
46
|
+
draggingRow: null,
|
|
47
|
+
editingCell: null,
|
|
48
|
+
editingRow: null,
|
|
49
|
+
globalFilterFn: 'fuzzy',
|
|
50
|
+
hoveredColumn: null,
|
|
51
|
+
hoveredRow: null,
|
|
52
|
+
isFullScreen: false,
|
|
53
|
+
isLoading: false,
|
|
54
|
+
isSaving: false,
|
|
55
|
+
showAlertBanner: false,
|
|
56
|
+
showColumnFilters: false,
|
|
57
|
+
showGlobalFilter: false,
|
|
58
|
+
showLoadingOverlay: false,
|
|
59
|
+
showProgressBars: false,
|
|
60
|
+
showSkeletons: false,
|
|
61
|
+
showToolbarDropZone: false,
|
|
62
|
+
...state,
|
|
63
|
+
}),
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
export const MRT_DefaultTableFeatures = tableFeatures({
|
|
67
|
+
aggregationFns: MRT_AggregationFns,
|
|
68
|
+
cellSelectionFeature,
|
|
69
|
+
cellSpanningFeature,
|
|
70
|
+
columnFacetingFeature,
|
|
71
|
+
columnFilteringFeature,
|
|
72
|
+
columnGroupingFeature,
|
|
73
|
+
columnOrderingFeature,
|
|
74
|
+
columnPinningFeature,
|
|
75
|
+
columnResizingFeature,
|
|
76
|
+
columnSizingFeature,
|
|
77
|
+
columnVisibilityFeature,
|
|
78
|
+
expandedRowModel: createExpandedRowModel(),
|
|
79
|
+
facetedMinMaxValues: createFacetedMinMaxValues(),
|
|
80
|
+
facetedRowModel: createFacetedRowModel(),
|
|
81
|
+
facetedUniqueValues: createFacetedUniqueValues(),
|
|
82
|
+
filteredRowModel: createFilteredRowModel(),
|
|
83
|
+
filterFns: MRT_FilterFns,
|
|
84
|
+
globalFilteringFeature,
|
|
85
|
+
groupedRowModel: createGroupedRowModel(),
|
|
86
|
+
mrtFeature,
|
|
87
|
+
paginatedRowModel: createPaginatedRowModel(),
|
|
88
|
+
rowAggregationFeature,
|
|
89
|
+
rowExpandingFeature,
|
|
90
|
+
rowPaginationFeature,
|
|
91
|
+
rowPinningFeature,
|
|
92
|
+
rowSelectionFeature,
|
|
93
|
+
rowSortingFeature,
|
|
94
|
+
sortedRowModel: createSortedRowModel(),
|
|
95
|
+
sortFns: MRT_SortingFns,
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
export interface MRT_TableFeatures extends StockFeatures {
|
|
99
|
+
aggregationFns: Record<string, AggregationFnDef<any, any, any, any>>;
|
|
100
|
+
filterFns: Record<string, FilterFn<any, any>>;
|
|
101
|
+
mrtFeature: TableFeature;
|
|
102
|
+
sortFns: Record<string, SortFn<any, any>>;
|
|
103
|
+
}
|
|
@@ -46,7 +46,7 @@ export const getMRT_RowExpandColumnDef = <TData extends MRT_RowData>(
|
|
|
46
46
|
<MRT_ExpandButton {...expandButtonProps} />
|
|
47
47
|
<Tooltip
|
|
48
48
|
{...getCommonTooltipProps('right')}
|
|
49
|
-
title={table.getColumn(row.groupingColumnId)
|
|
49
|
+
title={table.getColumn(row.groupingColumnId)?.columnDef.header}
|
|
50
50
|
>
|
|
51
51
|
<span>{row.groupingValue as ReactNode}</span>
|
|
52
52
|
</Tooltip>
|
|
@@ -71,7 +71,7 @@ export const getMRT_RowExpandColumnDef = <TData extends MRT_RowData>(
|
|
|
71
71
|
grouping
|
|
72
72
|
?.map(
|
|
73
73
|
(groupedColumnId) =>
|
|
74
|
-
table.getColumn(groupedColumnId)
|
|
74
|
+
table.getColumn(groupedColumnId)?.columnDef.header,
|
|
75
75
|
)
|
|
76
76
|
?.join(', ')}
|
|
77
77
|
</>
|
|
@@ -17,7 +17,6 @@ export const useMRT_ColumnVirtualizer = <
|
|
|
17
17
|
table: MRT_TableInstance<TData>,
|
|
18
18
|
): MRT_ColumnVirtualizer | undefined => {
|
|
19
19
|
const {
|
|
20
|
-
getState,
|
|
21
20
|
options: {
|
|
22
21
|
columnVirtualizerInstanceRef,
|
|
23
22
|
columnVirtualizerOptions,
|
|
@@ -26,7 +25,7 @@ export const useMRT_ColumnVirtualizer = <
|
|
|
26
25
|
},
|
|
27
26
|
refs: { tableContainerRef },
|
|
28
27
|
} = table;
|
|
29
|
-
const { columnPinning, columnVisibility, draggingColumn } =
|
|
28
|
+
const { columnPinning, columnVisibility, draggingColumn } = table.state;
|
|
30
29
|
|
|
31
30
|
if (!enableColumnVirtualization) return undefined;
|
|
32
31
|
|
|
@@ -43,9 +42,11 @@ export const useMRT_ColumnVirtualizer = <
|
|
|
43
42
|
() =>
|
|
44
43
|
enableColumnPinning
|
|
45
44
|
? [
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
.
|
|
45
|
+
visibleColumns
|
|
46
|
+
.filter((c) => c.getIsPinned() === 'start')
|
|
47
|
+
.map((c) => c.getPinnedIndex()),
|
|
48
|
+
visibleColumns
|
|
49
|
+
.filter((c) => c.getIsPinned() === 'end')
|
|
49
50
|
.map(
|
|
50
51
|
(column) => visibleColumns.length - column.getPinnedIndex() - 1,
|
|
51
52
|
)
|
|
@@ -13,8 +13,7 @@ export const useMRT_Effects = <TData extends MRT_RowData>(
|
|
|
13
13
|
) => {
|
|
14
14
|
const {
|
|
15
15
|
getIsSomeRowsPinned,
|
|
16
|
-
|
|
17
|
-
getState,
|
|
16
|
+
getPrePaginatedRowModel,
|
|
18
17
|
options: { enablePagination, enableRowPinning, rowCount },
|
|
19
18
|
} = table;
|
|
20
19
|
const {
|
|
@@ -26,10 +25,10 @@ export const useMRT_Effects = <TData extends MRT_RowData>(
|
|
|
26
25
|
pagination,
|
|
27
26
|
showSkeletons,
|
|
28
27
|
sorting,
|
|
29
|
-
} =
|
|
28
|
+
} = table.state;
|
|
30
29
|
|
|
31
30
|
const totalColumnCount = table.options.columns.length;
|
|
32
|
-
const totalRowCount = rowCount ??
|
|
31
|
+
const totalRowCount = rowCount ?? getPrePaginatedRowModel().rows.length;
|
|
33
32
|
|
|
34
33
|
const rerender = useReducer(() => ({}), {})[1];
|
|
35
34
|
const initialBodyHeight = useRef<string>(null);
|
|
@@ -20,7 +20,6 @@ export const useMRT_RowVirtualizer = <
|
|
|
20
20
|
): MRT_RowVirtualizer<TScrollElement, TItemElement> | undefined => {
|
|
21
21
|
const {
|
|
22
22
|
getRowModel,
|
|
23
|
-
getState,
|
|
24
23
|
options: {
|
|
25
24
|
enableRowVirtualization,
|
|
26
25
|
renderDetailPanel,
|
|
@@ -29,7 +28,7 @@ export const useMRT_RowVirtualizer = <
|
|
|
29
28
|
},
|
|
30
29
|
refs: { tableContainerRef },
|
|
31
30
|
} = table;
|
|
32
|
-
const { density, draggingRow, expanded } =
|
|
31
|
+
const { density, draggingRow, expanded } = table.state;
|
|
33
32
|
|
|
34
33
|
if (!enableRowVirtualization) return undefined;
|
|
35
34
|
|
package/src/hooks/useMRT_Rows.ts
CHANGED
|
@@ -12,7 +12,6 @@ export const useMRT_Rows = <TData extends MRT_RowData>(
|
|
|
12
12
|
): MRT_Row<TData>[] => {
|
|
13
13
|
const {
|
|
14
14
|
getRowModel,
|
|
15
|
-
getState,
|
|
16
15
|
options: { data, enableGlobalFilterRankedResults, positionCreatingRow },
|
|
17
16
|
} = table;
|
|
18
17
|
const {
|
|
@@ -22,7 +21,7 @@ export const useMRT_Rows = <TData extends MRT_RowData>(
|
|
|
22
21
|
pagination,
|
|
23
22
|
rowPinning,
|
|
24
23
|
sorting,
|
|
25
|
-
} =
|
|
24
|
+
} = table.state;
|
|
26
25
|
|
|
27
26
|
const rows = useMemo(
|
|
28
27
|
() => getMRT_Rows(table),
|