material-react-table 0.13.2 → 0.14.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/README.md +20 -3
- package/dist/MaterialReactTable.d.ts +6 -4
- package/dist/material-react-table.cjs.development.js +111 -98
- 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 +111 -98
- package/dist/material-react-table.esm.js.map +1 -1
- package/dist/toolbar/MRT_TablePagination.d.ts +1 -0
- package/dist/toolbar/MRT_ToolbarTop.d.ts +0 -1
- package/dist/utils.d.ts +5 -2
- package/package.json +1 -1
- package/src/MaterialReactTable.tsx +14 -6
- package/src/body/MRT_TableBodyCell.tsx +5 -1
- package/src/inputs/MRT_SearchTextField.tsx +8 -11
- package/src/menus/MRT_ShowHideColumnsMenu.tsx +8 -1
- package/src/table/MRT_TableRoot.tsx +16 -43
- package/src/toolbar/MRT_TablePagination.tsx +10 -2
- package/src/toolbar/MRT_ToolbarBottom.tsx +21 -18
- package/src/toolbar/MRT_ToolbarInternalButtons.tsx +1 -1
- package/src/toolbar/MRT_ToolbarTop.tsx +18 -15
- package/src/utils.ts +33 -1
package/dist/utils.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ColumnDef, ColumnOrderState, Table, Updater } from '@tanstack/react-table';
|
|
2
|
-
import { MRT_Column, MRT_ColumnDef, MRT_FilterFn } from '.';
|
|
2
|
+
import { MaterialReactTableProps, MRT_Column, MRT_ColumnDef, MRT_FilterFn } from '.';
|
|
3
3
|
export declare const getAllLeafColumnDefs: (columns: MRT_ColumnDef[]) => MRT_ColumnDef[];
|
|
4
4
|
export declare const createGroup: <D extends Record<string, any> = {}>(table: Table<D>, column: MRT_ColumnDef<D>, currentFilterFns: {
|
|
5
5
|
[key: string]: import("@tanstack/react-table").FilterFnOption<import("@tanstack/react-table").TableGenerics>;
|
|
@@ -7,7 +7,10 @@ export declare const createGroup: <D extends Record<string, any> = {}>(table: Ta
|
|
|
7
7
|
export declare const createDataColumn: <D extends Record<string, any> = {}>(table: Table<D>, column: MRT_ColumnDef<D>, currentFilterFns: {
|
|
8
8
|
[key: string]: import("@tanstack/react-table").FilterFnOption<import("@tanstack/react-table").TableGenerics>;
|
|
9
9
|
}) => ColumnDef<D>;
|
|
10
|
-
export declare const createDisplayColumn: <D extends Record<string, any> = {}>(table: Table<D>, column: Pick<MRT_ColumnDef<D>, "
|
|
10
|
+
export declare const createDisplayColumn: <D extends Record<string, any> = {}>(table: Table<D>, column: Pick<MRT_ColumnDef<D>, "accessorFn" | "footer" | "columns" | "filterFn" | "id" | "accessorKey" | "meta" | "enableHiding" | "enablePinning" | "enableColumnFilter" | "enableGlobalFilter" | "sortingFn" | "sortDescFirst" | "enableSorting" | "enableMultiSort" | "invertSorting" | "sortUndefined" | "aggregationFn" | "enableGrouping" | "enableResizing" | "size" | "minSize" | "maxSize" | "AggregatedCell" | "Cell" | "Edit" | "Filter" | "Footer" | "Header" | "enableClickToCopy" | "enableColumnActions" | "enableColumnOrdering" | "enableEditing" | "enabledColumnFilterOptions" | "filterSelectOptions" | "muiTableBodyCellCopyButtonProps" | "muiTableBodyCellEditTextFieldProps" | "muiTableBodyCellProps" | "muiTableFooterCellProps" | "muiTableHeadCellColumnActionsButtonProps" | "muiTableHeadCellFilterTextFieldProps" | "muiTableHeadCellProps" | "onCellEditBlur" | "onCellEditChanged" | "onColumnFilterValueChanged" | "onColumnFilterValueChangedDebounced"> & {
|
|
11
11
|
header?: string | undefined;
|
|
12
12
|
}) => ColumnDef<D>;
|
|
13
13
|
export declare const reorderColumn: (movingColumn: MRT_Column, receivingColumn: MRT_Column, columnOrder: ColumnOrderState, setColumnOrder: (updater: Updater<ColumnOrderState>) => void) => void;
|
|
14
|
+
export declare const getLeadingDisplayColumnIds: (props: MaterialReactTableProps<any>) => string[];
|
|
15
|
+
export declare const getTrailingDisplayColumnIds: (props: MaterialReactTableProps<any>) => (string | false | undefined)[];
|
|
16
|
+
export declare const getDefaultColumnOrderIds: (props: MaterialReactTableProps<any>) => string[];
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "0.
|
|
2
|
+
"version": "0.14.1",
|
|
3
3
|
"license": "MIT",
|
|
4
4
|
"name": "material-react-table",
|
|
5
5
|
"description": "A fully featured Material UI implementation of TanStack React Table, inspired by material-table and the MUI X DataGrid, written from the ground up in TypeScript.",
|
|
@@ -514,7 +514,11 @@ export type MaterialReactTableProps<D extends Record<string, any> = {}> =
|
|
|
514
514
|
}) => TableCellProps);
|
|
515
515
|
muiTableFooterProps?:
|
|
516
516
|
| TableFooterProps
|
|
517
|
-
| (({
|
|
517
|
+
| (({
|
|
518
|
+
instance,
|
|
519
|
+
}: {
|
|
520
|
+
instance: MRT_TableInstance<D>;
|
|
521
|
+
}) => TableFooterProps);
|
|
518
522
|
muiTableFooterRowProps?:
|
|
519
523
|
| TableRowProps
|
|
520
524
|
| (({
|
|
@@ -758,7 +762,6 @@ export type MaterialReactTableProps<D extends Record<string, any> = {}> =
|
|
|
758
762
|
positionActionsColumn?: 'first' | 'last';
|
|
759
763
|
positionGlobalFilter?: 'left' | 'right';
|
|
760
764
|
positionPagination?: 'bottom' | 'top' | 'both';
|
|
761
|
-
positionToolbarActions?: 'bottom' | 'top';
|
|
762
765
|
positionToolbarAlertBanner?: 'bottom' | 'top';
|
|
763
766
|
renderDetailPanel?: ({
|
|
764
767
|
row,
|
|
@@ -783,7 +786,12 @@ export type MaterialReactTableProps<D extends Record<string, any> = {}> =
|
|
|
783
786
|
row: MRT_Row<D>;
|
|
784
787
|
instance: MRT_TableInstance<D>;
|
|
785
788
|
}) => ReactNode;
|
|
786
|
-
|
|
789
|
+
renderToolbarBottomCustomActions?: ({
|
|
790
|
+
instance,
|
|
791
|
+
}: {
|
|
792
|
+
instance: MRT_TableInstance<D>;
|
|
793
|
+
}) => ReactNode;
|
|
794
|
+
renderToolbarTopCustomActions?: ({
|
|
787
795
|
instance,
|
|
788
796
|
}: {
|
|
789
797
|
instance: MRT_TableInstance<D>;
|
|
@@ -838,6 +846,7 @@ export default <D extends Record<string, any> = {}>({
|
|
|
838
846
|
enableMultiRowSelection = true,
|
|
839
847
|
enablePagination = true,
|
|
840
848
|
enablePinning = false,
|
|
849
|
+
enableRowSelection = false,
|
|
841
850
|
enableSelectAll = true,
|
|
842
851
|
enableSorting = true,
|
|
843
852
|
enableStickyHeader = false,
|
|
@@ -850,9 +859,8 @@ export default <D extends Record<string, any> = {}>({
|
|
|
850
859
|
localization,
|
|
851
860
|
persistentStateMode = 'sessionStorage',
|
|
852
861
|
positionActionsColumn = 'first',
|
|
853
|
-
positionPagination = 'bottom',
|
|
854
862
|
positionGlobalFilter = 'right',
|
|
855
|
-
|
|
863
|
+
positionPagination = 'bottom',
|
|
856
864
|
positionToolbarAlertBanner = 'top',
|
|
857
865
|
rowNumberMode = 'original',
|
|
858
866
|
selectAllMode = 'all',
|
|
@@ -877,6 +885,7 @@ export default <D extends Record<string, any> = {}>({
|
|
|
877
885
|
enableMultiRowSelection={enableMultiRowSelection}
|
|
878
886
|
enablePagination={enablePagination}
|
|
879
887
|
enablePinning={enablePinning}
|
|
888
|
+
enableRowSelection={enableRowSelection}
|
|
880
889
|
enableSelectAll={enableSelectAll}
|
|
881
890
|
enableSorting={enableSorting}
|
|
882
891
|
enableStickyHeader={enableStickyHeader}
|
|
@@ -891,7 +900,6 @@ export default <D extends Record<string, any> = {}>({
|
|
|
891
900
|
positionActionsColumn={positionActionsColumn}
|
|
892
901
|
positionGlobalFilter={positionGlobalFilter}
|
|
893
902
|
positionPagination={positionPagination}
|
|
894
|
-
positionToolbarActions={positionToolbarActions}
|
|
895
903
|
positionToolbarAlertBanner={positionToolbarAlertBanner}
|
|
896
904
|
rowNumberMode={rowNumberMode}
|
|
897
905
|
selectAllMode={selectAllMode}
|
|
@@ -30,6 +30,7 @@ export const MRT_TableBodyCell: FC<Props> = ({
|
|
|
30
30
|
muiTableBodyCellProps,
|
|
31
31
|
muiTableBodyCellSkeletonProps,
|
|
32
32
|
onCellClick,
|
|
33
|
+
onRowClick,
|
|
33
34
|
rowNumberMode,
|
|
34
35
|
tableId,
|
|
35
36
|
},
|
|
@@ -146,7 +147,10 @@ export const MRT_TableBodyCell: FC<Props> = ({
|
|
|
146
147
|
: getIsFirstRightPinnedColumn()
|
|
147
148
|
? `-4px 0 4px -2px ${alpha(theme.palette.common.black, 0.1)}`
|
|
148
149
|
: undefined,
|
|
149
|
-
cursor:
|
|
150
|
+
cursor:
|
|
151
|
+
(isEditable && editingMode === 'cell') || onRowClick || onCellClick
|
|
152
|
+
? 'pointer'
|
|
153
|
+
: 'text',
|
|
150
154
|
left:
|
|
151
155
|
column.getIsPinned() === 'left'
|
|
152
156
|
? `${column.getStart('left')}px`
|
|
@@ -79,16 +79,14 @@ export const MRT_SearchTextField: FC<Props> = ({ instance }) => {
|
|
|
79
79
|
startAdornment: (
|
|
80
80
|
<InputAdornment position="start">
|
|
81
81
|
<Tooltip arrow title={localization.changeSearchMode}>
|
|
82
|
-
<
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
</IconButton>
|
|
91
|
-
</span>
|
|
82
|
+
<IconButton
|
|
83
|
+
aria-label={localization.changeSearchMode}
|
|
84
|
+
onClick={handleGlobalFilterMenuOpen}
|
|
85
|
+
size="small"
|
|
86
|
+
sx={{ height: '1.75rem', width: '1.75rem' }}
|
|
87
|
+
>
|
|
88
|
+
<SearchIcon />
|
|
89
|
+
</IconButton>
|
|
92
90
|
</Tooltip>
|
|
93
91
|
</InputAdornment>
|
|
94
92
|
),
|
|
@@ -107,7 +105,6 @@ export const MRT_SearchTextField: FC<Props> = ({ instance }) => {
|
|
|
107
105
|
),
|
|
108
106
|
}}
|
|
109
107
|
{...textFieldProps}
|
|
110
|
-
sx={{ justifySelf: 'end', ...textFieldProps?.sx }}
|
|
111
108
|
/>
|
|
112
109
|
<MRT_FilterOptionMenu
|
|
113
110
|
anchorEl={anchorEl}
|
|
@@ -2,6 +2,7 @@ import React, { FC, useMemo } from 'react';
|
|
|
2
2
|
import { Button, Menu, Divider, Box } from '@mui/material';
|
|
3
3
|
import { MRT_ShowHideColumnsMenuItems } from './MRT_ShowHideColumnsMenuItems';
|
|
4
4
|
import type { MRT_Column, MRT_TableInstance } from '..';
|
|
5
|
+
import { getDefaultColumnOrderIds } from '../utils';
|
|
5
6
|
|
|
6
7
|
interface Props {
|
|
7
8
|
anchorEl: HTMLElement | null;
|
|
@@ -88,7 +89,13 @@ export const MRT_ShowHideColumnsMenu: FC<Props> = ({
|
|
|
88
89
|
</Button>
|
|
89
90
|
)}
|
|
90
91
|
{!isSubMenu && enableColumnOrdering && (
|
|
91
|
-
<Button
|
|
92
|
+
<Button
|
|
93
|
+
onClick={() =>
|
|
94
|
+
instance.setColumnOrder(
|
|
95
|
+
getDefaultColumnOrderIds(instance.options as any),
|
|
96
|
+
)
|
|
97
|
+
}
|
|
98
|
+
>
|
|
92
99
|
{localization.resetOrder}
|
|
93
100
|
</Button>
|
|
94
101
|
)}
|
|
@@ -34,6 +34,7 @@ import {
|
|
|
34
34
|
createDisplayColumn,
|
|
35
35
|
createGroup,
|
|
36
36
|
getAllLeafColumnDefs,
|
|
37
|
+
getDefaultColumnOrderIds,
|
|
37
38
|
} from '../utils';
|
|
38
39
|
import { defaultFilterFNs } from '../filtersFNs';
|
|
39
40
|
import { Box, Dialog, Grow } from '@mui/material';
|
|
@@ -48,28 +49,10 @@ export const MRT_TableRoot = <D extends Record<string, any> = {}>(
|
|
|
48
49
|
[props.tableId],
|
|
49
50
|
);
|
|
50
51
|
|
|
51
|
-
const showActionColumn =
|
|
52
|
-
props.enableRowActions ||
|
|
53
|
-
(props.enableEditing && props.editingMode === 'row');
|
|
54
|
-
|
|
55
|
-
const showExpandColumn = props.enableExpanding || props.enableGrouping;
|
|
56
|
-
|
|
57
52
|
const initialState: Partial<MRT_TableState<D>> = useMemo(() => {
|
|
58
53
|
const initState = props.initialState ?? {};
|
|
59
|
-
|
|
60
54
|
initState.columnOrder =
|
|
61
|
-
initState
|
|
62
|
-
(props.enableColumnOrdering || props.enableGrouping)
|
|
63
|
-
? ([
|
|
64
|
-
showActionColumn && 'mrt-row-actions',
|
|
65
|
-
showExpandColumn && 'mrt-expand',
|
|
66
|
-
props.enableRowSelection && 'mrt-select',
|
|
67
|
-
props.enableRowNumbers && 'mrt-row-numbers',
|
|
68
|
-
...getAllLeafColumnDefs(props.columns as MRT_ColumnDef[]).map(
|
|
69
|
-
(c) => c.id,
|
|
70
|
-
),
|
|
71
|
-
].filter(Boolean) as string[])
|
|
72
|
-
: [];
|
|
55
|
+
initState.columnOrder ?? getDefaultColumnOrderIds(props);
|
|
73
56
|
|
|
74
57
|
if (!props.enablePersistentState || !props.tableId) {
|
|
75
58
|
return initState;
|
|
@@ -97,6 +80,9 @@ export const MRT_TableRoot = <D extends Record<string, any> = {}>(
|
|
|
97
80
|
return initState;
|
|
98
81
|
}, []);
|
|
99
82
|
|
|
83
|
+
const [columnOrder, setColumnOrder] = useState(
|
|
84
|
+
initialState.columnOrder ?? [],
|
|
85
|
+
);
|
|
100
86
|
const [currentEditingCell, setCurrentEditingCell] =
|
|
101
87
|
useState<MRT_Cell<D> | null>(initialState?.currentEditingCell ?? null);
|
|
102
88
|
const [currentEditingRow, setCurrentEditingRow] = useState<MRT_Row<D> | null>(
|
|
@@ -148,14 +134,13 @@ export const MRT_TableRoot = <D extends Record<string, any> = {}>(
|
|
|
148
134
|
getSortedRowModel: getSortedRowModel(),
|
|
149
135
|
getSubRows: (row) => (row as MRT_Row)?.subRows,
|
|
150
136
|
tableId,
|
|
151
|
-
initialState,
|
|
152
137
|
}) as Table<D>,
|
|
153
138
|
[],
|
|
154
139
|
);
|
|
155
140
|
|
|
156
|
-
const
|
|
157
|
-
|
|
158
|
-
|
|
141
|
+
const displayColumns = useMemo(() => {
|
|
142
|
+
return [
|
|
143
|
+
columnOrder.includes('mrt-row-actions') &&
|
|
159
144
|
createDisplayColumn(table, {
|
|
160
145
|
Cell: ({ cell }) => (
|
|
161
146
|
<MRT_ToggleRowActionMenuButton
|
|
@@ -169,7 +154,7 @@ export const MRT_TableRoot = <D extends Record<string, any> = {}>(
|
|
|
169
154
|
muiTableHeadCellProps: props.muiTableHeadCellProps,
|
|
170
155
|
size: 70,
|
|
171
156
|
}),
|
|
172
|
-
|
|
157
|
+
columnOrder.includes('mrt-expand') &&
|
|
173
158
|
createDisplayColumn(table, {
|
|
174
159
|
Cell: ({ cell }) => (
|
|
175
160
|
<MRT_ExpandButton row={cell.row as any} instance={instance} />
|
|
@@ -184,7 +169,7 @@ export const MRT_TableRoot = <D extends Record<string, any> = {}>(
|
|
|
184
169
|
muiTableHeadCellProps: props.muiTableHeadCellProps,
|
|
185
170
|
size: 50,
|
|
186
171
|
}),
|
|
187
|
-
|
|
172
|
+
columnOrder.includes('mrt-select') &&
|
|
188
173
|
createDisplayColumn(table, {
|
|
189
174
|
Cell: ({ cell }) => (
|
|
190
175
|
<MRT_SelectCheckbox row={cell.row as any} instance={instance} />
|
|
@@ -199,7 +184,7 @@ export const MRT_TableRoot = <D extends Record<string, any> = {}>(
|
|
|
199
184
|
muiTableHeadCellProps: props.muiTableHeadCellProps,
|
|
200
185
|
size: 50,
|
|
201
186
|
}),
|
|
202
|
-
|
|
187
|
+
columnOrder.includes('mrt-row-numbers') &&
|
|
203
188
|
createDisplayColumn(table, {
|
|
204
189
|
Cell: ({ cell }) => cell.row.index + 1,
|
|
205
190
|
Header: () => props.localization?.rowNumber,
|
|
@@ -210,22 +195,8 @@ export const MRT_TableRoot = <D extends Record<string, any> = {}>(
|
|
|
210
195
|
size: 50,
|
|
211
196
|
}),
|
|
212
197
|
].filter(Boolean) as MRT_ColumnDef<D>[];
|
|
213
|
-
|
|
214
|
-
const trailingDisplayColumns = [] as MRT_ColumnDef<D>[];
|
|
215
|
-
|
|
216
|
-
if (props.enableRowActions && props.positionActionsColumn === 'last') {
|
|
217
|
-
trailingDisplayColumns.push(
|
|
218
|
-
...leadingDisplayColumns.splice(
|
|
219
|
-
leadingDisplayColumns.findIndex(
|
|
220
|
-
(col) => col.id === 'mrt-row-actions',
|
|
221
|
-
),
|
|
222
|
-
1,
|
|
223
|
-
),
|
|
224
|
-
);
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
return [leadingDisplayColumns, trailingDisplayColumns];
|
|
228
198
|
}, [
|
|
199
|
+
columnOrder,
|
|
229
200
|
props.editingMode,
|
|
230
201
|
props.enableEditing,
|
|
231
202
|
props.enableExpandAll,
|
|
@@ -244,13 +215,12 @@ export const MRT_TableRoot = <D extends Record<string, any> = {}>(
|
|
|
244
215
|
|
|
245
216
|
const columns = useMemo(
|
|
246
217
|
() => [
|
|
247
|
-
...
|
|
218
|
+
...displayColumns,
|
|
248
219
|
...props.columns.map((column) =>
|
|
249
220
|
column.columns
|
|
250
221
|
? createGroup(table, column as any, currentFilterFns)
|
|
251
222
|
: createDataColumn(table, column as any, currentFilterFns),
|
|
252
223
|
),
|
|
253
|
-
...trailingDisplayColumns,
|
|
254
224
|
],
|
|
255
225
|
[table, props.columns, currentFilterFns],
|
|
256
226
|
);
|
|
@@ -277,13 +247,16 @@ export const MRT_TableRoot = <D extends Record<string, any> = {}>(
|
|
|
277
247
|
const instance = {
|
|
278
248
|
//@ts-ignore
|
|
279
249
|
...useTableInstance(table, {
|
|
250
|
+
onColumnOrderChange: setColumnOrder,
|
|
280
251
|
...props,
|
|
281
252
|
//@ts-ignore
|
|
282
253
|
columns,
|
|
283
254
|
data,
|
|
284
255
|
//@ts-ignore
|
|
285
256
|
globalFilterFn: currentGlobalFilterFn,
|
|
257
|
+
initialState,
|
|
286
258
|
state: {
|
|
259
|
+
columnOrder,
|
|
287
260
|
currentEditingCell,
|
|
288
261
|
currentEditingRow,
|
|
289
262
|
currentFilterFns,
|
|
@@ -4,19 +4,21 @@ import { MRT_TableInstance } from '..';
|
|
|
4
4
|
|
|
5
5
|
interface Props {
|
|
6
6
|
instance: MRT_TableInstance;
|
|
7
|
+
position: 'top' | 'bottom';
|
|
7
8
|
}
|
|
8
9
|
|
|
9
|
-
export const MRT_TablePagination: FC<Props> = ({ instance }) => {
|
|
10
|
+
export const MRT_TablePagination: FC<Props> = ({ instance, position }) => {
|
|
10
11
|
const {
|
|
11
12
|
getPrePaginationRowModel,
|
|
12
13
|
getState,
|
|
13
14
|
setPageIndex,
|
|
14
15
|
setPageSize,
|
|
15
|
-
options: { muiTablePaginationProps },
|
|
16
|
+
options: { muiTablePaginationProps, enableToolbarInternalActions },
|
|
16
17
|
} = instance;
|
|
17
18
|
|
|
18
19
|
const {
|
|
19
20
|
pagination: { pageSize = 10, pageIndex = 0 },
|
|
21
|
+
showGlobalFilter,
|
|
20
22
|
} = getState();
|
|
21
23
|
|
|
22
24
|
const tablePaginationProps =
|
|
@@ -49,6 +51,12 @@ export const MRT_TablePagination: FC<Props> = ({ instance }) => {
|
|
|
49
51
|
{...tablePaginationProps}
|
|
50
52
|
sx={{
|
|
51
53
|
m: '0 0.5rem',
|
|
54
|
+
mt:
|
|
55
|
+
position === 'top' &&
|
|
56
|
+
enableToolbarInternalActions &&
|
|
57
|
+
!showGlobalFilter
|
|
58
|
+
? '3.5rem'
|
|
59
|
+
: undefined,
|
|
52
60
|
position: 'relative',
|
|
53
61
|
zIndex: 2,
|
|
54
62
|
...tablePaginationProps?.sx,
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import React, { FC } from 'react';
|
|
2
2
|
import { alpha, Box, Toolbar, useMediaQuery } from '@mui/material';
|
|
3
3
|
import { MRT_TablePagination } from './MRT_TablePagination';
|
|
4
|
-
import { MRT_ToolbarInternalButtons } from './MRT_ToolbarInternalButtons';
|
|
5
4
|
import { MRT_ToolbarAlertBanner } from './MRT_ToolbarAlertBanner';
|
|
6
5
|
import { MRT_LinearProgressBar } from './MRT_LinearProgressBar';
|
|
7
6
|
import { commonToolbarStyles } from './MRT_ToolbarTop';
|
|
@@ -15,14 +14,12 @@ export const MRT_ToolbarBottom: FC<Props> = ({ instance }) => {
|
|
|
15
14
|
const {
|
|
16
15
|
getState,
|
|
17
16
|
options: {
|
|
18
|
-
enableToolbarInternalActions,
|
|
19
|
-
tableId,
|
|
20
17
|
enablePagination,
|
|
21
18
|
muiTableToolbarBottomProps,
|
|
22
19
|
positionPagination,
|
|
23
|
-
positionToolbarActions,
|
|
24
20
|
positionToolbarAlertBanner,
|
|
25
|
-
|
|
21
|
+
renderToolbarBottomCustomActions,
|
|
22
|
+
tableId,
|
|
26
23
|
},
|
|
27
24
|
} = instance;
|
|
28
25
|
|
|
@@ -38,10 +35,7 @@ export const MRT_ToolbarBottom: FC<Props> = ({ instance }) => {
|
|
|
38
35
|
const stackAlertBanner =
|
|
39
36
|
isMobile ||
|
|
40
37
|
(positionToolbarAlertBanner === 'bottom' &&
|
|
41
|
-
|
|
42
|
-
(positionToolbarAlertBanner === 'bottom' &&
|
|
43
|
-
!!renderToolbarCustomActions &&
|
|
44
|
-
positionToolbarActions === 'bottom');
|
|
38
|
+
!!renderToolbarBottomCustomActions);
|
|
45
39
|
|
|
46
40
|
return (
|
|
47
41
|
<Toolbar
|
|
@@ -67,20 +61,29 @@ export const MRT_ToolbarBottom: FC<Props> = ({ instance }) => {
|
|
|
67
61
|
display: 'flex',
|
|
68
62
|
justifyContent: 'space-between',
|
|
69
63
|
width: '100%',
|
|
70
|
-
position: stackAlertBanner ? 'relative' : 'absolute',
|
|
71
|
-
right: 0,
|
|
72
|
-
top: 0,
|
|
73
64
|
}}
|
|
74
65
|
>
|
|
75
|
-
{
|
|
76
|
-
<
|
|
66
|
+
{renderToolbarBottomCustomActions ? (
|
|
67
|
+
<Box sx={{ p: '0.5rem' }}>
|
|
68
|
+
{renderToolbarBottomCustomActions({ instance })}
|
|
69
|
+
</Box>
|
|
77
70
|
) : (
|
|
78
71
|
<span />
|
|
79
72
|
)}
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
73
|
+
<Box
|
|
74
|
+
sx={{
|
|
75
|
+
display: 'flex',
|
|
76
|
+
justifyContent: 'flex-end',
|
|
77
|
+
position: stackAlertBanner ? 'relative' : 'absolute',
|
|
78
|
+
right: 0,
|
|
79
|
+
top: 0,
|
|
80
|
+
}}
|
|
81
|
+
>
|
|
82
|
+
{enablePagination &&
|
|
83
|
+
['bottom', 'both'].includes(positionPagination ?? '') && (
|
|
84
|
+
<MRT_TablePagination instance={instance} position="bottom" />
|
|
85
|
+
)}
|
|
86
|
+
</Box>
|
|
84
87
|
</Box>
|
|
85
88
|
</Toolbar>
|
|
86
89
|
);
|
|
@@ -15,7 +15,6 @@ export const commonToolbarStyles = ({ theme }: { theme: Theme }) => ({
|
|
|
15
15
|
overflow: 'hidden',
|
|
16
16
|
p: '0 !important',
|
|
17
17
|
transition: 'all 0.2s ease-in-out',
|
|
18
|
-
width: '100%',
|
|
19
18
|
zIndex: 1,
|
|
20
19
|
});
|
|
21
20
|
|
|
@@ -30,13 +29,12 @@ export const MRT_ToolbarTop: FC<Props> = ({ instance }) => {
|
|
|
30
29
|
enableGlobalFilter,
|
|
31
30
|
enablePagination,
|
|
32
31
|
enableToolbarInternalActions,
|
|
33
|
-
tableId,
|
|
34
32
|
muiTableToolbarTopProps,
|
|
35
|
-
positionPagination,
|
|
36
33
|
positionGlobalFilter,
|
|
37
|
-
|
|
34
|
+
positionPagination,
|
|
38
35
|
positionToolbarAlertBanner,
|
|
39
|
-
|
|
36
|
+
renderToolbarTopCustomActions,
|
|
37
|
+
tableId,
|
|
40
38
|
},
|
|
41
39
|
} = instance;
|
|
42
40
|
|
|
@@ -52,7 +50,7 @@ export const MRT_ToolbarTop: FC<Props> = ({ instance }) => {
|
|
|
52
50
|
const stackAlertBanner =
|
|
53
51
|
isMobile ||
|
|
54
52
|
(positionToolbarAlertBanner === 'top' &&
|
|
55
|
-
(!!
|
|
53
|
+
(!!renderToolbarTopCustomActions || showGlobalFilter));
|
|
56
54
|
|
|
57
55
|
return (
|
|
58
56
|
<Toolbar
|
|
@@ -77,29 +75,34 @@ export const MRT_ToolbarTop: FC<Props> = ({ instance }) => {
|
|
|
77
75
|
<Box
|
|
78
76
|
sx={{
|
|
79
77
|
alignItems: 'flex-start',
|
|
78
|
+
boxSizing: 'border-box',
|
|
80
79
|
display: 'flex',
|
|
81
80
|
justifyContent: 'space-between',
|
|
82
81
|
p: '0.5rem',
|
|
83
82
|
position: stackAlertBanner ? 'relative' : 'absolute',
|
|
84
83
|
right: 0,
|
|
85
84
|
top: 0,
|
|
86
|
-
width:
|
|
85
|
+
width: '100%',
|
|
87
86
|
}}
|
|
88
87
|
>
|
|
89
88
|
{enableGlobalFilter && positionGlobalFilter === 'left' && (
|
|
90
89
|
<MRT_SearchTextField instance={instance} />
|
|
91
90
|
)}
|
|
92
|
-
|
|
93
|
-
{
|
|
91
|
+
|
|
92
|
+
{renderToolbarTopCustomActions?.({ instance }) ?? <span />}
|
|
93
|
+
{enableToolbarInternalActions ? (
|
|
94
94
|
<MRT_ToolbarInternalButtons instance={instance} />
|
|
95
|
+
) : (
|
|
96
|
+
enableGlobalFilter &&
|
|
97
|
+
positionGlobalFilter === 'right' && (
|
|
98
|
+
<MRT_SearchTextField instance={instance} />
|
|
99
|
+
)
|
|
95
100
|
)}
|
|
96
101
|
</Box>
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
)}
|
|
102
|
-
</div>
|
|
102
|
+
{enablePagination &&
|
|
103
|
+
['top', 'both'].includes(positionPagination ?? '') && (
|
|
104
|
+
<MRT_TablePagination instance={instance} position="top" />
|
|
105
|
+
)}
|
|
103
106
|
<MRT_LinearProgressBar alignTo="bottom" instance={instance} />
|
|
104
107
|
</Toolbar>
|
|
105
108
|
);
|
package/src/utils.ts
CHANGED
|
@@ -4,7 +4,12 @@ import {
|
|
|
4
4
|
Table,
|
|
5
5
|
Updater,
|
|
6
6
|
} from '@tanstack/react-table';
|
|
7
|
-
import {
|
|
7
|
+
import {
|
|
8
|
+
MaterialReactTableProps,
|
|
9
|
+
MRT_Column,
|
|
10
|
+
MRT_ColumnDef,
|
|
11
|
+
MRT_FilterFn,
|
|
12
|
+
} from '.';
|
|
8
13
|
import { defaultFilterFNs } from './filtersFNs';
|
|
9
14
|
|
|
10
15
|
export const getAllLeafColumnDefs = (
|
|
@@ -74,3 +79,30 @@ export const reorderColumn = (
|
|
|
74
79
|
);
|
|
75
80
|
setColumnOrder([...columnOrder]);
|
|
76
81
|
};
|
|
82
|
+
|
|
83
|
+
export const getLeadingDisplayColumnIds = (
|
|
84
|
+
props: MaterialReactTableProps<any>,
|
|
85
|
+
) =>
|
|
86
|
+
[
|
|
87
|
+
((props.positionActionsColumn === 'first' && props.enableRowActions) ||
|
|
88
|
+
(props.enableEditing && props.editingMode === 'row')) &&
|
|
89
|
+
'mrt-row-actions',
|
|
90
|
+
(props.enableExpanding || props.enableGrouping) && 'mrt-expand',
|
|
91
|
+
props.enableRowSelection && 'mrt-select',
|
|
92
|
+
props.enableRowNumbers && 'mrt-row-numbers',
|
|
93
|
+
].filter(Boolean) as string[];
|
|
94
|
+
|
|
95
|
+
export const getTrailingDisplayColumnIds = (
|
|
96
|
+
props: MaterialReactTableProps<any>,
|
|
97
|
+
) => [
|
|
98
|
+
((props.positionActionsColumn === 'last' && props.enableRowActions) ||
|
|
99
|
+
(props.enableEditing && props.editingMode === 'row')) &&
|
|
100
|
+
'mrt-row-actions',
|
|
101
|
+
];
|
|
102
|
+
|
|
103
|
+
export const getDefaultColumnOrderIds = (props: MaterialReactTableProps<any>) =>
|
|
104
|
+
[
|
|
105
|
+
...getLeadingDisplayColumnIds(props),
|
|
106
|
+
...getAllLeafColumnDefs(props.columns as MRT_ColumnDef[]).map((c) => c.id),
|
|
107
|
+
...getTrailingDisplayColumnIds(props),
|
|
108
|
+
].filter(Boolean) as string[];
|