material-react-table 0.41.0 → 1.0.0-beta.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 +22 -20
- package/dist/cjs/MaterialReactTable.d.ts +96 -19
- package/dist/cjs/_locales/en.d.ts +2 -0
- package/dist/cjs/_locales/es.d.ts +2 -0
- package/dist/cjs/body/MRT_EditRowModal.d.ts +0 -1
- package/dist/cjs/body/MRT_TableBody.d.ts +1 -2
- package/dist/cjs/body/MRT_TableBodyCellValue.d.ts +2 -2
- package/dist/cjs/buttons/MRT_ColumnPinningButtons.d.ts +0 -1
- package/dist/cjs/buttons/MRT_EditActionButtons.d.ts +0 -1
- package/dist/cjs/buttons/MRT_FullScreenToggleButton.d.ts +0 -1
- package/dist/cjs/buttons/MRT_ShowHideColumnsButton.d.ts +0 -1
- package/dist/cjs/buttons/MRT_ToggleDensePaddingButton.d.ts +0 -1
- package/dist/cjs/buttons/MRT_ToggleFiltersButton.d.ts +0 -1
- package/dist/cjs/buttons/MRT_ToggleGlobalFilterButton.d.ts +0 -1
- package/dist/cjs/column.utils.d.ts +12 -1
- package/dist/cjs/index.d.ts +4 -3
- package/dist/cjs/index.js +244 -195
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/inputs/MRT_EditCellTextField.d.ts +0 -1
- package/dist/cjs/inputs/MRT_GlobalFilterTextField.d.ts +0 -1
- package/dist/cjs/menus/MRT_FilterOptionMenu.d.ts +3 -4
- package/dist/cjs/menus/MRT_ShowHideColumnsMenu.d.ts +0 -1
- package/dist/cjs/table/MRT_Table.d.ts +1 -2
- package/dist/cjs/table/MRT_TableRoot.d.ts +250 -3
- package/dist/cjs/toolbar/MRT_TablePagination.d.ts +3 -4
- package/dist/cjs/toolbar/MRT_ToolbarAlertBanner.d.ts +1 -1
- package/dist/cjs/toolbar/MRT_ToolbarInternalButtons.d.ts +3 -4
- package/dist/cjs/toolbar/MRT_TopToolbar.d.ts +1 -0
- package/dist/en.cjs +90 -0
- package/dist/en.cjs.d.ts +2 -0
- package/dist/en.cjs.map +1 -0
- package/dist/en.esm.d.ts +2 -0
- package/dist/en.esm.js +86 -0
- package/dist/en.esm.js.map +1 -0
- package/dist/esm/MaterialReactTable.d.ts +96 -19
- package/dist/esm/_locales/en.d.ts +2 -0
- package/dist/esm/_locales/es.d.ts +2 -0
- package/dist/esm/body/MRT_EditRowModal.d.ts +0 -1
- package/dist/esm/body/MRT_TableBody.d.ts +1 -2
- package/dist/esm/body/MRT_TableBodyCellValue.d.ts +2 -2
- package/dist/esm/buttons/MRT_ColumnPinningButtons.d.ts +0 -1
- package/dist/esm/buttons/MRT_EditActionButtons.d.ts +0 -1
- package/dist/esm/buttons/MRT_FullScreenToggleButton.d.ts +0 -1
- package/dist/esm/buttons/MRT_ShowHideColumnsButton.d.ts +0 -1
- package/dist/esm/buttons/MRT_ToggleDensePaddingButton.d.ts +0 -1
- package/dist/esm/buttons/MRT_ToggleFiltersButton.d.ts +0 -1
- package/dist/esm/buttons/MRT_ToggleGlobalFilterButton.d.ts +0 -1
- package/dist/esm/column.utils.d.ts +12 -1
- package/dist/esm/index.d.ts +4 -3
- package/dist/esm/inputs/MRT_EditCellTextField.d.ts +0 -1
- package/dist/esm/inputs/MRT_GlobalFilterTextField.d.ts +0 -1
- package/dist/esm/material-react-table.esm.js +245 -198
- package/dist/esm/material-react-table.esm.js.map +1 -1
- package/dist/esm/menus/MRT_FilterOptionMenu.d.ts +3 -4
- package/dist/esm/menus/MRT_ShowHideColumnsMenu.d.ts +0 -1
- package/dist/esm/table/MRT_Table.d.ts +1 -2
- package/dist/esm/table/MRT_TableRoot.d.ts +250 -3
- package/dist/esm/toolbar/MRT_TablePagination.d.ts +3 -4
- package/dist/esm/toolbar/MRT_ToolbarAlertBanner.d.ts +1 -1
- package/dist/esm/toolbar/MRT_ToolbarInternalButtons.d.ts +3 -4
- package/dist/esm/toolbar/MRT_TopToolbar.d.ts +1 -0
- package/dist/index.d.ts +47 -41
- package/package.json +7 -6
- package/src/MaterialReactTable.tsx +100 -23
- package/src/_locales/de.ts +0 -0
- package/src/{localization.ts → _locales/en.ts} +4 -82
- package/src/_locales/es.ts +86 -0
- package/src/_locales/fr.ts +0 -0
- package/src/_locales/hi.ts +0 -0
- package/src/_locales/id.ts +0 -0
- package/src/_locales/ja.ts +0 -0
- package/src/_locales/nl.ts +0 -0
- package/src/_locales/pt.ts +0 -0
- package/src/_locales/ru.ts +0 -0
- package/src/_locales/uk.ts +0 -0
- package/src/_locales/vi.ts +0 -0
- package/src/_locales/zh.ts +0 -0
- package/src/body/MRT_TableBody.tsx +54 -30
- package/src/body/MRT_TableBodyCell.tsx +11 -58
- package/src/body/MRT_TableBodyCellValue.tsx +7 -2
- package/src/body/MRT_TableBodyRowGrabHandle.tsx +5 -8
- package/src/buttons/MRT_GrabHandleButton.tsx +2 -2
- package/src/buttons/MRT_ToggleGlobalFilterButton.tsx +7 -2
- package/src/column.utils.ts +72 -0
- package/src/footer/MRT_TableFooter.tsx +3 -2
- package/src/footer/MRT_TableFooterCell.tsx +5 -15
- package/src/head/MRT_TableHead.tsx +10 -2
- package/src/head/MRT_TableHeadCell.tsx +9 -50
- package/src/head/MRT_TableHeadCellFilterLabel.tsx +7 -7
- package/src/head/MRT_TableHeadCellGrabHandle.tsx +5 -12
- package/src/index.tsx +6 -3
- package/src/inputs/MRT_FilterTextField.tsx +8 -7
- package/src/inputs/MRT_GlobalFilterTextField.tsx +7 -1
- package/src/menus/MRT_FilterOptionMenu.tsx +19 -2
- package/src/table/MRT_Table.tsx +3 -4
- package/src/table/MRT_TableContainer.tsx +2 -11
- package/src/table/MRT_TablePaper.tsx +34 -20
- package/src/table/MRT_TableRoot.tsx +34 -11
- package/src/toolbar/MRT_BottomToolbar.tsx +11 -2
- package/src/toolbar/MRT_TablePagination.tsx +7 -5
- package/src/toolbar/MRT_ToolbarAlertBanner.tsx +7 -1
- package/src/toolbar/MRT_ToolbarInternalButtons.tsx +14 -12
- package/src/toolbar/MRT_TopToolbar.tsx +13 -2
- package/dist/cjs/localization.d.ts +0 -82
- package/dist/esm/localization.d.ts +0 -82
|
@@ -14,7 +14,7 @@ export const MRT_TableBodyRowGrabHandle: FC<Props> = ({
|
|
|
14
14
|
table,
|
|
15
15
|
}) => {
|
|
16
16
|
const {
|
|
17
|
-
options: { muiTableBodyRowDragHandleProps
|
|
17
|
+
options: { muiTableBodyRowDragHandleProps },
|
|
18
18
|
} = table;
|
|
19
19
|
const { row } = cell;
|
|
20
20
|
|
|
@@ -23,17 +23,14 @@ export const MRT_TableBodyRowGrabHandle: FC<Props> = ({
|
|
|
23
23
|
? muiTableBodyRowDragHandleProps({ row, table })
|
|
24
24
|
: muiTableBodyRowDragHandleProps;
|
|
25
25
|
|
|
26
|
-
const handleDragStart = (
|
|
27
|
-
|
|
26
|
+
const handleDragStart = (event: DragEvent<HTMLButtonElement>) => {
|
|
27
|
+
iconButtonProps?.onDragStart?.(event);
|
|
28
|
+
event.dataTransfer.setDragImage(rowRef.current as HTMLElement, 0, 0);
|
|
28
29
|
table.setDraggingRow(row as any);
|
|
29
30
|
};
|
|
30
31
|
|
|
31
32
|
const handleDragEnd = (event: DragEvent<HTMLButtonElement>) => {
|
|
32
|
-
|
|
33
|
-
event,
|
|
34
|
-
draggedRow: table.getState().draggingRow as any,
|
|
35
|
-
targetRow: table.getState().hoveredRow as any,
|
|
36
|
-
});
|
|
33
|
+
iconButtonProps?.onDragEnd?.(event);
|
|
37
34
|
table.setDraggingRow(null);
|
|
38
35
|
table.setHoveredRow(null);
|
|
39
36
|
};
|
|
@@ -33,14 +33,14 @@ export const MRT_GrabHandleButton = <TData extends Record<string, any> = {}>({
|
|
|
33
33
|
<IconButton
|
|
34
34
|
disableRipple
|
|
35
35
|
draggable="true"
|
|
36
|
-
onDragStart={onDragStart}
|
|
37
|
-
onDragEnd={onDragEnd}
|
|
38
36
|
size="small"
|
|
39
37
|
{...iconButtonProps}
|
|
40
38
|
onClick={(e) => {
|
|
41
39
|
e.stopPropagation();
|
|
42
40
|
iconButtonProps?.onClick?.(e);
|
|
43
41
|
}}
|
|
42
|
+
onDragStart={onDragStart}
|
|
43
|
+
onDragEnd={onDragEnd}
|
|
44
44
|
sx={(theme) => ({
|
|
45
45
|
cursor: 'grab',
|
|
46
46
|
m: 0,
|
|
@@ -23,7 +23,7 @@ export const MRT_ToggleGlobalFilterButton = <
|
|
|
23
23
|
refs: { searchInputRef },
|
|
24
24
|
setShowGlobalFilter,
|
|
25
25
|
} = table;
|
|
26
|
-
const { showGlobalFilter } = getState();
|
|
26
|
+
const { globalFilter, showGlobalFilter } = getState();
|
|
27
27
|
|
|
28
28
|
const handleToggleSearch = () => {
|
|
29
29
|
setShowGlobalFilter(!showGlobalFilter);
|
|
@@ -32,7 +32,12 @@ export const MRT_ToggleGlobalFilterButton = <
|
|
|
32
32
|
|
|
33
33
|
return (
|
|
34
34
|
<Tooltip arrow title={rest?.title ?? localization.showHideSearch}>
|
|
35
|
-
<IconButton
|
|
35
|
+
<IconButton
|
|
36
|
+
disabled={!!globalFilter}
|
|
37
|
+
onClick={handleToggleSearch}
|
|
38
|
+
{...rest}
|
|
39
|
+
title={undefined}
|
|
40
|
+
>
|
|
36
41
|
{showGlobalFilter ? <SearchOffIcon /> : <SearchIcon />}
|
|
37
42
|
</IconButton>
|
|
38
43
|
</Tooltip>
|
package/src/column.utils.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ColumnOrderState, GroupingState } from '@tanstack/react-table';
|
|
2
|
+
import { alpha, lighten, TableCellProps, Theme } from '@mui/material';
|
|
2
3
|
import {
|
|
3
4
|
MaterialReactTableProps,
|
|
4
5
|
MRT_Column,
|
|
@@ -6,6 +7,8 @@ import {
|
|
|
6
7
|
MRT_DefinedColumnDef,
|
|
7
8
|
MRT_DisplayColumnIds,
|
|
8
9
|
MRT_FilterOption,
|
|
10
|
+
MRT_Header,
|
|
11
|
+
MRT_TableInstance,
|
|
9
12
|
} from '.';
|
|
10
13
|
import { MRT_FilterFns } from './filterFns';
|
|
11
14
|
import { MRT_SortingFns } from './sortingFns';
|
|
@@ -165,3 +168,72 @@ export const getDefaultColumnFilterFn = <
|
|
|
165
168
|
if (columnDef.filterVariant === 'range') return 'betweenInclusive';
|
|
166
169
|
return 'fuzzy';
|
|
167
170
|
};
|
|
171
|
+
|
|
172
|
+
export const getIsLastLeftPinnedColumn = (
|
|
173
|
+
table: MRT_TableInstance,
|
|
174
|
+
column: MRT_Column,
|
|
175
|
+
) => {
|
|
176
|
+
return (
|
|
177
|
+
column.getIsPinned() === 'left' &&
|
|
178
|
+
table.getLeftLeafHeaders().length - 1 === column.getPinnedIndex()
|
|
179
|
+
);
|
|
180
|
+
};
|
|
181
|
+
|
|
182
|
+
export const getIsFirstRightPinnedColumn = (column: MRT_Column) => {
|
|
183
|
+
return column.getIsPinned() === 'right' && column.getPinnedIndex() === 0;
|
|
184
|
+
};
|
|
185
|
+
|
|
186
|
+
export const getTotalRight = (table: MRT_TableInstance, column: MRT_Column) => {
|
|
187
|
+
return (
|
|
188
|
+
(table.getRightLeafHeaders().length - 1 - column.getPinnedIndex()) * 160
|
|
189
|
+
);
|
|
190
|
+
};
|
|
191
|
+
|
|
192
|
+
export const getCommonCellStyles = ({
|
|
193
|
+
column,
|
|
194
|
+
header,
|
|
195
|
+
table,
|
|
196
|
+
tableCellProps,
|
|
197
|
+
theme,
|
|
198
|
+
}: {
|
|
199
|
+
column: MRT_Column;
|
|
200
|
+
header?: MRT_Header;
|
|
201
|
+
table: MRT_TableInstance;
|
|
202
|
+
tableCellProps: TableCellProps;
|
|
203
|
+
theme: Theme;
|
|
204
|
+
}) => ({
|
|
205
|
+
backgroundColor:
|
|
206
|
+
column.getIsPinned() && column.columnDef.columnDefType !== 'group'
|
|
207
|
+
? alpha(lighten(theme.palette.background.default, 0.04), 0.95)
|
|
208
|
+
: 'inherit',
|
|
209
|
+
backgroundImage: 'inherit',
|
|
210
|
+
boxShadow: getIsLastLeftPinnedColumn(table, column)
|
|
211
|
+
? `-4px 0 8px -6px ${alpha(theme.palette.common.black, 0.2)} inset`
|
|
212
|
+
: getIsFirstRightPinnedColumn(column)
|
|
213
|
+
? `4px 0 8px -6px ${alpha(theme.palette.common.black, 0.2)} inset`
|
|
214
|
+
: undefined,
|
|
215
|
+
left:
|
|
216
|
+
column.getIsPinned() === 'left'
|
|
217
|
+
? `${column.getStart('left')}px`
|
|
218
|
+
: undefined,
|
|
219
|
+
opacity:
|
|
220
|
+
table.getState().draggingColumn?.id === column.id ||
|
|
221
|
+
table.getState().hoveredColumn?.id === column.id
|
|
222
|
+
? 0.5
|
|
223
|
+
: 1,
|
|
224
|
+
position:
|
|
225
|
+
column.getIsPinned() && column.columnDef.columnDefType !== 'group'
|
|
226
|
+
? 'sticky'
|
|
227
|
+
: undefined,
|
|
228
|
+
right:
|
|
229
|
+
column.getIsPinned() === 'right'
|
|
230
|
+
? `${getTotalRight(table, column)}px`
|
|
231
|
+
: undefined,
|
|
232
|
+
transition: `all ${column.getIsResizing() ? 0 : '0.2s'} ease-in-out`,
|
|
233
|
+
...(tableCellProps?.sx instanceof Function
|
|
234
|
+
? tableCellProps.sx(theme)
|
|
235
|
+
: (tableCellProps?.sx as any)),
|
|
236
|
+
maxWidth: `min(${column.getSize()}px, fit-content)`,
|
|
237
|
+
minWidth: `max(${column.getSize()}px, ${column.columnDef.minSize ?? 30}px)`,
|
|
238
|
+
width: header?.getSize() ?? column.getSize(),
|
|
239
|
+
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React, { FC } from 'react';
|
|
2
|
-
import { TableFooter } from '@mui/material';
|
|
2
|
+
import { lighten, TableFooter } from '@mui/material';
|
|
3
3
|
import { MRT_TableFooterRow } from './MRT_TableFooterRow';
|
|
4
4
|
import type { MRT_TableInstance } from '..';
|
|
5
5
|
|
|
@@ -27,7 +27,7 @@ export const MRT_TableFooter: FC<Props> = ({ table }) => {
|
|
|
27
27
|
<TableFooter
|
|
28
28
|
{...tableFooterProps}
|
|
29
29
|
sx={(theme) => ({
|
|
30
|
-
|
|
30
|
+
backgroundColor: lighten(theme.palette.background.default, 0.06),
|
|
31
31
|
bottom: stickFooter ? 0 : undefined,
|
|
32
32
|
opacity: stickFooter ? 0.95 : undefined,
|
|
33
33
|
outline: stickFooter
|
|
@@ -35,6 +35,7 @@ export const MRT_TableFooter: FC<Props> = ({ table }) => {
|
|
|
35
35
|
? `1px solid ${theme.palette.grey[300]}`
|
|
36
36
|
: `1px solid ${theme.palette.grey[700]}`
|
|
37
37
|
: undefined,
|
|
38
|
+
position: stickFooter ? 'sticky' : undefined,
|
|
38
39
|
...(tableFooterProps?.sx instanceof Function
|
|
39
40
|
? tableFooterProps?.sx(theme)
|
|
40
41
|
: (tableFooterProps?.sx as any)),
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import React, { FC } from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { TableCell } from '@mui/material';
|
|
3
|
+
import { getCommonCellStyles } from '../column.utils';
|
|
3
4
|
import type { MRT_Header, MRT_TableInstance } from '..';
|
|
4
5
|
|
|
5
6
|
interface Props {
|
|
@@ -10,7 +11,7 @@ interface Props {
|
|
|
10
11
|
export const MRT_TableFooterCell: FC<Props> = ({ footer, table }) => {
|
|
11
12
|
const {
|
|
12
13
|
getState,
|
|
13
|
-
options: { muiTableFooterCellProps
|
|
14
|
+
options: { muiTableFooterCellProps },
|
|
14
15
|
} = table;
|
|
15
16
|
const { density } = getState();
|
|
16
17
|
const { column } = footer;
|
|
@@ -39,26 +40,15 @@ export const MRT_TableFooterCell: FC<Props> = ({ footer, table }) => {
|
|
|
39
40
|
variant="head"
|
|
40
41
|
{...tableCellProps}
|
|
41
42
|
sx={(theme) => ({
|
|
42
|
-
backgroundColor: theme.palette.background.default,
|
|
43
|
-
backgroundImage: `linear-gradient(${alpha(
|
|
44
|
-
theme.palette.common.white,
|
|
45
|
-
0.05,
|
|
46
|
-
)},${alpha(theme.palette.common.white, 0.05)})`,
|
|
47
43
|
fontWeight: 'bold',
|
|
48
|
-
maxWidth: `${column.getSize()}px`,
|
|
49
|
-
minWidth: `${column.getSize()}px`,
|
|
50
44
|
p:
|
|
51
45
|
density === 'compact'
|
|
52
46
|
? '0.5rem'
|
|
53
47
|
: density === 'comfortable'
|
|
54
48
|
? '1rem'
|
|
55
49
|
: '1.5rem',
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
verticalAlign: 'text-top',
|
|
59
|
-
...(tableCellProps?.sx instanceof Function
|
|
60
|
-
? tableCellProps.sx(theme)
|
|
61
|
-
: (tableCellProps?.sx as any)),
|
|
50
|
+
verticalAlign: 'top',
|
|
51
|
+
...getCommonCellStyles({ column, table, theme, tableCellProps }),
|
|
62
52
|
})}
|
|
63
53
|
>
|
|
64
54
|
<>
|
|
@@ -10,7 +10,7 @@ interface Props {
|
|
|
10
10
|
export const MRT_TableHead: FC<Props> = ({ table }) => {
|
|
11
11
|
const {
|
|
12
12
|
getHeaderGroups,
|
|
13
|
-
options: { muiTableHeadProps },
|
|
13
|
+
options: { enableStickyHeader, muiTableHeadProps },
|
|
14
14
|
} = table;
|
|
15
15
|
|
|
16
16
|
const tableHeadProps =
|
|
@@ -19,7 +19,15 @@ export const MRT_TableHead: FC<Props> = ({ table }) => {
|
|
|
19
19
|
: muiTableHeadProps;
|
|
20
20
|
|
|
21
21
|
return (
|
|
22
|
-
<TableHead
|
|
22
|
+
<TableHead
|
|
23
|
+
{...tableHeadProps}
|
|
24
|
+
sx={(theme) => ({
|
|
25
|
+
opacity: enableStickyHeader ? 0.95 : undefined,
|
|
26
|
+
...(tableHeadProps?.sx instanceof Function
|
|
27
|
+
? tableHeadProps?.sx(theme)
|
|
28
|
+
: (tableHeadProps?.sx as any)),
|
|
29
|
+
})}
|
|
30
|
+
>
|
|
23
31
|
{getHeaderGroups().map((headerGroup) => (
|
|
24
32
|
<MRT_TableHeadRow
|
|
25
33
|
headerGroup={headerGroup as any}
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import React, { DragEvent, FC, ReactNode } from 'react';
|
|
2
|
-
import { Box, TableCell, Theme,
|
|
2
|
+
import { Box, TableCell, Theme, useTheme } from '@mui/material';
|
|
3
3
|
import { MRT_TableHeadCellColumnActionsButton } from './MRT_TableHeadCellColumnActionsButton';
|
|
4
4
|
import { MRT_TableHeadCellFilterContainer } from './MRT_TableHeadCellFilterContainer';
|
|
5
5
|
import { MRT_TableHeadCellFilterLabel } from './MRT_TableHeadCellFilterLabel';
|
|
6
6
|
import { MRT_TableHeadCellGrabHandle } from './MRT_TableHeadCellGrabHandle';
|
|
7
7
|
import { MRT_TableHeadCellResizeHandle } from './MRT_TableHeadCellResizeHandle';
|
|
8
8
|
import { MRT_TableHeadCellSortLabel } from './MRT_TableHeadCellSortLabel';
|
|
9
|
+
import { getCommonCellStyles } from '../column.utils';
|
|
9
10
|
import type { MRT_Header, MRT_TableInstance } from '..';
|
|
10
11
|
|
|
11
12
|
interface Props {
|
|
@@ -21,7 +22,6 @@ export const MRT_TableHeadCell: FC<Props> = ({ header, table }) => {
|
|
|
21
22
|
enableColumnActions,
|
|
22
23
|
enableColumnDragging,
|
|
23
24
|
enableColumnOrdering,
|
|
24
|
-
enableColumnResizing,
|
|
25
25
|
enableGrouping,
|
|
26
26
|
enableMultiSort,
|
|
27
27
|
muiTableHeadCellProps,
|
|
@@ -54,23 +54,6 @@ export const MRT_TableHeadCell: FC<Props> = ({ header, table }) => {
|
|
|
54
54
|
...mcTableHeadCellProps,
|
|
55
55
|
};
|
|
56
56
|
|
|
57
|
-
const getIsLastLeftPinnedColumn = () => {
|
|
58
|
-
return (
|
|
59
|
-
column.getIsPinned() === 'left' &&
|
|
60
|
-
table.getLeftLeafHeaders().length - 1 === column.getPinnedIndex()
|
|
61
|
-
);
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
const getIsFirstRightPinnedColumn = () => {
|
|
65
|
-
return column.getIsPinned() === 'right' && column.getPinnedIndex() === 0;
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
const getTotalRight = () => {
|
|
69
|
-
return (
|
|
70
|
-
(table.getRightLeafHeaders().length - 1 - column.getPinnedIndex()) * 150
|
|
71
|
-
);
|
|
72
|
-
};
|
|
73
|
-
|
|
74
57
|
const handleDragEnter = (_e: DragEvent) => {
|
|
75
58
|
if (enableGrouping && hoveredColumn?.id === 'drop-zone') {
|
|
76
59
|
setHoveredColumn(null);
|
|
@@ -115,26 +98,8 @@ export const MRT_TableHeadCell: FC<Props> = ({ header, table }) => {
|
|
|
115
98
|
ref={tableHeadCellRef}
|
|
116
99
|
{...tableCellProps}
|
|
117
100
|
sx={(theme: Theme) => ({
|
|
118
|
-
backgroundColor:
|
|
119
|
-
column.getIsPinned() && columnDefType !== 'group'
|
|
120
|
-
? alpha(lighten(theme.palette.background.default, 0.04), 0.95)
|
|
121
|
-
: 'inherit',
|
|
122
|
-
backgroundImage: 'inherit',
|
|
123
|
-
boxShadow: getIsLastLeftPinnedColumn()
|
|
124
|
-
? `4px 0 4px -2px ${alpha(theme.palette.common.black, 0.1)}`
|
|
125
|
-
: getIsFirstRightPinnedColumn()
|
|
126
|
-
? `-4px 0 4px -2px ${alpha(theme.palette.common.black, 0.1)}`
|
|
127
|
-
: undefined,
|
|
128
101
|
fontWeight: 'bold',
|
|
129
|
-
left:
|
|
130
|
-
column.getIsPinned() === 'left'
|
|
131
|
-
? `${column.getStart('left')}px`
|
|
132
|
-
: undefined,
|
|
133
102
|
overflow: 'visible',
|
|
134
|
-
opacity:
|
|
135
|
-
draggingColumn?.id === column.id || hoveredColumn?.id === column.id
|
|
136
|
-
? 0.5
|
|
137
|
-
: 1,
|
|
138
103
|
p:
|
|
139
104
|
density === 'compact'
|
|
140
105
|
? '0.5rem'
|
|
@@ -151,19 +116,12 @@ export const MRT_TableHeadCell: FC<Props> = ({ header, table }) => {
|
|
|
151
116
|
: showColumnFilters || density === 'compact'
|
|
152
117
|
? '0.4rem'
|
|
153
118
|
: '0.6rem',
|
|
154
|
-
position:
|
|
155
|
-
column.getIsPinned() && columnDefType !== 'group'
|
|
156
|
-
? 'sticky'
|
|
157
|
-
: undefined,
|
|
158
119
|
pt:
|
|
159
120
|
columnDefType === 'group' || density === 'compact'
|
|
160
121
|
? '0.25rem'
|
|
161
122
|
: density === 'comfortable'
|
|
162
123
|
? '.75rem'
|
|
163
124
|
: '1.25rem',
|
|
164
|
-
right:
|
|
165
|
-
column.getIsPinned() === 'right' ? `${getTotalRight()}px` : undefined,
|
|
166
|
-
transition: `all ${enableColumnResizing ? 0 : '0.2s'} ease-in-out`,
|
|
167
125
|
userSelect: enableMultiSort && column.getCanSort() ? 'none' : undefined,
|
|
168
126
|
verticalAlign: 'top',
|
|
169
127
|
zIndex:
|
|
@@ -172,13 +130,14 @@ export const MRT_TableHeadCell: FC<Props> = ({ header, table }) => {
|
|
|
172
130
|
: column.getIsPinned() && columnDefType !== 'group'
|
|
173
131
|
? 2
|
|
174
132
|
: 1,
|
|
175
|
-
...(
|
|
176
|
-
|
|
177
|
-
|
|
133
|
+
...getCommonCellStyles({
|
|
134
|
+
column,
|
|
135
|
+
header,
|
|
136
|
+
table,
|
|
137
|
+
tableCellProps,
|
|
138
|
+
theme,
|
|
139
|
+
}),
|
|
178
140
|
...draggingBorders,
|
|
179
|
-
maxWidth: `min(${column.getSize()}px, fit-content)`,
|
|
180
|
-
minWidth: `max(${column.getSize()}px, ${columnDef.minSize ?? 30}px)`,
|
|
181
|
-
width: header.getSize(),
|
|
182
141
|
})}
|
|
183
142
|
>
|
|
184
143
|
{header.isPlaceholder ? null : (
|
|
@@ -17,11 +17,11 @@ export const MRT_TableHeadCellFilterLabel: FC<Props> = ({ header, table }) => {
|
|
|
17
17
|
const { column } = header;
|
|
18
18
|
const { columnDef } = column;
|
|
19
19
|
|
|
20
|
-
const isRangeFilter =
|
|
21
|
-
'
|
|
22
|
-
'betweenInclusive',
|
|
23
|
-
|
|
24
|
-
|
|
20
|
+
const isRangeFilter =
|
|
21
|
+
columnDef.filterVariant === 'range' ||
|
|
22
|
+
['between', 'betweenInclusive', 'inNumberRange'].includes(
|
|
23
|
+
columnDef._filterFn,
|
|
24
|
+
);
|
|
25
25
|
const currentFilterOption = columnDef._filterFn;
|
|
26
26
|
const filterTooltip = localization.filteringByColumn
|
|
27
27
|
.replace('{column}', String(columnDef.header))
|
|
@@ -51,8 +51,8 @@ export const MRT_TableHeadCellFilterLabel: FC<Props> = ({ header, table }) => {
|
|
|
51
51
|
<Grow
|
|
52
52
|
unmountOnExit
|
|
53
53
|
in={
|
|
54
|
-
(!!column.getFilterValue() && isRangeFilter) ||
|
|
55
|
-
(
|
|
54
|
+
(!!column.getFilterValue() && !isRangeFilter) ||
|
|
55
|
+
(isRangeFilter && // @ts-ignore
|
|
56
56
|
(!!column.getFilterValue()?.[0] || !!column.getFilterValue()?.[1]))
|
|
57
57
|
}
|
|
58
58
|
>
|
|
@@ -16,11 +16,7 @@ export const MRT_TableHeadCellGrabHandle: FC<Props> = ({
|
|
|
16
16
|
}) => {
|
|
17
17
|
const {
|
|
18
18
|
getState,
|
|
19
|
-
options: {
|
|
20
|
-
enableColumnOrdering,
|
|
21
|
-
muiTableHeadCellDragHandleProps,
|
|
22
|
-
onColumnDrop,
|
|
23
|
-
},
|
|
19
|
+
options: { enableColumnOrdering, muiTableHeadCellDragHandleProps },
|
|
24
20
|
setColumnOrder,
|
|
25
21
|
setDraggingColumn,
|
|
26
22
|
setHoveredColumn,
|
|
@@ -43,17 +39,14 @@ export const MRT_TableHeadCellGrabHandle: FC<Props> = ({
|
|
|
43
39
|
...mcIconButtonProps,
|
|
44
40
|
};
|
|
45
41
|
|
|
46
|
-
const handleDragStart = (
|
|
42
|
+
const handleDragStart = (event: DragEvent<HTMLButtonElement>) => {
|
|
43
|
+
iconButtonProps?.onDragStart?.(event);
|
|
47
44
|
setDraggingColumn(column);
|
|
48
|
-
|
|
45
|
+
event.dataTransfer.setDragImage(tableHeadCellRef.current as HTMLElement, 0, 0);
|
|
49
46
|
};
|
|
50
47
|
|
|
51
48
|
const handleDragEnd = (event: DragEvent<HTMLButtonElement>) => {
|
|
52
|
-
|
|
53
|
-
event,
|
|
54
|
-
draggedColumn: column,
|
|
55
|
-
targetColumn: hoveredColumn,
|
|
56
|
-
});
|
|
49
|
+
iconButtonProps?.onDragEnd?.(event);
|
|
57
50
|
if (hoveredColumn?.id === 'drop-zone') {
|
|
58
51
|
column.toggleGrouping();
|
|
59
52
|
} else if (
|
package/src/index.tsx
CHANGED
|
@@ -3,23 +3,26 @@ export default MaterialReactTable;
|
|
|
3
3
|
export * from './MaterialReactTable';
|
|
4
4
|
|
|
5
5
|
import type { MRT_Icons } from './icons';
|
|
6
|
-
|
|
7
|
-
export type { MRT_Localization, MRT_Icons };
|
|
6
|
+
export type { MRT_Icons };
|
|
8
7
|
|
|
9
8
|
import { MRT_CopyButton } from './buttons/MRT_CopyButton';
|
|
10
9
|
import { MRT_FullScreenToggleButton } from './buttons/MRT_FullScreenToggleButton';
|
|
11
10
|
import { MRT_GlobalFilterTextField } from './inputs/MRT_GlobalFilterTextField';
|
|
12
11
|
import { MRT_ShowHideColumnsButton } from './buttons/MRT_ShowHideColumnsButton';
|
|
12
|
+
import { MRT_TablePagination } from './toolbar/MRT_TablePagination';
|
|
13
13
|
import { MRT_ToggleDensePaddingButton } from './buttons/MRT_ToggleDensePaddingButton';
|
|
14
14
|
import { MRT_ToggleFiltersButton } from './buttons/MRT_ToggleFiltersButton';
|
|
15
15
|
import { MRT_ToggleGlobalFilterButton } from './buttons/MRT_ToggleGlobalFilterButton';
|
|
16
|
+
import { MRT_ToolbarInternalButtons } from './toolbar/MRT_ToolbarInternalButtons';
|
|
16
17
|
|
|
17
18
|
export {
|
|
19
|
+
MRT_CopyButton,
|
|
18
20
|
MRT_FullScreenToggleButton,
|
|
19
21
|
MRT_GlobalFilterTextField,
|
|
20
22
|
MRT_ShowHideColumnsButton,
|
|
23
|
+
MRT_TablePagination,
|
|
21
24
|
MRT_ToggleDensePaddingButton,
|
|
22
25
|
MRT_ToggleFiltersButton,
|
|
23
26
|
MRT_ToggleGlobalFilterButton,
|
|
24
|
-
|
|
27
|
+
MRT_ToolbarInternalButtons,
|
|
25
28
|
};
|
|
@@ -3,7 +3,6 @@ import React, {
|
|
|
3
3
|
FC,
|
|
4
4
|
MouseEvent,
|
|
5
5
|
useCallback,
|
|
6
|
-
useEffect,
|
|
7
6
|
useState,
|
|
8
7
|
} from 'react';
|
|
9
8
|
import {
|
|
@@ -18,8 +17,8 @@ import {
|
|
|
18
17
|
TextFieldProps,
|
|
19
18
|
Tooltip,
|
|
20
19
|
} from '@mui/material';
|
|
21
|
-
import { MRT_FilterOptionMenu } from '../menus/MRT_FilterOptionMenu';
|
|
22
20
|
import type { MRT_Header, MRT_TableInstance } from '..';
|
|
21
|
+
import { MRT_FilterOptionMenu } from '../menus/MRT_FilterOptionMenu';
|
|
23
22
|
|
|
24
23
|
interface Props {
|
|
25
24
|
header: MRT_Header;
|
|
@@ -170,10 +169,6 @@ export const MRT_FilterTextField: FC<Props> = ({
|
|
|
170
169
|
setAnchorEl(event.currentTarget);
|
|
171
170
|
};
|
|
172
171
|
|
|
173
|
-
useEffect(() => {
|
|
174
|
-
setFilterValue('');
|
|
175
|
-
}, [columnDef._filterFn]);
|
|
176
|
-
|
|
177
172
|
if (columnDef.Filter) {
|
|
178
173
|
return <>{columnDef.Filter?.({ column, header, table })}</>;
|
|
179
174
|
}
|
|
@@ -313,7 +308,12 @@ export const MRT_FilterTextField: FC<Props> = ({
|
|
|
313
308
|
}}
|
|
314
309
|
sx={(theme) => ({
|
|
315
310
|
p: 0,
|
|
316
|
-
minWidth:
|
|
311
|
+
minWidth:
|
|
312
|
+
columnDef.filterVariant === 'range'
|
|
313
|
+
? '90px'
|
|
314
|
+
: !filterChipLabel
|
|
315
|
+
? '120px'
|
|
316
|
+
: 'auto',
|
|
317
317
|
width: '100%',
|
|
318
318
|
'& .MuiSelect-icon': {
|
|
319
319
|
mr: '1.5rem',
|
|
@@ -369,6 +369,7 @@ export const MRT_FilterTextField: FC<Props> = ({
|
|
|
369
369
|
header={header}
|
|
370
370
|
setAnchorEl={setAnchorEl}
|
|
371
371
|
table={table}
|
|
372
|
+
setFilterValue={setFilterValue}
|
|
372
373
|
/>
|
|
373
374
|
</>
|
|
374
375
|
);
|
|
@@ -62,7 +62,12 @@ export const MRT_GlobalFilterTextField = <
|
|
|
62
62
|
: muiSearchTextFieldProps;
|
|
63
63
|
|
|
64
64
|
return (
|
|
65
|
-
<Collapse
|
|
65
|
+
<Collapse
|
|
66
|
+
in={showGlobalFilter}
|
|
67
|
+
orientation="horizontal"
|
|
68
|
+
unmountOnExit
|
|
69
|
+
mountOnEnter
|
|
70
|
+
>
|
|
66
71
|
<TextField
|
|
67
72
|
placeholder={localization.search}
|
|
68
73
|
onChange={handleChange}
|
|
@@ -114,6 +119,7 @@ export const MRT_GlobalFilterTextField = <
|
|
|
114
119
|
anchorEl={anchorEl}
|
|
115
120
|
setAnchorEl={setAnchorEl}
|
|
116
121
|
table={table}
|
|
122
|
+
onSelect={handleClear}
|
|
117
123
|
/>
|
|
118
124
|
</Collapse>
|
|
119
125
|
);
|
|
@@ -4,9 +4,9 @@ import type {
|
|
|
4
4
|
MRT_FilterOption,
|
|
5
5
|
MRT_Header,
|
|
6
6
|
MRT_InternalFilterOption,
|
|
7
|
+
MRT_Localization,
|
|
7
8
|
MRT_TableInstance,
|
|
8
9
|
} from '..';
|
|
9
|
-
import { MRT_Localization } from '../localization';
|
|
10
10
|
|
|
11
11
|
export const mrtFilterOptions = (
|
|
12
12
|
localization: MRT_Localization,
|
|
@@ -102,6 +102,7 @@ interface Props<TData extends Record<string, any> = {}> {
|
|
|
102
102
|
header?: MRT_Header<TData>;
|
|
103
103
|
onSelect?: () => void;
|
|
104
104
|
setAnchorEl: (anchorEl: HTMLElement | null) => void;
|
|
105
|
+
setFilterValue?: (filterValue: any) => void;
|
|
105
106
|
table: MRT_TableInstance<TData>;
|
|
106
107
|
}
|
|
107
108
|
|
|
@@ -110,6 +111,7 @@ export const MRT_FilterOptionMenu = <TData extends Record<string, any> = {}>({
|
|
|
110
111
|
header,
|
|
111
112
|
onSelect,
|
|
112
113
|
setAnchorEl,
|
|
114
|
+
setFilterValue,
|
|
113
115
|
table,
|
|
114
116
|
}: Props<TData>) => {
|
|
115
117
|
const {
|
|
@@ -152,10 +154,25 @@ export const MRT_FilterOptionMenu = <TData extends Record<string, any> = {}>({
|
|
|
152
154
|
}));
|
|
153
155
|
if (['empty', 'notEmpty'].includes(option as string)) {
|
|
154
156
|
column.setFilterValue(' ');
|
|
155
|
-
} else if (
|
|
157
|
+
} else if (
|
|
158
|
+
columnDef?.filterVariant === 'multi-select' ||
|
|
159
|
+
['arrIncludesSome', 'arrIncludesAll', 'arrIncludes'].includes(
|
|
160
|
+
option as string,
|
|
161
|
+
)
|
|
162
|
+
) {
|
|
163
|
+
column.setFilterValue([]);
|
|
164
|
+
setFilterValue?.([]);
|
|
165
|
+
} else if (
|
|
166
|
+
columnDef?.filterVariant === 'range' ||
|
|
167
|
+
['between', 'betweenInclusive', 'inNumberRange'].includes(
|
|
168
|
+
option as MRT_FilterOption,
|
|
169
|
+
)
|
|
170
|
+
) {
|
|
156
171
|
column.setFilterValue(['', '']);
|
|
172
|
+
setFilterValue?.('');
|
|
157
173
|
} else {
|
|
158
174
|
column.setFilterValue('');
|
|
175
|
+
setFilterValue?.('');
|
|
159
176
|
}
|
|
160
177
|
} else {
|
|
161
178
|
setGlobalFilterFn(option);
|
package/src/table/MRT_Table.tsx
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, { FC
|
|
1
|
+
import React, { FC } from 'react';
|
|
2
2
|
import { Table } from '@mui/material';
|
|
3
3
|
import { MRT_TableHead } from '../head/MRT_TableHead';
|
|
4
4
|
import { MRT_TableBody } from '../body/MRT_TableBody';
|
|
@@ -6,11 +6,10 @@ import { MRT_TableFooter } from '../footer/MRT_TableFooter';
|
|
|
6
6
|
import { MRT_TableInstance } from '..';
|
|
7
7
|
|
|
8
8
|
interface Props {
|
|
9
|
-
tableContainerRef: RefObject<HTMLDivElement>;
|
|
10
9
|
table: MRT_TableInstance;
|
|
11
10
|
}
|
|
12
11
|
|
|
13
|
-
export const MRT_Table: FC<Props> = ({
|
|
12
|
+
export const MRT_Table: FC<Props> = ({ table }) => {
|
|
14
13
|
const {
|
|
15
14
|
getState,
|
|
16
15
|
options: {
|
|
@@ -44,7 +43,7 @@ export const MRT_Table: FC<Props> = ({ tableContainerRef, table }) => {
|
|
|
44
43
|
})}
|
|
45
44
|
>
|
|
46
45
|
{enableTableHead && <MRT_TableHead table={table} />}
|
|
47
|
-
<MRT_TableBody
|
|
46
|
+
<MRT_TableBody table={table} />
|
|
48
47
|
{enableTableFooter && <MRT_TableFooter table={table} />}
|
|
49
48
|
</Table>
|
|
50
49
|
);
|
|
@@ -1,10 +1,4 @@
|
|
|
1
|
-
import React, {
|
|
2
|
-
FC,
|
|
3
|
-
RefObject,
|
|
4
|
-
useEffect,
|
|
5
|
-
useLayoutEffect,
|
|
6
|
-
useState,
|
|
7
|
-
} from 'react';
|
|
1
|
+
import React, { FC, useEffect, useLayoutEffect, useState } from 'react';
|
|
8
2
|
import { TableContainer } from '@mui/material';
|
|
9
3
|
import { MRT_Table } from './MRT_Table';
|
|
10
4
|
import type { MRT_TableInstance } from '..';
|
|
@@ -77,10 +71,7 @@ export const MRT_TableContainer: FC<Props> = ({ table }) => {
|
|
|
77
71
|
...tableContainerProps?.style,
|
|
78
72
|
}}
|
|
79
73
|
>
|
|
80
|
-
<MRT_Table
|
|
81
|
-
tableContainerRef={tableContainerRef as RefObject<HTMLDivElement>}
|
|
82
|
-
table={table}
|
|
83
|
-
/>
|
|
74
|
+
<MRT_Table table={table} />
|
|
84
75
|
</TableContainer>
|
|
85
76
|
);
|
|
86
77
|
};
|