material-react-table 0.6.9 → 0.7.0-alpha.10
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/README.md +29 -19
- package/dist/MaterialReactTable.d.ts +314 -108
- package/dist/body/MRT_TableBody.d.ts +3 -0
- package/dist/body/MRT_TableBodyCell.d.ts +2 -11
- package/dist/body/MRT_TableBodyRow.d.ts +3 -1
- package/dist/body/MRT_TableDetailPanel.d.ts +2 -1
- package/dist/buttons/MRT_CopyButton.d.ts +2 -1
- package/dist/buttons/MRT_EditActionButtons.d.ts +2 -1
- package/dist/buttons/MRT_ExpandAllButton.d.ts +2 -0
- package/dist/buttons/MRT_ExpandButton.d.ts +2 -1
- package/dist/buttons/MRT_FullScreenToggleButton.d.ts +2 -0
- package/dist/buttons/MRT_ShowHideColumnsButton.d.ts +2 -0
- package/dist/buttons/MRT_ToggleColumnActionMenuButton.d.ts +3 -2
- package/dist/buttons/MRT_ToggleDensePaddingButton.d.ts +2 -0
- package/dist/buttons/MRT_ToggleFiltersButton.d.ts +2 -0
- package/dist/buttons/MRT_ToggleRowActionMenuButton.d.ts +2 -1
- package/dist/buttons/MRT_ToggleSearchButton.d.ts +2 -0
- package/dist/enums.d.ts +2 -1
- package/dist/filtersFNs.d.ts +13 -5
- package/dist/footer/MRT_TableFooter.d.ts +3 -0
- package/dist/footer/MRT_TableFooterCell.d.ts +3 -2
- package/dist/footer/MRT_TableFooterRow.d.ts +2 -1
- package/dist/head/MRT_TableHead.d.ts +3 -0
- package/dist/head/MRT_TableHeadCell.d.ts +4 -18
- package/dist/head/MRT_TableHeadRow.d.ts +2 -1
- package/dist/icons.d.ts +1 -1
- package/dist/inputs/MRT_EditCellTextField.d.ts +2 -1
- package/dist/inputs/MRT_FilterTextField.d.ts +3 -2
- package/dist/inputs/MRT_SearchTextField.d.ts +2 -0
- package/dist/inputs/MRT_SelectCheckbox.d.ts +2 -1
- package/dist/localization.d.ts +10 -2
- package/dist/material-react-table.cjs.development.js +2286 -2459
- 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 +2288 -2461
- package/dist/material-react-table.esm.js.map +1 -1
- package/dist/menus/MRT_ColumnActionMenu.d.ts +3 -2
- package/dist/menus/MRT_FilterTypeMenu.d.ts +4 -3
- package/dist/menus/MRT_RowActionMenu.d.ts +3 -2
- package/dist/menus/MRT_ShowHideColumnsMenu.d.ts +2 -0
- package/dist/menus/MRT_ShowHideColumnsMenuItems.d.ts +2 -1
- package/dist/table/MRT_Table.d.ts +3 -0
- package/dist/table/MRT_TableContainer.d.ts +2 -0
- package/dist/table/MRT_TablePaper.d.ts +7 -0
- package/dist/table/MRT_TableRoot.d.ts +3 -0
- package/dist/toolbar/MRT_LinearProgressBar.d.ts +2 -0
- package/dist/toolbar/MRT_TablePagination.d.ts +2 -0
- package/dist/toolbar/MRT_ToolbarAlertBanner.d.ts +2 -0
- package/dist/toolbar/MRT_ToolbarBottom.d.ts +2 -0
- package/dist/toolbar/MRT_ToolbarInternalButtons.d.ts +2 -0
- package/dist/toolbar/MRT_ToolbarTop.d.ts +4 -2
- package/dist/utils.d.ts +12 -2
- package/package.json +29 -30
- package/src/MaterialReactTable.tsx +614 -297
- package/src/body/MRT_TableBody.tsx +26 -22
- package/src/body/MRT_TableBodyCell.tsx +79 -55
- package/src/body/MRT_TableBodyRow.tsx +37 -67
- package/src/body/MRT_TableDetailPanel.tsx +21 -17
- package/src/buttons/MRT_CopyButton.tsx +34 -10
- package/src/buttons/MRT_EditActionButtons.tsx +16 -13
- package/src/buttons/MRT_ExpandAllButton.tsx +36 -28
- package/src/buttons/MRT_ExpandButton.tsx +35 -41
- package/src/buttons/MRT_FullScreenToggleButton.tsx +18 -11
- package/src/buttons/MRT_ShowHideColumnsButton.tsx +18 -7
- package/src/buttons/MRT_ToggleColumnActionMenuButton.tsx +22 -11
- package/src/buttons/MRT_ToggleDensePaddingButton.tsx +18 -11
- package/src/buttons/MRT_ToggleFiltersButton.tsx +16 -9
- package/src/buttons/MRT_ToggleRowActionMenuButton.tsx +31 -26
- package/src/buttons/MRT_ToggleSearchButton.tsx +24 -12
- package/src/enums.ts +2 -1
- package/src/filtersFNs.ts +17 -3
- package/src/footer/MRT_TableFooter.tsx +24 -8
- package/src/footer/MRT_TableFooterCell.tsx +34 -26
- package/src/footer/MRT_TableFooterRow.tsx +21 -39
- package/src/head/MRT_TableHead.tsx +24 -8
- package/src/head/MRT_TableHeadCell.tsx +185 -142
- package/src/head/MRT_TableHeadRow.tsx +16 -93
- package/src/icons.ts +3 -3
- package/src/inputs/MRT_EditCellTextField.tsx +39 -24
- package/src/inputs/MRT_FilterTextField.tsx +53 -39
- package/src/inputs/MRT_SearchTextField.tsx +71 -25
- package/src/inputs/MRT_SelectCheckbox.tsx +42 -30
- package/src/localization.ts +20 -4
- package/src/menus/MRT_ColumnActionMenu.tsx +129 -69
- package/src/menus/MRT_FilterTypeMenu.tsx +55 -23
- package/src/menus/MRT_RowActionMenu.tsx +22 -15
- package/src/menus/MRT_ShowHideColumnsMenu.tsx +52 -20
- package/src/menus/MRT_ShowHideColumnsMenuItems.tsx +27 -17
- package/src/table/MRT_Table.tsx +25 -15
- package/src/table/MRT_TableContainer.tsx +106 -45
- package/src/table/MRT_TablePaper.tsx +65 -0
- package/src/table/MRT_TableRoot.tsx +239 -0
- package/src/toolbar/MRT_LinearProgressBar.tsx +10 -7
- package/src/toolbar/MRT_TablePagination.tsx +33 -19
- package/src/toolbar/MRT_ToolbarAlertBanner.tsx +33 -20
- package/src/toolbar/MRT_ToolbarBottom.tsx +32 -21
- package/src/toolbar/MRT_ToolbarInternalButtons.tsx +34 -20
- package/src/toolbar/MRT_ToolbarTop.tsx +36 -29
- package/src/utils.ts +37 -8
- package/dist/head/MRT_TableHeadCellActions.d.ts +0 -5
- package/dist/table/MRT_TableSpacerCell.d.ts +0 -6
- package/dist/useMRT.d.ts +0 -27
- package/src/@types/faker.d.ts +0 -4
- package/src/@types/react-table-config.d.ts +0 -53
- package/src/head/MRT_TableHeadCellActions.tsx +0 -29
- package/src/table/MRT_TableSpacerCell.tsx +0 -20
- package/src/useMRT.tsx +0 -215
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import React, { FC, useEffect } from 'react';
|
|
2
|
+
import { Paper } from '@mui/material';
|
|
3
|
+
import { MRT_ToolbarTop } from '../toolbar/MRT_ToolbarTop';
|
|
4
|
+
import { MRT_ToolbarBottom } from '../toolbar/MRT_ToolbarBottom';
|
|
5
|
+
import { MRT_TableContainer } from './MRT_TableContainer';
|
|
6
|
+
import { MRT_TableInstance } from '..';
|
|
7
|
+
|
|
8
|
+
interface Props {
|
|
9
|
+
tableInstance: MRT_TableInstance;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export const MRT_TablePaper: FC<Props> = ({ tableInstance }) => {
|
|
13
|
+
const {
|
|
14
|
+
getState,
|
|
15
|
+
options: { hideToolbarBottom, hideToolbarTop, muiTablePaperProps },
|
|
16
|
+
} = tableInstance;
|
|
17
|
+
|
|
18
|
+
const { isFullScreen } = getState();
|
|
19
|
+
|
|
20
|
+
useEffect(() => {
|
|
21
|
+
if (typeof window !== 'undefined') {
|
|
22
|
+
if (isFullScreen) {
|
|
23
|
+
document.body.style.overflow = 'hidden';
|
|
24
|
+
} else {
|
|
25
|
+
document.body.style.overflow = 'auto';
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}, [isFullScreen]);
|
|
29
|
+
|
|
30
|
+
const tablePaperProps =
|
|
31
|
+
muiTablePaperProps instanceof Function
|
|
32
|
+
? muiTablePaperProps({ tableInstance })
|
|
33
|
+
: muiTablePaperProps;
|
|
34
|
+
|
|
35
|
+
return (
|
|
36
|
+
<Paper
|
|
37
|
+
elevation={2}
|
|
38
|
+
{...tablePaperProps}
|
|
39
|
+
sx={{
|
|
40
|
+
transition: 'all 0.2s ease-in-out',
|
|
41
|
+
...tablePaperProps?.sx,
|
|
42
|
+
}}
|
|
43
|
+
style={{
|
|
44
|
+
height: isFullScreen ? '100%' : undefined,
|
|
45
|
+
left: isFullScreen ? '0' : undefined,
|
|
46
|
+
margin: isFullScreen ? '0' : undefined,
|
|
47
|
+
maxHeight: isFullScreen ? '100%' : undefined,
|
|
48
|
+
maxWidth: isFullScreen ? '100%' : undefined,
|
|
49
|
+
overflowY: !isFullScreen ? 'hidden' : undefined,
|
|
50
|
+
position: isFullScreen ? 'fixed' : undefined,
|
|
51
|
+
right: isFullScreen ? '0' : undefined,
|
|
52
|
+
top: isFullScreen ? '0' : undefined,
|
|
53
|
+
width: isFullScreen ? '100vw' : undefined,
|
|
54
|
+
zIndex: isFullScreen ? 1200 : 1,
|
|
55
|
+
bottom: isFullScreen ? '0' : undefined,
|
|
56
|
+
}}
|
|
57
|
+
>
|
|
58
|
+
{!hideToolbarTop && <MRT_ToolbarTop tableInstance={tableInstance} />}
|
|
59
|
+
<MRT_TableContainer tableInstance={tableInstance} />
|
|
60
|
+
{!hideToolbarBottom && (
|
|
61
|
+
<MRT_ToolbarBottom tableInstance={tableInstance} />
|
|
62
|
+
)}
|
|
63
|
+
</Paper>
|
|
64
|
+
);
|
|
65
|
+
};
|
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
import {
|
|
2
|
+
columnFilterRowsFn,
|
|
3
|
+
createTable,
|
|
4
|
+
expandRowsFn,
|
|
5
|
+
functionalUpdate,
|
|
6
|
+
globalFilterRowsFn,
|
|
7
|
+
groupRowsFn,
|
|
8
|
+
paginateRowsFn,
|
|
9
|
+
PaginationState,
|
|
10
|
+
sortRowsFn,
|
|
11
|
+
Table,
|
|
12
|
+
useTable,
|
|
13
|
+
} from '@tanstack/react-table';
|
|
14
|
+
import React, { useMemo, useState } from 'react';
|
|
15
|
+
import {
|
|
16
|
+
MRT_ColumnInterface,
|
|
17
|
+
MRT_FilterType,
|
|
18
|
+
MRT_Row,
|
|
19
|
+
MRT_TableInstance,
|
|
20
|
+
} from '..';
|
|
21
|
+
import { MRT_ExpandAllButton } from '../buttons/MRT_ExpandAllButton';
|
|
22
|
+
import { MRT_ExpandButton } from '../buttons/MRT_ExpandButton';
|
|
23
|
+
import { MRT_ToggleRowActionMenuButton } from '../buttons/MRT_ToggleRowActionMenuButton';
|
|
24
|
+
import { MRT_SelectCheckbox } from '../inputs/MRT_SelectCheckbox';
|
|
25
|
+
import { MaterialReactTableProps } from '../MaterialReactTable';
|
|
26
|
+
import { MRT_TablePaper } from './MRT_TablePaper';
|
|
27
|
+
import {
|
|
28
|
+
createDataColumn,
|
|
29
|
+
createDisplayColumn,
|
|
30
|
+
createGroup,
|
|
31
|
+
getAllLeafColumnDefs,
|
|
32
|
+
} from '../utils';
|
|
33
|
+
import { defaultFilterFNs } from '../filtersFNs';
|
|
34
|
+
import { MRT_FILTER_TYPE } from '../enums';
|
|
35
|
+
|
|
36
|
+
export const MRT_TableRoot = <D extends Record<string, any> = {}>(
|
|
37
|
+
props: MaterialReactTableProps<D>,
|
|
38
|
+
) => {
|
|
39
|
+
const idPrefix = useMemo(
|
|
40
|
+
() => props.idPrefix ?? Math.random().toString(36).substring(2, 9),
|
|
41
|
+
[props.idPrefix],
|
|
42
|
+
);
|
|
43
|
+
const [currentEditingRow, setCurrentEditingRow] = useState<MRT_Row | null>(
|
|
44
|
+
null,
|
|
45
|
+
);
|
|
46
|
+
const [isDensePadding, setIsDensePadding] = useState(
|
|
47
|
+
props.initialState?.isDensePadding ?? false,
|
|
48
|
+
);
|
|
49
|
+
const [isFullScreen, setIsFullScreen] = useState(
|
|
50
|
+
props.initialState?.isFullScreen ?? false,
|
|
51
|
+
);
|
|
52
|
+
const [showFilters, setShowFilters] = useState(
|
|
53
|
+
props.initialState?.showFilters ?? false,
|
|
54
|
+
);
|
|
55
|
+
const [showSearch, setShowSearch] = useState(
|
|
56
|
+
props.initialState?.showSearch ?? false,
|
|
57
|
+
);
|
|
58
|
+
const [pagination, setPagination] = useState<PaginationState>({
|
|
59
|
+
pageIndex: props.initialState?.pagination?.pageIndex ?? 0,
|
|
60
|
+
pageSize: props.initialState?.pagination?.pageSize ?? 10,
|
|
61
|
+
pageCount: props.initialState?.pagination?.pageCount ?? -1,
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
const [currentFilterTypes, setCurrentFilterTypes] = useState<{
|
|
65
|
+
[key: string]: MRT_FilterType;
|
|
66
|
+
}>(() =>
|
|
67
|
+
Object.assign(
|
|
68
|
+
{},
|
|
69
|
+
...getAllLeafColumnDefs(props.columns as MRT_ColumnInterface[]).map(
|
|
70
|
+
(c) => ({
|
|
71
|
+
[c.id as string]:
|
|
72
|
+
c.filter ??
|
|
73
|
+
props?.initialState?.columnFilters?.[c.id as any] ??
|
|
74
|
+
(!!c.filterSelectOptions?.length
|
|
75
|
+
? MRT_FILTER_TYPE.EQUALS
|
|
76
|
+
: MRT_FILTER_TYPE.BEST_MATCH),
|
|
77
|
+
}),
|
|
78
|
+
),
|
|
79
|
+
),
|
|
80
|
+
);
|
|
81
|
+
|
|
82
|
+
const [currentGlobalFilterType, setCurrentGlobalFilterType] = useState(
|
|
83
|
+
props.globalFilterType ?? MRT_FILTER_TYPE.BEST_MATCH_FIRST,
|
|
84
|
+
);
|
|
85
|
+
|
|
86
|
+
const table = useMemo(
|
|
87
|
+
() => createTable<{ Row: D }>(),
|
|
88
|
+
[],
|
|
89
|
+
) as unknown as Table<D>;
|
|
90
|
+
|
|
91
|
+
const displayColumns = useMemo(
|
|
92
|
+
() =>
|
|
93
|
+
[
|
|
94
|
+
(props.enableRowActions || props.enableEditing) &&
|
|
95
|
+
createDisplayColumn(table, {
|
|
96
|
+
Cell: ({ cell }) => (
|
|
97
|
+
<MRT_ToggleRowActionMenuButton
|
|
98
|
+
row={cell.row as any}
|
|
99
|
+
tableInstance={tableInstance}
|
|
100
|
+
/>
|
|
101
|
+
),
|
|
102
|
+
header: props.localization?.actions,
|
|
103
|
+
id: 'mrt-row-actions',
|
|
104
|
+
maxWidth: 60,
|
|
105
|
+
width: 60,
|
|
106
|
+
}),
|
|
107
|
+
(props.enableExpanded || props.enableGrouping) &&
|
|
108
|
+
createDisplayColumn(table, {
|
|
109
|
+
Cell: ({ cell }) => (
|
|
110
|
+
<MRT_ExpandButton
|
|
111
|
+
row={cell.row as any}
|
|
112
|
+
tableInstance={tableInstance}
|
|
113
|
+
/>
|
|
114
|
+
),
|
|
115
|
+
Header: () =>
|
|
116
|
+
props.enableExpandAll ? (
|
|
117
|
+
<MRT_ExpandAllButton tableInstance={tableInstance} />
|
|
118
|
+
) : null,
|
|
119
|
+
header: props.localization?.expand,
|
|
120
|
+
id: 'mrt-expand',
|
|
121
|
+
maxWidth: 40,
|
|
122
|
+
width: 40,
|
|
123
|
+
}),
|
|
124
|
+
props.enableRowSelection &&
|
|
125
|
+
createDisplayColumn(table, {
|
|
126
|
+
Cell: ({ cell }) => (
|
|
127
|
+
<MRT_SelectCheckbox
|
|
128
|
+
row={cell.row as any}
|
|
129
|
+
tableInstance={tableInstance}
|
|
130
|
+
/>
|
|
131
|
+
),
|
|
132
|
+
Header: () =>
|
|
133
|
+
props.enableSelectAll ? (
|
|
134
|
+
<MRT_SelectCheckbox selectAll tableInstance={tableInstance} />
|
|
135
|
+
) : null,
|
|
136
|
+
header: props.localization?.select,
|
|
137
|
+
id: 'mrt-select',
|
|
138
|
+
maxWidth: 40,
|
|
139
|
+
width: 40,
|
|
140
|
+
}),
|
|
141
|
+
props.enableRowNumbers &&
|
|
142
|
+
createDisplayColumn(table, {
|
|
143
|
+
Cell: ({ cell }) => cell.row.index + 1,
|
|
144
|
+
Header: () => props.localization?.rowNumber,
|
|
145
|
+
header: props.localization?.rowNumbers,
|
|
146
|
+
id: 'mrt-row-numbers',
|
|
147
|
+
maxWidth: 40,
|
|
148
|
+
width: 40,
|
|
149
|
+
minWidth: 40,
|
|
150
|
+
}),
|
|
151
|
+
].filter(Boolean),
|
|
152
|
+
[
|
|
153
|
+
table,
|
|
154
|
+
props.enableExpandAll,
|
|
155
|
+
props.enableExpanded,
|
|
156
|
+
props.enableRowActions,
|
|
157
|
+
props.enableGrouping,
|
|
158
|
+
props.enableEditing,
|
|
159
|
+
props.enableRowNumbers,
|
|
160
|
+
props.enableRowSelection,
|
|
161
|
+
props.enableSelectAll,
|
|
162
|
+
props.localization,
|
|
163
|
+
],
|
|
164
|
+
);
|
|
165
|
+
|
|
166
|
+
const columns = useMemo(
|
|
167
|
+
() =>
|
|
168
|
+
table.createColumns([
|
|
169
|
+
...displayColumns,
|
|
170
|
+
...props.columns.map((column) =>
|
|
171
|
+
column.columns
|
|
172
|
+
? createGroup(table, column, currentFilterTypes)
|
|
173
|
+
: createDataColumn(table, column, currentFilterTypes),
|
|
174
|
+
),
|
|
175
|
+
] as any),
|
|
176
|
+
[table, props.columns, currentFilterTypes],
|
|
177
|
+
);
|
|
178
|
+
|
|
179
|
+
const data = useMemo(
|
|
180
|
+
() =>
|
|
181
|
+
props.isLoading && !props.data.length
|
|
182
|
+
? [...Array(10).fill(null)].map((_) =>
|
|
183
|
+
Object.assign(
|
|
184
|
+
{},
|
|
185
|
+
...getAllLeafColumnDefs(
|
|
186
|
+
props.columns as MRT_ColumnInterface[],
|
|
187
|
+
).map((c) => ({
|
|
188
|
+
[c.id]: null,
|
|
189
|
+
})),
|
|
190
|
+
),
|
|
191
|
+
)
|
|
192
|
+
: props.data,
|
|
193
|
+
[props.data, props.isLoading],
|
|
194
|
+
);
|
|
195
|
+
|
|
196
|
+
//@ts-ignore
|
|
197
|
+
const tableInstance: MRT_TableInstance<{}> = useTable(table, {
|
|
198
|
+
...props,
|
|
199
|
+
columnFilterRowsFn: columnFilterRowsFn,
|
|
200
|
+
columns,
|
|
201
|
+
data,
|
|
202
|
+
debugAll: false,
|
|
203
|
+
expandRowsFn: expandRowsFn,
|
|
204
|
+
//@ts-ignore
|
|
205
|
+
filterTypes: defaultFilterFNs,
|
|
206
|
+
getSubRows: props.getSubRows ?? ((originalRow: D) => originalRow.subRows),
|
|
207
|
+
globalFilterRowsFn: globalFilterRowsFn,
|
|
208
|
+
globalFilterType: currentGlobalFilterType,
|
|
209
|
+
groupRowsFn: groupRowsFn,
|
|
210
|
+
idPrefix,
|
|
211
|
+
//@ts-ignore
|
|
212
|
+
initialState: props.initialState,
|
|
213
|
+
onPaginationChange: (updater: any) =>
|
|
214
|
+
setPagination((old) => functionalUpdate(updater, old)),
|
|
215
|
+
paginateRowsFn: paginateRowsFn,
|
|
216
|
+
setCurrentEditingRow,
|
|
217
|
+
setCurrentFilterTypes,
|
|
218
|
+
setCurrentGlobalFilterType,
|
|
219
|
+
setIsDensePadding,
|
|
220
|
+
setIsFullScreen,
|
|
221
|
+
setShowFilters,
|
|
222
|
+
setShowSearch,
|
|
223
|
+
sortRowsFn,
|
|
224
|
+
state: {
|
|
225
|
+
currentEditingRow,
|
|
226
|
+
currentFilterTypes,
|
|
227
|
+
currentGlobalFilterType,
|
|
228
|
+
isDensePadding,
|
|
229
|
+
isFullScreen,
|
|
230
|
+
//@ts-ignore
|
|
231
|
+
pagination,
|
|
232
|
+
showFilters,
|
|
233
|
+
showSearch,
|
|
234
|
+
...props.state,
|
|
235
|
+
},
|
|
236
|
+
});
|
|
237
|
+
|
|
238
|
+
return <MRT_TablePaper tableInstance={tableInstance} />;
|
|
239
|
+
};
|
|
@@ -1,20 +1,23 @@
|
|
|
1
1
|
import React, { FC } from 'react';
|
|
2
2
|
import { Collapse, LinearProgress } from '@mui/material';
|
|
3
|
-
import {
|
|
3
|
+
import { MRT_TableInstance } from '..';
|
|
4
4
|
|
|
5
|
-
interface Props {
|
|
5
|
+
interface Props {
|
|
6
|
+
tableInstance: MRT_TableInstance;
|
|
7
|
+
}
|
|
6
8
|
|
|
7
|
-
export const MRT_LinearProgressBar: FC<Props> = () => {
|
|
8
|
-
const {
|
|
9
|
-
|
|
9
|
+
export const MRT_LinearProgressBar: FC<Props> = ({ tableInstance }) => {
|
|
10
|
+
const {
|
|
11
|
+
options: { muiLinearProgressProps, isReloading, isLoading },
|
|
12
|
+
} = tableInstance;
|
|
10
13
|
|
|
11
14
|
const linearProgressProps =
|
|
12
15
|
muiLinearProgressProps instanceof Function
|
|
13
|
-
? muiLinearProgressProps(tableInstance)
|
|
16
|
+
? muiLinearProgressProps({ tableInstance })
|
|
14
17
|
: muiLinearProgressProps;
|
|
15
18
|
|
|
16
19
|
return (
|
|
17
|
-
<Collapse in={
|
|
20
|
+
<Collapse in={isReloading || isLoading} unmountOnExit>
|
|
18
21
|
<LinearProgress
|
|
19
22
|
aria-label="Loading"
|
|
20
23
|
aria-busy="true"
|
|
@@ -1,37 +1,51 @@
|
|
|
1
1
|
import React, { ChangeEvent, FC } from 'react';
|
|
2
2
|
import { TablePagination } from '@mui/material';
|
|
3
|
-
import {
|
|
3
|
+
import { MRT_TableInstance } from '..';
|
|
4
4
|
|
|
5
|
-
interface Props {
|
|
5
|
+
interface Props {
|
|
6
|
+
tableInstance: MRT_TableInstance;
|
|
7
|
+
}
|
|
6
8
|
|
|
7
|
-
export const MRT_TablePagination: FC<Props> = () => {
|
|
8
|
-
const {
|
|
9
|
+
export const MRT_TablePagination: FC<Props> = ({ tableInstance }) => {
|
|
10
|
+
const {
|
|
11
|
+
getPrePaginationRowModel,
|
|
12
|
+
getState,
|
|
13
|
+
setPageIndex,
|
|
14
|
+
setPageSize,
|
|
15
|
+
options: { muiTablePaginationProps },
|
|
16
|
+
} = tableInstance;
|
|
17
|
+
|
|
18
|
+
const {
|
|
19
|
+
pagination: { pageSize = 10, pageIndex = 0 },
|
|
20
|
+
} = getState();
|
|
9
21
|
|
|
10
22
|
const tablePaginationProps =
|
|
11
23
|
muiTablePaginationProps instanceof Function
|
|
12
|
-
? muiTablePaginationProps(tableInstance)
|
|
24
|
+
? muiTablePaginationProps({ tableInstance })
|
|
13
25
|
: muiTablePaginationProps;
|
|
14
26
|
|
|
15
27
|
const handleChangeRowsPerPage = (event: ChangeEvent<HTMLInputElement>) => {
|
|
16
|
-
|
|
17
|
-
tableInstance.gotoPage(0);
|
|
28
|
+
setPageSize(+event.target.value);
|
|
18
29
|
};
|
|
19
30
|
|
|
31
|
+
const showFirstLastPageButtons =
|
|
32
|
+
getPrePaginationRowModel().rows.length / pageSize > 2;
|
|
33
|
+
|
|
20
34
|
return (
|
|
21
35
|
<TablePagination
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
36
|
+
SelectProps={{
|
|
37
|
+
sx: { m: '0 1rem 0 1ch' },
|
|
38
|
+
MenuProps: { MenuListProps: { disablePadding: true } },
|
|
39
|
+
}}
|
|
40
|
+
component="div"
|
|
41
|
+
count={getPrePaginationRowModel().rows.length}
|
|
42
|
+
onPageChange={(_: any, newPage: number) => setPageIndex(newPage)}
|
|
25
43
|
onRowsPerPageChange={handleChangeRowsPerPage}
|
|
26
|
-
page={
|
|
27
|
-
rowsPerPage={
|
|
28
|
-
|
|
29
|
-
showFirstButton={
|
|
30
|
-
|
|
31
|
-
}
|
|
32
|
-
showLastButton={
|
|
33
|
-
tableInstance.rows.length / tableInstance.state.pageSize > 2
|
|
34
|
-
}
|
|
44
|
+
page={pageIndex}
|
|
45
|
+
rowsPerPage={pageSize}
|
|
46
|
+
rowsPerPageOptions={[5, 10, 15, 20, 25, 30, 50, 100]}
|
|
47
|
+
showFirstButton={showFirstLastPageButtons}
|
|
48
|
+
showLastButton={showFirstLastPageButtons}
|
|
35
49
|
{...tablePaginationProps}
|
|
36
50
|
sx={{
|
|
37
51
|
m: '0 0.5rem',
|
|
@@ -1,51 +1,63 @@
|
|
|
1
1
|
import React, { FC, Fragment } from 'react';
|
|
2
2
|
import { Alert, Box, Chip, Collapse, useMediaQuery } from '@mui/material';
|
|
3
|
-
import {
|
|
3
|
+
import { MRT_TableInstance } from '..';
|
|
4
4
|
|
|
5
|
-
interface Props {
|
|
5
|
+
interface Props {
|
|
6
|
+
tableInstance: MRT_TableInstance;
|
|
7
|
+
}
|
|
6
8
|
|
|
7
|
-
export const MRT_ToolbarAlertBanner: FC<Props> = () => {
|
|
9
|
+
export const MRT_ToolbarAlertBanner: FC<Props> = ({ tableInstance }) => {
|
|
8
10
|
const {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
11
|
+
getPrePaginationRowModel,
|
|
12
|
+
getSelectedRowModel,
|
|
13
|
+
getState,
|
|
14
|
+
toggleColumnGrouping,
|
|
15
|
+
options: {
|
|
16
|
+
localization,
|
|
17
|
+
muiTableToolbarAlertBannerProps,
|
|
18
|
+
positionToolbarActions,
|
|
19
|
+
positionToolbarAlertBanner,
|
|
20
|
+
renderToolbarCustomActions,
|
|
21
|
+
},
|
|
22
|
+
} = tableInstance;
|
|
23
|
+
|
|
24
|
+
const { grouping } = getState();
|
|
16
25
|
|
|
17
26
|
const isMobile = useMediaQuery('(max-width:720px)');
|
|
18
27
|
|
|
19
28
|
const alertProps =
|
|
20
29
|
muiTableToolbarAlertBannerProps instanceof Function
|
|
21
|
-
? muiTableToolbarAlertBannerProps(tableInstance)
|
|
30
|
+
? muiTableToolbarAlertBannerProps({ tableInstance })
|
|
22
31
|
: muiTableToolbarAlertBannerProps;
|
|
23
32
|
|
|
24
33
|
const selectMessage =
|
|
25
|
-
|
|
34
|
+
getSelectedRowModel().rows.length > 0
|
|
26
35
|
? localization.selectedCountOfRowCountRowsSelected
|
|
27
36
|
?.replace(
|
|
28
37
|
'{selectedCount}',
|
|
29
|
-
|
|
38
|
+
getSelectedRowModel().rows.length.toString(),
|
|
39
|
+
)
|
|
40
|
+
?.replace(
|
|
41
|
+
'{rowCount}',
|
|
42
|
+
getPrePaginationRowModel().rows.length.toString(),
|
|
30
43
|
)
|
|
31
|
-
?.replace('{rowCount}', tableInstance.flatRows.length.toString())
|
|
32
44
|
: null;
|
|
33
45
|
|
|
34
46
|
const groupedByMessage =
|
|
35
|
-
|
|
47
|
+
grouping.length > 0 ? (
|
|
36
48
|
<span>
|
|
37
49
|
{localization.groupedBy}{' '}
|
|
38
|
-
{
|
|
50
|
+
{grouping.map((columnId, index) => (
|
|
39
51
|
<Fragment key={`${index}-${columnId}`}>
|
|
40
52
|
{index > 0 ? localization.thenBy : ''}
|
|
41
53
|
<Chip
|
|
42
54
|
color="secondary"
|
|
43
55
|
label={
|
|
44
|
-
tableInstance
|
|
45
|
-
(
|
|
46
|
-
|
|
56
|
+
tableInstance
|
|
57
|
+
.getAllColumns()
|
|
58
|
+
.find((column) => column.id === columnId)?.header
|
|
47
59
|
}
|
|
48
|
-
onDelete={() =>
|
|
60
|
+
onDelete={() => toggleColumnGrouping(columnId)}
|
|
49
61
|
/>
|
|
50
62
|
</Fragment>
|
|
51
63
|
))}
|
|
@@ -84,6 +96,7 @@ export const MRT_ToolbarAlertBanner: FC<Props> = () => {
|
|
|
84
96
|
>
|
|
85
97
|
<Box sx={{ p: '0.5rem 1rem' }}>
|
|
86
98
|
{selectMessage}
|
|
99
|
+
<br />
|
|
87
100
|
{groupedByMessage}
|
|
88
101
|
</Box>
|
|
89
102
|
</Alert>
|
|
@@ -1,56 +1,67 @@
|
|
|
1
1
|
import React, { FC } from 'react';
|
|
2
|
-
import { Box, Toolbar } from '@mui/material';
|
|
3
|
-
import { useMRT } from '../useMRT';
|
|
2
|
+
import { alpha, Box, Toolbar } from '@mui/material';
|
|
4
3
|
import { MRT_TablePagination } from './MRT_TablePagination';
|
|
5
4
|
import { MRT_ToolbarInternalButtons } from './MRT_ToolbarInternalButtons';
|
|
6
5
|
import { MRT_ToolbarAlertBanner } from './MRT_ToolbarAlertBanner';
|
|
7
6
|
import { MRT_LinearProgressBar } from './MRT_LinearProgressBar';
|
|
8
7
|
import { commonToolbarStyles } from './MRT_ToolbarTop';
|
|
8
|
+
import { MRT_TableInstance } from '..';
|
|
9
9
|
|
|
10
|
-
interface Props {
|
|
10
|
+
interface Props {
|
|
11
|
+
tableInstance: MRT_TableInstance;
|
|
12
|
+
}
|
|
11
13
|
|
|
12
|
-
export const MRT_ToolbarBottom: FC<Props> = () => {
|
|
14
|
+
export const MRT_ToolbarBottom: FC<Props> = ({ tableInstance }) => {
|
|
13
15
|
const {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
16
|
+
getState,
|
|
17
|
+
options: {
|
|
18
|
+
hideToolbarInternalActions,
|
|
19
|
+
idPrefix,
|
|
20
|
+
enablePagination,
|
|
21
|
+
muiTableToolbarBottomProps,
|
|
22
|
+
positionPagination,
|
|
23
|
+
positionToolbarActions,
|
|
24
|
+
positionToolbarAlertBanner,
|
|
25
|
+
},
|
|
26
|
+
} = tableInstance;
|
|
27
|
+
|
|
28
|
+
const { isFullScreen } = getState();
|
|
22
29
|
|
|
23
30
|
const toolbarProps =
|
|
24
31
|
muiTableToolbarBottomProps instanceof Function
|
|
25
|
-
? muiTableToolbarBottomProps(tableInstance)
|
|
32
|
+
? muiTableToolbarBottomProps({ tableInstance })
|
|
26
33
|
: muiTableToolbarBottomProps;
|
|
27
34
|
|
|
28
35
|
return (
|
|
29
36
|
<Toolbar
|
|
37
|
+
id={`mrt-${idPrefix}-toolbar-bottom`}
|
|
30
38
|
variant="dense"
|
|
31
39
|
{...toolbarProps}
|
|
32
40
|
sx={(theme) =>
|
|
33
41
|
({
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
42
|
+
...commonToolbarStyles({ theme }),
|
|
43
|
+
bottom: isFullScreen ? '0' : undefined,
|
|
44
|
+
position: isFullScreen ? 'fixed' : undefined,
|
|
45
|
+
boxShadow: `-3px 0 6px ${alpha(theme.palette.common.black, 0.1)}`,
|
|
37
46
|
...toolbarProps?.sx,
|
|
38
47
|
} as any)
|
|
39
48
|
}
|
|
40
49
|
>
|
|
41
|
-
<MRT_LinearProgressBar />
|
|
50
|
+
<MRT_LinearProgressBar tableInstance={tableInstance} />
|
|
42
51
|
<Box
|
|
43
52
|
sx={{ display: 'flex', justifyContent: 'space-between', width: '100%' }}
|
|
44
53
|
>
|
|
45
54
|
{!hideToolbarInternalActions && positionToolbarActions === 'bottom' ? (
|
|
46
|
-
<MRT_ToolbarInternalButtons />
|
|
55
|
+
<MRT_ToolbarInternalButtons tableInstance={tableInstance} />
|
|
47
56
|
) : (
|
|
48
57
|
<span />
|
|
49
58
|
)}
|
|
50
|
-
{positionToolbarAlertBanner === 'bottom' &&
|
|
51
|
-
|
|
59
|
+
{positionToolbarAlertBanner === 'bottom' && (
|
|
60
|
+
<MRT_ToolbarAlertBanner tableInstance={tableInstance} />
|
|
61
|
+
)}
|
|
62
|
+
{enablePagination &&
|
|
52
63
|
['bottom', 'both'].includes(positionPagination ?? '') && (
|
|
53
|
-
<MRT_TablePagination />
|
|
64
|
+
<MRT_TablePagination tableInstance={tableInstance} />
|
|
54
65
|
)}
|
|
55
66
|
</Box>
|
|
56
67
|
</Toolbar>
|
|
@@ -5,30 +5,34 @@ import { MRT_ShowHideColumnsButton } from '../buttons/MRT_ShowHideColumnsButton'
|
|
|
5
5
|
import { MRT_ToggleDensePaddingButton } from '../buttons/MRT_ToggleDensePaddingButton';
|
|
6
6
|
import { MRT_ToggleFiltersButton } from '../buttons/MRT_ToggleFiltersButton';
|
|
7
7
|
import { MRT_ToggleSearchButton } from '../buttons/MRT_ToggleSearchButton';
|
|
8
|
-
import {
|
|
8
|
+
import { MRT_TableInstance } from '..';
|
|
9
9
|
|
|
10
|
-
interface Props {
|
|
10
|
+
interface Props {
|
|
11
|
+
tableInstance: MRT_TableInstance;
|
|
12
|
+
}
|
|
11
13
|
|
|
12
|
-
export const MRT_ToolbarInternalButtons: FC<Props> = () => {
|
|
14
|
+
export const MRT_ToolbarInternalButtons: FC<Props> = ({ tableInstance }) => {
|
|
13
15
|
const {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
16
|
+
options: {
|
|
17
|
+
enableColumnFilters,
|
|
18
|
+
enableHiding,
|
|
19
|
+
enableDensePaddingToggle,
|
|
20
|
+
enableGlobalFilter,
|
|
21
|
+
enableFullScreenToggle,
|
|
22
|
+
renderToolbarInternalActions,
|
|
23
|
+
},
|
|
24
|
+
} = tableInstance;
|
|
22
25
|
|
|
23
26
|
if (renderToolbarInternalActions) {
|
|
24
27
|
return (
|
|
25
28
|
<>
|
|
26
|
-
{renderToolbarInternalActions(
|
|
27
|
-
|
|
28
|
-
MRT_ToggleFiltersButton,
|
|
29
|
+
{renderToolbarInternalActions({
|
|
30
|
+
MRT_FullScreenToggleButton,
|
|
29
31
|
MRT_ShowHideColumnsButton,
|
|
30
32
|
MRT_ToggleDensePaddingButton,
|
|
31
|
-
|
|
33
|
+
MRT_ToggleFiltersButton,
|
|
34
|
+
MRT_ToggleSearchButton,
|
|
35
|
+
tableInstance,
|
|
32
36
|
})}
|
|
33
37
|
</>
|
|
34
38
|
);
|
|
@@ -43,11 +47,21 @@ export const MRT_ToolbarInternalButtons: FC<Props> = () => {
|
|
|
43
47
|
p: '0 0.5rem',
|
|
44
48
|
}}
|
|
45
49
|
>
|
|
46
|
-
{
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
{
|
|
50
|
-
|
|
50
|
+
{enableGlobalFilter && (
|
|
51
|
+
<MRT_ToggleSearchButton tableInstance={tableInstance} />
|
|
52
|
+
)}
|
|
53
|
+
{enableColumnFilters && (
|
|
54
|
+
<MRT_ToggleFiltersButton tableInstance={tableInstance} />
|
|
55
|
+
)}
|
|
56
|
+
{enableHiding && (
|
|
57
|
+
<MRT_ShowHideColumnsButton tableInstance={tableInstance} />
|
|
58
|
+
)}
|
|
59
|
+
{enableDensePaddingToggle && (
|
|
60
|
+
<MRT_ToggleDensePaddingButton tableInstance={tableInstance} />
|
|
61
|
+
)}
|
|
62
|
+
{enableFullScreenToggle && (
|
|
63
|
+
<MRT_FullScreenToggleButton tableInstance={tableInstance} />
|
|
64
|
+
)}
|
|
51
65
|
</Box>
|
|
52
66
|
);
|
|
53
67
|
};
|