material-react-table 0.7.5 → 0.8.0-alpha.2
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 +16 -15
- package/dist/body/MRT_TableBody.d.ts +0 -1
- package/dist/body/MRT_TableBodyCell.d.ts +1 -0
- package/dist/body/MRT_TableBodyRow.d.ts +0 -1
- package/dist/buttons/MRT_ColumnPinningButtons.d.ts +8 -0
- package/dist/buttons/MRT_CopyButton.d.ts +2 -1
- package/dist/enums.d.ts +2 -2
- package/dist/filtersFNs.d.ts +31 -30
- package/dist/footer/MRT_TableFooter.d.ts +0 -1
- package/dist/head/MRT_TableHead.d.ts +0 -1
- package/dist/inputs/MRT_FilterRangeFields.d.ts +8 -0
- package/dist/inputs/MRT_FilterTextField.d.ts +1 -0
- package/dist/localization.d.ts +7 -2
- package/dist/material-react-table.cjs.development.js +451 -418
- 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 +454 -421
- package/dist/material-react-table.esm.js.map +1 -1
- package/dist/table/MRT_Table.d.ts +0 -1
- package/dist/toolbar/MRT_ToolbarTop.d.ts +1 -0
- package/dist/utils.d.ts +1 -1
- package/package.json +21 -25
- package/src/MaterialReactTable.tsx +20 -24
- package/src/body/MRT_TableBody.tsx +3 -11
- package/src/body/MRT_TableBodyCell.tsx +103 -52
- package/src/body/MRT_TableBodyRow.tsx +21 -30
- package/src/buttons/MRT_ColumnPinningButtons.tsx +57 -0
- package/src/buttons/MRT_CopyButton.tsx +3 -2
- package/src/buttons/MRT_EditActionButtons.tsx +1 -2
- package/src/buttons/MRT_ExpandAllButton.tsx +22 -18
- package/src/buttons/MRT_ExpandButton.tsx +27 -21
- package/src/enums.ts +2 -2
- package/src/filtersFNs.ts +71 -81
- package/src/footer/MRT_TableFooter.tsx +6 -16
- package/src/footer/MRT_TableFooterCell.tsx +15 -15
- package/src/footer/MRT_TableFooterRow.tsx +6 -8
- package/src/head/MRT_TableHead.tsx +5 -16
- package/src/head/MRT_TableHeadCell.tsx +116 -49
- package/src/head/MRT_TableHeadRow.tsx +8 -15
- package/src/inputs/MRT_EditCellTextField.tsx +3 -3
- package/src/inputs/MRT_FilterRangeFields.tsx +41 -0
- package/src/inputs/MRT_FilterTextField.tsx +76 -41
- package/src/inputs/MRT_SelectCheckbox.tsx +15 -17
- package/src/localization.ts +15 -5
- package/src/menus/MRT_ColumnActionMenu.tsx +13 -12
- package/src/menus/MRT_FilterOptionMenu.tsx +36 -33
- package/src/menus/MRT_ShowHideColumnsMenu.tsx +25 -11
- package/src/menus/MRT_ShowHideColumnsMenuItems.tsx +16 -6
- package/src/table/MRT_Table.tsx +8 -19
- package/src/table/MRT_TableContainer.tsx +8 -69
- package/src/table/MRT_TableRoot.tsx +44 -52
- package/src/toolbar/MRT_LinearProgressBar.tsx +5 -2
- package/src/toolbar/MRT_ToolbarAlertBanner.tsx +3 -2
- package/src/toolbar/MRT_ToolbarTop.tsx +4 -6
|
@@ -1,19 +1,18 @@
|
|
|
1
1
|
import React, { useEffect, useMemo, useState } from 'react';
|
|
2
2
|
import {
|
|
3
|
+
FilterFn,
|
|
3
4
|
PaginationState,
|
|
4
|
-
Table,
|
|
5
5
|
createTable,
|
|
6
6
|
functionalUpdate,
|
|
7
|
-
getColumnFilteredRowModelSync,
|
|
8
7
|
getExpandedRowModel,
|
|
9
|
-
getGlobalFilteredRowModelSync,
|
|
10
|
-
getGroupedRowModelSync,
|
|
11
8
|
getPaginationRowModel,
|
|
12
|
-
getSortedRowModelSync,
|
|
13
9
|
useTableInstance,
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
10
|
+
getGroupedRowModel,
|
|
11
|
+
getSortedRowModel,
|
|
12
|
+
getCoreRowModel,
|
|
13
|
+
getFilteredRowModel,
|
|
14
|
+
ReactTableGenerics,
|
|
15
|
+
getFacetedRowModel,
|
|
17
16
|
} from '@tanstack/react-table';
|
|
18
17
|
import {
|
|
19
18
|
MRT_Cell,
|
|
@@ -96,7 +95,7 @@ export const MRT_TableRoot = <D extends Record<string, any> = {}>(
|
|
|
96
95
|
const [pagination, setPagination] = useState<PaginationState>({
|
|
97
96
|
pageIndex: initialState?.pagination?.pageIndex ?? 0,
|
|
98
97
|
pageSize: initialState?.pagination?.pageSize ?? 10,
|
|
99
|
-
pageCount: initialState?.pagination?.pageCount
|
|
98
|
+
pageCount: initialState?.pagination?.pageCount,
|
|
100
99
|
});
|
|
101
100
|
|
|
102
101
|
const [currentFilterFns, setCurrentFilterFns] = useState<{
|
|
@@ -110,16 +109,16 @@ export const MRT_TableRoot = <D extends Record<string, any> = {}>(
|
|
|
110
109
|
initialState?.currentFilterFns?.[c.id] ??
|
|
111
110
|
(!!c.filterSelectOptions?.length
|
|
112
111
|
? MRT_FILTER_OPTION.EQUALS
|
|
113
|
-
: MRT_FILTER_OPTION.
|
|
112
|
+
: MRT_FILTER_OPTION.FUZZY),
|
|
114
113
|
})),
|
|
115
114
|
),
|
|
116
115
|
);
|
|
117
116
|
|
|
118
117
|
const [currentGlobalFilterFn, setCurrentGlobalFilterFn] = useState<
|
|
119
|
-
MRT_FILTER_OPTION | FilterFn<
|
|
120
|
-
>(props.globalFilterFn ?? MRT_FILTER_OPTION.
|
|
118
|
+
MRT_FILTER_OPTION | FilterFn<ReactTableGenerics> | string | number | symbol
|
|
119
|
+
>(props.globalFilterFn ?? MRT_FILTER_OPTION.FUZZY);
|
|
121
120
|
|
|
122
|
-
const table = useMemo(() => createTable()
|
|
121
|
+
const table = useMemo(() => createTable(), []);
|
|
123
122
|
|
|
124
123
|
const displayColumns = useMemo(
|
|
125
124
|
() =>
|
|
@@ -129,20 +128,19 @@ export const MRT_TableRoot = <D extends Record<string, any> = {}>(
|
|
|
129
128
|
createDisplayColumn(table, {
|
|
130
129
|
Cell: ({ cell }) => (
|
|
131
130
|
<MRT_ToggleRowActionMenuButton
|
|
132
|
-
row={cell.row as
|
|
131
|
+
row={cell.row as any}
|
|
133
132
|
tableInstance={tableInstance}
|
|
134
133
|
/>
|
|
135
134
|
),
|
|
136
135
|
header: props.localization?.actions,
|
|
137
136
|
id: 'mrt-row-actions',
|
|
138
|
-
|
|
139
|
-
width: 60,
|
|
137
|
+
size: 60,
|
|
140
138
|
}),
|
|
141
|
-
(props.
|
|
139
|
+
(props.enableExpanding || props.enableGrouping) &&
|
|
142
140
|
createDisplayColumn(table, {
|
|
143
141
|
Cell: ({ cell }) => (
|
|
144
142
|
<MRT_ExpandButton
|
|
145
|
-
row={cell.row as
|
|
143
|
+
row={cell.row as any}
|
|
146
144
|
tableInstance={tableInstance}
|
|
147
145
|
/>
|
|
148
146
|
),
|
|
@@ -152,14 +150,13 @@ export const MRT_TableRoot = <D extends Record<string, any> = {}>(
|
|
|
152
150
|
) : null,
|
|
153
151
|
header: props.localization?.expand,
|
|
154
152
|
id: 'mrt-expand',
|
|
155
|
-
|
|
156
|
-
width: 40,
|
|
153
|
+
size: 50,
|
|
157
154
|
}),
|
|
158
155
|
props.enableRowSelection &&
|
|
159
156
|
createDisplayColumn(table, {
|
|
160
157
|
Cell: ({ cell }) => (
|
|
161
158
|
<MRT_SelectCheckbox
|
|
162
|
-
row={cell.row as
|
|
159
|
+
row={cell.row as any}
|
|
163
160
|
tableInstance={tableInstance}
|
|
164
161
|
/>
|
|
165
162
|
),
|
|
@@ -169,8 +166,7 @@ export const MRT_TableRoot = <D extends Record<string, any> = {}>(
|
|
|
169
166
|
) : null,
|
|
170
167
|
header: props.localization?.select,
|
|
171
168
|
id: 'mrt-select',
|
|
172
|
-
|
|
173
|
-
width: 40,
|
|
169
|
+
size: 50,
|
|
174
170
|
}),
|
|
175
171
|
props.enableRowNumbers &&
|
|
176
172
|
createDisplayColumn(table, {
|
|
@@ -178,16 +174,14 @@ export const MRT_TableRoot = <D extends Record<string, any> = {}>(
|
|
|
178
174
|
Header: () => props.localization?.rowNumber,
|
|
179
175
|
header: props.localization?.rowNumbers,
|
|
180
176
|
id: 'mrt-row-numbers',
|
|
181
|
-
|
|
182
|
-
width: 40,
|
|
183
|
-
minWidth: 40,
|
|
177
|
+
size: 50,
|
|
184
178
|
}),
|
|
185
179
|
].filter(Boolean),
|
|
186
180
|
[
|
|
187
181
|
props.editingMode,
|
|
188
182
|
props.enableEditing,
|
|
189
183
|
props.enableExpandAll,
|
|
190
|
-
props.
|
|
184
|
+
props.enableExpanding,
|
|
191
185
|
props.enableGrouping,
|
|
192
186
|
props.enableRowActions,
|
|
193
187
|
props.enableRowNumbers,
|
|
@@ -199,21 +193,21 @@ export const MRT_TableRoot = <D extends Record<string, any> = {}>(
|
|
|
199
193
|
);
|
|
200
194
|
|
|
201
195
|
const columns = useMemo(
|
|
202
|
-
() =>
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
column
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
] as ColumnDef<D>[]),
|
|
196
|
+
() => [
|
|
197
|
+
...displayColumns,
|
|
198
|
+
...props.columns.map((column) =>
|
|
199
|
+
column.columns
|
|
200
|
+
? createGroup(table, column as any, currentFilterFns)
|
|
201
|
+
: createDataColumn(table, column as any, currentFilterFns),
|
|
202
|
+
),
|
|
203
|
+
],
|
|
211
204
|
[table, props.columns, currentFilterFns],
|
|
212
205
|
);
|
|
213
206
|
|
|
214
|
-
const data: D[
|
|
207
|
+
const data: D[] = useMemo(
|
|
215
208
|
() =>
|
|
216
|
-
props.isLoading
|
|
209
|
+
(props.state?.isLoading || props.state?.showSkeletons) &&
|
|
210
|
+
!props.data.length
|
|
217
211
|
? [...Array(10).fill(null)].map(() =>
|
|
218
212
|
Object.assign(
|
|
219
213
|
{},
|
|
@@ -225,30 +219,31 @@ export const MRT_TableRoot = <D extends Record<string, any> = {}>(
|
|
|
225
219
|
),
|
|
226
220
|
)
|
|
227
221
|
: props.data,
|
|
228
|
-
[props.data, props.isLoading],
|
|
222
|
+
[props.data, props.state?.isLoading, props.state?.showSkeletons],
|
|
229
223
|
);
|
|
230
224
|
|
|
231
225
|
//@ts-ignore
|
|
232
|
-
const tableInstance
|
|
226
|
+
const tableInstance = {
|
|
227
|
+
//@ts-ignore
|
|
233
228
|
...useTableInstance(table, {
|
|
234
|
-
//@ts-ignore
|
|
235
229
|
filterFns: defaultFilterFNs,
|
|
236
|
-
|
|
237
|
-
getCoreRowModel: getCoreRowModelSync(),
|
|
230
|
+
getCoreRowModel: getCoreRowModel(),
|
|
238
231
|
getExpandedRowModel: getExpandedRowModel(),
|
|
239
|
-
|
|
240
|
-
|
|
232
|
+
getFacetedRowModel: getFacetedRowModel(),
|
|
233
|
+
getFilteredRowModel: getFilteredRowModel(),
|
|
234
|
+
getGroupedRowModel: getGroupedRowModel(),
|
|
241
235
|
getPaginationRowModel: getPaginationRowModel(),
|
|
242
|
-
getSortedRowModel:
|
|
243
|
-
getSubRows: (
|
|
236
|
+
getSortedRowModel: getSortedRowModel(),
|
|
237
|
+
getSubRows: (row) => (row as MRT_Row)?.subRows,
|
|
238
|
+
//@ts-ignore
|
|
244
239
|
globalFilterFn: currentGlobalFilterFn,
|
|
245
240
|
onPaginationChange: (updater: any) =>
|
|
246
241
|
setPagination((old) => functionalUpdate(updater, old)),
|
|
247
242
|
...props,
|
|
243
|
+
//@ts-ignore
|
|
248
244
|
columns,
|
|
249
245
|
data,
|
|
250
246
|
idPrefix,
|
|
251
|
-
//@ts-ignore
|
|
252
247
|
initialState,
|
|
253
248
|
state: {
|
|
254
249
|
currentEditingCell,
|
|
@@ -264,18 +259,15 @@ export const MRT_TableRoot = <D extends Record<string, any> = {}>(
|
|
|
264
259
|
...props.state,
|
|
265
260
|
},
|
|
266
261
|
}),
|
|
267
|
-
//@ts-ignore
|
|
268
262
|
setCurrentEditingCell,
|
|
269
|
-
//@ts-ignore
|
|
270
263
|
setCurrentEditingRow,
|
|
271
264
|
setCurrentFilterFns,
|
|
272
|
-
//@ts-ignore
|
|
273
265
|
setCurrentGlobalFilterFn,
|
|
274
266
|
setIsDensePadding,
|
|
275
267
|
setIsFullScreen,
|
|
276
268
|
setShowFilters,
|
|
277
269
|
setShowGlobalFilter,
|
|
278
|
-
};
|
|
270
|
+
} as MRT_TableInstance;
|
|
279
271
|
|
|
280
272
|
useEffect(() => {
|
|
281
273
|
if (typeof window === 'undefined' || !props.enablePersistentState) {
|
|
@@ -8,16 +8,19 @@ interface Props {
|
|
|
8
8
|
|
|
9
9
|
export const MRT_LinearProgressBar: FC<Props> = ({ tableInstance }) => {
|
|
10
10
|
const {
|
|
11
|
-
options: { muiLinearProgressProps
|
|
11
|
+
options: { muiLinearProgressProps },
|
|
12
|
+
getState,
|
|
12
13
|
} = tableInstance;
|
|
13
14
|
|
|
15
|
+
const { isLoading, showProgressBars } = getState();
|
|
16
|
+
|
|
14
17
|
const linearProgressProps =
|
|
15
18
|
muiLinearProgressProps instanceof Function
|
|
16
19
|
? muiLinearProgressProps({ tableInstance })
|
|
17
20
|
: muiLinearProgressProps;
|
|
18
21
|
|
|
19
22
|
return (
|
|
20
|
-
<Collapse in={
|
|
23
|
+
<Collapse in={isLoading || showProgressBars} mountOnEnter unmountOnExit>
|
|
21
24
|
<LinearProgress
|
|
22
25
|
aria-label="Loading"
|
|
23
26
|
aria-busy="true"
|
|
@@ -11,7 +11,6 @@ export const MRT_ToolbarAlertBanner: FC<Props> = ({ tableInstance }) => {
|
|
|
11
11
|
getPrePaginationRowModel,
|
|
12
12
|
getSelectedRowModel,
|
|
13
13
|
getState,
|
|
14
|
-
toggleColumnGrouping,
|
|
15
14
|
options: {
|
|
16
15
|
localization,
|
|
17
16
|
muiTableToolbarAlertBannerProps,
|
|
@@ -57,7 +56,9 @@ export const MRT_ToolbarAlertBanner: FC<Props> = ({ tableInstance }) => {
|
|
|
57
56
|
.getAllColumns()
|
|
58
57
|
.find((column) => column.id === columnId)?.header
|
|
59
58
|
}
|
|
60
|
-
onDelete={() =>
|
|
59
|
+
onDelete={() =>
|
|
60
|
+
tableInstance.getColumn(columnId).toggleGrouping()
|
|
61
|
+
}
|
|
61
62
|
/>
|
|
62
63
|
</Fragment>
|
|
63
64
|
))}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React, { FC } from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { Box, lighten, Theme, Toolbar } from '@mui/material';
|
|
3
3
|
import { MRT_SearchTextField } from '../inputs/MRT_SearchTextField';
|
|
4
4
|
import { MRT_ToolbarInternalButtons } from './MRT_ToolbarInternalButtons';
|
|
5
5
|
import { MRT_TablePagination } from './MRT_TablePagination';
|
|
@@ -8,13 +8,11 @@ import { MRT_LinearProgressBar } from './MRT_LinearProgressBar';
|
|
|
8
8
|
import { MRT_TableInstance } from '..';
|
|
9
9
|
|
|
10
10
|
export const commonToolbarStyles = ({ theme }: { theme: Theme }) => ({
|
|
11
|
-
backgroundColor: theme.palette.background.default,
|
|
12
|
-
backgroundImage:
|
|
13
|
-
theme.palette.common.white,
|
|
14
|
-
0.05,
|
|
15
|
-
)},${alpha(theme.palette.common.white, 0.05)})`,
|
|
11
|
+
backgroundColor: lighten(theme.palette.background.default, 0.04),
|
|
12
|
+
backgroundImage: 'none',
|
|
16
13
|
display: 'grid',
|
|
17
14
|
p: '0 !important',
|
|
15
|
+
transition: 'all 0.2s ease-in-out',
|
|
18
16
|
width: '100%',
|
|
19
17
|
zIndex: 1,
|
|
20
18
|
});
|