material-react-table 0.7.0-alpha.1 → 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 +203 -61
- package/dist/buttons/MRT_CopyButton.d.ts +1 -2
- package/dist/localization.d.ts +1 -0
- package/dist/material-react-table.cjs.development.js +303 -956
- 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 +303 -956
- package/dist/material-react-table.esm.js.map +1 -1
- package/dist/utils.d.ts +1 -1
- package/package.json +4 -4
- package/src/MaterialReactTable.tsx +380 -128
- package/src/body/MRT_TableBody.tsx +1 -1
- package/src/body/MRT_TableBodyCell.tsx +9 -6
- package/src/body/MRT_TableBodyRow.tsx +2 -2
- package/src/body/MRT_TableDetailPanel.tsx +6 -4
- package/src/buttons/MRT_CopyButton.tsx +3 -4
- package/src/buttons/MRT_EditActionButtons.tsx +5 -3
- package/src/buttons/MRT_ExpandButton.tsx +1 -1
- package/src/buttons/MRT_ToggleColumnActionMenuButton.tsx +5 -2
- package/src/buttons/MRT_ToggleRowActionMenuButton.tsx +6 -6
- package/src/buttons/MRT_ToggleSearchButton.tsx +6 -1
- package/src/footer/MRT_TableFooter.tsx +1 -1
- package/src/footer/MRT_TableFooterCell.tsx +2 -2
- package/src/footer/MRT_TableFooterRow.tsx +1 -1
- package/src/head/MRT_TableHead.tsx +1 -1
- package/src/head/MRT_TableHeadCell.tsx +22 -29
- package/src/head/MRT_TableHeadRow.tsx +1 -1
- package/src/inputs/MRT_EditCellTextField.tsx +30 -14
- package/src/inputs/MRT_FilterTextField.tsx +2 -2
- package/src/inputs/MRT_SearchTextField.tsx +8 -3
- package/src/inputs/MRT_SelectCheckbox.tsx +9 -7
- package/src/localization.ts +2 -1
- package/src/menus/MRT_RowActionMenu.tsx +7 -5
- package/src/menus/MRT_ShowHideColumnsMenuItems.tsx +4 -5
- package/src/table/MRT_Table.tsx +1 -1
- package/src/table/MRT_TableContainer.tsx +16 -20
- package/src/table/MRT_TablePaper.tsx +9 -5
- package/src/table/MRT_TableRoot.tsx +11 -8
- package/src/toolbar/MRT_LinearProgressBar.tsx +1 -1
- package/src/toolbar/MRT_TablePagination.tsx +6 -2
- package/src/toolbar/MRT_ToolbarAlertBanner.tsx +2 -1
- package/src/toolbar/MRT_ToolbarBottom.tsx +1 -1
- package/src/toolbar/MRT_ToolbarInternalButtons.tsx +5 -4
- package/src/toolbar/MRT_ToolbarTop.tsx +2 -2
|
@@ -22,7 +22,7 @@ export const MRT_TableBody: FC<Props> = ({ pinned, tableInstance }) => {
|
|
|
22
22
|
|
|
23
23
|
const mTableBodyProps =
|
|
24
24
|
muiTableBodyProps instanceof Function
|
|
25
|
-
? muiTableBodyProps(tableInstance)
|
|
25
|
+
? muiTableBodyProps({ tableInstance })
|
|
26
26
|
: muiTableBodyProps;
|
|
27
27
|
|
|
28
28
|
const tableBodyProps = {
|
|
@@ -16,6 +16,7 @@ export const MRT_TableBodyCell: FC<Props> = ({ cell, tableInstance }) => {
|
|
|
16
16
|
options: {
|
|
17
17
|
enableClickToCopy,
|
|
18
18
|
enableColumnPinning,
|
|
19
|
+
enableEditing,
|
|
19
20
|
isLoading,
|
|
20
21
|
muiTableBodyCellProps,
|
|
21
22
|
muiTableBodyCellSkeletonProps,
|
|
@@ -29,12 +30,12 @@ export const MRT_TableBodyCell: FC<Props> = ({ cell, tableInstance }) => {
|
|
|
29
30
|
|
|
30
31
|
const mTableCellBodyProps =
|
|
31
32
|
muiTableBodyCellProps instanceof Function
|
|
32
|
-
? muiTableBodyCellProps(cell)
|
|
33
|
+
? muiTableBodyCellProps({ cell, tableInstance })
|
|
33
34
|
: muiTableBodyCellProps;
|
|
34
35
|
|
|
35
36
|
const mcTableCellBodyProps =
|
|
36
37
|
column.muiTableBodyCellProps instanceof Function
|
|
37
|
-
? column.muiTableBodyCellProps(cell)
|
|
38
|
+
? column.muiTableBodyCellProps({ cell, tableInstance })
|
|
38
39
|
: column.muiTableBodyCellProps;
|
|
39
40
|
|
|
40
41
|
const tableCellProps = {
|
|
@@ -55,7 +56,7 @@ export const MRT_TableBodyCell: FC<Props> = ({ cell, tableInstance }) => {
|
|
|
55
56
|
return (
|
|
56
57
|
<TableCell
|
|
57
58
|
onClick={(event: MouseEvent<HTMLTableCellElement>) =>
|
|
58
|
-
onCellClick?.(event, cell)
|
|
59
|
+
onCellClick?.({ event, cell, tableInstance })
|
|
59
60
|
}
|
|
60
61
|
{...tableCellProps}
|
|
61
62
|
sx={{
|
|
@@ -93,19 +94,21 @@ export const MRT_TableBodyCell: FC<Props> = ({ cell, tableInstance }) => {
|
|
|
93
94
|
column.id !==
|
|
94
95
|
row.groupingColumnId) ? null : cell.getIsAggregated() ? (
|
|
95
96
|
cell.renderAggregatedCell()
|
|
96
|
-
) :
|
|
97
|
+
) : enableEditing &&
|
|
98
|
+
column.enableEditing !== false &&
|
|
99
|
+
currentEditingRow?.id === row.id ? (
|
|
97
100
|
<MRT_EditCellTextField cell={cell} tableInstance={tableInstance} />
|
|
98
101
|
) : (enableClickToCopy || column.enableClickToCopy) &&
|
|
99
102
|
column.enableClickToCopy !== false ? (
|
|
100
103
|
<>
|
|
101
104
|
<MRT_CopyButton cell={cell} tableInstance={tableInstance}>
|
|
102
|
-
{cell.renderCell()}
|
|
105
|
+
{cell.column?.Cell?.({ cell, tableInstance }) ?? cell.renderCell()}
|
|
103
106
|
</MRT_CopyButton>
|
|
104
107
|
{row.getIsGrouped() && <> ({row.subRows?.length})</>}
|
|
105
108
|
</>
|
|
106
109
|
) : (
|
|
107
110
|
<>
|
|
108
|
-
{cell.renderCell()}
|
|
111
|
+
{cell.column?.Cell?.({ cell, tableInstance }) ?? cell.renderCell()}
|
|
109
112
|
{row.getIsGrouped() && <> ({row.subRows?.length})</>}
|
|
110
113
|
</>
|
|
111
114
|
)}
|
|
@@ -27,7 +27,7 @@ export const MRT_TableBodyRow: FC<Props> = ({ pinned, row, tableInstance }) => {
|
|
|
27
27
|
|
|
28
28
|
const mTableBodyRowProps =
|
|
29
29
|
muiTableBodyRowProps instanceof Function
|
|
30
|
-
? muiTableBodyRowProps(row)
|
|
30
|
+
? muiTableBodyRowProps({ row, tableInstance })
|
|
31
31
|
: muiTableBodyRowProps;
|
|
32
32
|
|
|
33
33
|
const tableRowProps = {
|
|
@@ -47,7 +47,7 @@ export const MRT_TableBodyRow: FC<Props> = ({ pinned, row, tableInstance }) => {
|
|
|
47
47
|
<TableRow
|
|
48
48
|
hover
|
|
49
49
|
onClick={(event: MouseEvent<HTMLTableRowElement>) =>
|
|
50
|
-
onRowClick?.(event, row)
|
|
50
|
+
onRowClick?.({ event, row, tableInstance })
|
|
51
51
|
}
|
|
52
52
|
selected={getIsSelected()}
|
|
53
53
|
{...tableRowProps}
|
|
@@ -20,12 +20,12 @@ export const MRT_TableDetailPanel: FC<Props> = ({ row, tableInstance }) => {
|
|
|
20
20
|
|
|
21
21
|
const tableRowProps =
|
|
22
22
|
muiTableBodyRowProps instanceof Function
|
|
23
|
-
? muiTableBodyRowProps(row)
|
|
23
|
+
? muiTableBodyRowProps({ row, tableInstance })
|
|
24
24
|
: muiTableBodyRowProps;
|
|
25
25
|
|
|
26
26
|
const tableCellProps =
|
|
27
27
|
muiTableDetailPanelProps instanceof Function
|
|
28
|
-
? muiTableDetailPanelProps(row)
|
|
28
|
+
? muiTableDetailPanelProps({ row, tableInstance })
|
|
29
29
|
: muiTableDetailPanelProps;
|
|
30
30
|
|
|
31
31
|
return (
|
|
@@ -33,7 +33,7 @@ export const MRT_TableDetailPanel: FC<Props> = ({ row, tableInstance }) => {
|
|
|
33
33
|
<TableCell
|
|
34
34
|
colSpan={getVisibleFlatColumns().length + 10}
|
|
35
35
|
onClick={(event: MouseEvent<HTMLTableCellElement>) =>
|
|
36
|
-
onDetailPanelClick?.(event, row)
|
|
36
|
+
onDetailPanelClick?.({ event, row, tableInstance })
|
|
37
37
|
}
|
|
38
38
|
{...tableCellProps}
|
|
39
39
|
sx={{
|
|
@@ -44,7 +44,9 @@ export const MRT_TableDetailPanel: FC<Props> = ({ row, tableInstance }) => {
|
|
|
44
44
|
...tableCellProps?.sx,
|
|
45
45
|
}}
|
|
46
46
|
>
|
|
47
|
-
<Collapse in={row.getIsExpanded()}>
|
|
47
|
+
<Collapse in={row.getIsExpanded()}>
|
|
48
|
+
{renderDetailPanel?.({ row, tableInstance })}
|
|
49
|
+
</Collapse>
|
|
48
50
|
</TableCell>
|
|
49
51
|
</TableRow>
|
|
50
52
|
);
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import React, { FC,
|
|
1
|
+
import React, { FC, useState } from 'react';
|
|
2
2
|
import { Button, Tooltip } from '@mui/material';
|
|
3
3
|
import { MRT_Cell, MRT_TableInstance } from '..';
|
|
4
4
|
|
|
5
5
|
interface Props {
|
|
6
6
|
cell: MRT_Cell;
|
|
7
|
-
children: ReactNode;
|
|
8
7
|
tableInstance: MRT_TableInstance;
|
|
9
8
|
}
|
|
10
9
|
|
|
@@ -27,12 +26,12 @@ export const MRT_CopyButton: FC<Props> = ({
|
|
|
27
26
|
|
|
28
27
|
const mTableBodyCellCopyButtonProps =
|
|
29
28
|
muiTableBodyCellCopyButtonProps instanceof Function
|
|
30
|
-
? muiTableBodyCellCopyButtonProps(cell)
|
|
29
|
+
? muiTableBodyCellCopyButtonProps({ cell, tableInstance })
|
|
31
30
|
: muiTableBodyCellCopyButtonProps;
|
|
32
31
|
|
|
33
32
|
const mcTableBodyCellCopyButtonProps =
|
|
34
33
|
cell.column.muiTableBodyCellCopyButtonProps instanceof Function
|
|
35
|
-
? cell.column.muiTableBodyCellCopyButtonProps(cell)
|
|
34
|
+
? cell.column.muiTableBodyCellCopyButtonProps({ cell, tableInstance })
|
|
36
35
|
: cell.column.muiTableBodyCellCopyButtonProps;
|
|
37
36
|
|
|
38
37
|
const buttonProps = {
|
|
@@ -14,18 +14,20 @@ export const MRT_EditActionButtons: FC<Props> = ({ row, tableInstance }) => {
|
|
|
14
14
|
options: {
|
|
15
15
|
icons: { CancelIcon, SaveIcon },
|
|
16
16
|
localization,
|
|
17
|
-
|
|
17
|
+
onEditSubmit,
|
|
18
18
|
setCurrentEditingRow,
|
|
19
19
|
},
|
|
20
20
|
} = tableInstance;
|
|
21
21
|
|
|
22
|
+
const { currentEditingRow } = getState();
|
|
23
|
+
|
|
22
24
|
const handleCancel = () => {
|
|
23
25
|
row.values = (row.original as RowValues) ?? {};
|
|
24
26
|
setCurrentEditingRow(null);
|
|
25
27
|
};
|
|
26
28
|
|
|
27
|
-
const handleSave =
|
|
28
|
-
|
|
29
|
+
const handleSave = () => {
|
|
30
|
+
onEditSubmit?.({ row: currentEditingRow ?? row, tableInstance });
|
|
29
31
|
setCurrentEditingRow(null);
|
|
30
32
|
};
|
|
31
33
|
|
|
@@ -22,7 +22,7 @@ export const MRT_ExpandButton: FC<Props> = ({ row, tableInstance }) => {
|
|
|
22
22
|
|
|
23
23
|
const handleToggleExpand = (event: MouseEvent<HTMLButtonElement>) => {
|
|
24
24
|
row.toggleExpanded();
|
|
25
|
-
onRowExpandChange?.(event, row);
|
|
25
|
+
onRowExpandChange?.({ event, row, tableInstance });
|
|
26
26
|
};
|
|
27
27
|
|
|
28
28
|
return (
|
|
@@ -32,12 +32,15 @@ export const MRT_ToggleColumnActionMenuButton: FC<Props> = ({
|
|
|
32
32
|
|
|
33
33
|
const mTableHeadCellColumnActionsButtonProps =
|
|
34
34
|
muiTableHeadCellColumnActionsButtonProps instanceof Function
|
|
35
|
-
? muiTableHeadCellColumnActionsButtonProps(column)
|
|
35
|
+
? muiTableHeadCellColumnActionsButtonProps({ column, tableInstance })
|
|
36
36
|
: muiTableHeadCellColumnActionsButtonProps;
|
|
37
37
|
|
|
38
38
|
const mcTableHeadCellColumnActionsButtonProps =
|
|
39
39
|
column.muiTableHeadCellColumnActionsButtonProps instanceof Function
|
|
40
|
-
? column.muiTableHeadCellColumnActionsButtonProps(
|
|
40
|
+
? column.muiTableHeadCellColumnActionsButtonProps({
|
|
41
|
+
column,
|
|
42
|
+
tableInstance,
|
|
43
|
+
})
|
|
41
44
|
: column.muiTableHeadCellColumnActionsButtonProps;
|
|
42
45
|
|
|
43
46
|
const iconButtonProps = {
|
|
@@ -27,7 +27,7 @@ export const MRT_ToggleRowActionMenuButton: FC<Props> = ({
|
|
|
27
27
|
const {
|
|
28
28
|
getState,
|
|
29
29
|
options: {
|
|
30
|
-
|
|
30
|
+
enableEditing,
|
|
31
31
|
icons: { EditIcon, MoreHorizIcon },
|
|
32
32
|
localization,
|
|
33
33
|
renderRowActionMenuItems,
|
|
@@ -46,7 +46,7 @@ export const MRT_ToggleRowActionMenuButton: FC<Props> = ({
|
|
|
46
46
|
setAnchorEl(event.currentTarget);
|
|
47
47
|
};
|
|
48
48
|
|
|
49
|
-
const
|
|
49
|
+
const handleStartEditMode = () => {
|
|
50
50
|
setCurrentEditingRow({ ...row });
|
|
51
51
|
setAnchorEl(null);
|
|
52
52
|
};
|
|
@@ -54,12 +54,12 @@ export const MRT_ToggleRowActionMenuButton: FC<Props> = ({
|
|
|
54
54
|
return (
|
|
55
55
|
<>
|
|
56
56
|
{renderRowActions ? (
|
|
57
|
-
<>{renderRowActions(row, tableInstance)}</>
|
|
57
|
+
<>{renderRowActions({ row, tableInstance })}</>
|
|
58
58
|
) : row.id === currentEditingRow?.id ? (
|
|
59
59
|
<MRT_EditActionButtons row={row} tableInstance={tableInstance} />
|
|
60
|
-
) : !renderRowActionMenuItems &&
|
|
60
|
+
) : !renderRowActionMenuItems && enableEditing ? (
|
|
61
61
|
<Tooltip placement="right" arrow title={localization.edit}>
|
|
62
|
-
<IconButton sx={commonIconButtonStyles} onClick={
|
|
62
|
+
<IconButton sx={commonIconButtonStyles} onClick={handleStartEditMode}>
|
|
63
63
|
<EditIcon />
|
|
64
64
|
</IconButton>
|
|
65
65
|
</Tooltip>
|
|
@@ -82,7 +82,7 @@ export const MRT_ToggleRowActionMenuButton: FC<Props> = ({
|
|
|
82
82
|
</Tooltip>
|
|
83
83
|
<MRT_RowActionMenu
|
|
84
84
|
anchorEl={anchorEl}
|
|
85
|
-
handleEdit={
|
|
85
|
+
handleEdit={handleStartEditMode}
|
|
86
86
|
row={row}
|
|
87
87
|
setAnchorEl={setAnchorEl}
|
|
88
88
|
tableInstance={tableInstance}
|
|
@@ -23,13 +23,18 @@ export const MRT_ToggleSearchButton: FC<Props> = ({
|
|
|
23
23
|
|
|
24
24
|
const { showSearch } = getState();
|
|
25
25
|
|
|
26
|
+
const textFieldProps =
|
|
27
|
+
muiSearchTextFieldProps instanceof Function
|
|
28
|
+
? muiSearchTextFieldProps({ tableInstance })
|
|
29
|
+
: muiSearchTextFieldProps;
|
|
30
|
+
|
|
26
31
|
const handleToggleSearch = () => {
|
|
27
32
|
setShowSearch(!showSearch);
|
|
28
33
|
setTimeout(
|
|
29
34
|
() =>
|
|
30
35
|
document
|
|
31
36
|
.getElementById(
|
|
32
|
-
|
|
37
|
+
textFieldProps?.id ?? `mrt-${idPrefix}-search-text-field`,
|
|
33
38
|
)
|
|
34
39
|
?.focus(),
|
|
35
40
|
200,
|
|
@@ -19,7 +19,7 @@ export const MRT_TableFooter: FC<Props> = ({ pinned, tableInstance }) => {
|
|
|
19
19
|
|
|
20
20
|
const tableFooterProps =
|
|
21
21
|
muiTableFooterProps instanceof Function
|
|
22
|
-
? muiTableFooterProps(tableInstance)
|
|
22
|
+
? muiTableFooterProps({ tableInstance })
|
|
23
23
|
: muiTableFooterProps;
|
|
24
24
|
|
|
25
25
|
const getFooterGroupsMap = {
|
|
@@ -19,12 +19,12 @@ export const MRT_TableFooterCell: FC<Props> = ({ footer, tableInstance }) => {
|
|
|
19
19
|
|
|
20
20
|
const mTableFooterCellProps =
|
|
21
21
|
muiTableFooterCellProps instanceof Function
|
|
22
|
-
? muiTableFooterCellProps(column)
|
|
22
|
+
? muiTableFooterCellProps({ column, tableInstance })
|
|
23
23
|
: muiTableFooterCellProps;
|
|
24
24
|
|
|
25
25
|
const mcTableFooterCellProps =
|
|
26
26
|
column.muiTableFooterCellProps instanceof Function
|
|
27
|
-
? column.muiTableFooterCellProps(column)
|
|
27
|
+
? column.muiTableFooterCellProps({ column, tableInstance })
|
|
28
28
|
: column.muiTableFooterCellProps;
|
|
29
29
|
|
|
30
30
|
const tableCellProps = {
|
|
@@ -26,7 +26,7 @@ export const MRT_TableFooterRow: FC<Props> = ({
|
|
|
26
26
|
|
|
27
27
|
const mTableFooterRowProps =
|
|
28
28
|
muiTableFooterRowProps instanceof Function
|
|
29
|
-
? muiTableFooterRowProps(footerGroup)
|
|
29
|
+
? muiTableFooterRowProps({ footerGroup, tableInstance })
|
|
30
30
|
: muiTableFooterRowProps;
|
|
31
31
|
|
|
32
32
|
const tableRowProps = {
|
|
@@ -19,7 +19,7 @@ export const MRT_TableHead: FC<Props> = ({ pinned, tableInstance }) => {
|
|
|
19
19
|
|
|
20
20
|
const tableHeadProps =
|
|
21
21
|
muiTableHeadProps instanceof Function
|
|
22
|
-
? muiTableHeadProps(tableInstance)
|
|
22
|
+
? muiTableHeadProps({ tableInstance })
|
|
23
23
|
: muiTableHeadProps;
|
|
24
24
|
|
|
25
25
|
const getHeaderGroupsMap = {
|
|
@@ -40,12 +40,12 @@ export const MRT_TableHeadCell: FC<Props> = ({ header, tableInstance }) => {
|
|
|
40
40
|
|
|
41
41
|
const mTableHeadCellProps =
|
|
42
42
|
muiTableHeadCellProps instanceof Function
|
|
43
|
-
? muiTableHeadCellProps(column)
|
|
43
|
+
? muiTableHeadCellProps({ column, tableInstance })
|
|
44
44
|
: muiTableHeadCellProps;
|
|
45
45
|
|
|
46
46
|
const mcTableHeadCellProps =
|
|
47
47
|
column.muiTableHeadCellProps instanceof Function
|
|
48
|
-
? column.muiTableHeadCellProps(column)
|
|
48
|
+
? column.muiTableHeadCellProps({ column, tableInstance })
|
|
49
49
|
: column.muiTableHeadCellProps;
|
|
50
50
|
|
|
51
51
|
const tableCellProps = {
|
|
@@ -57,35 +57,28 @@ export const MRT_TableHeadCell: FC<Props> = ({ header, tableInstance }) => {
|
|
|
57
57
|
const sortTooltip = !!column.getIsSorted()
|
|
58
58
|
? column.getIsSorted() === 'desc'
|
|
59
59
|
? localization.clearSort
|
|
60
|
-
: localization.sortByColumnDesc.replace(
|
|
61
|
-
|
|
62
|
-
column.header as string,
|
|
63
|
-
)
|
|
64
|
-
: localization.sortByColumnAsc.replace('{column}', column.header as string);
|
|
60
|
+
: localization.sortByColumnDesc.replace('{column}', column.header)
|
|
61
|
+
: localization.sortByColumnAsc.replace('{column}', column.header);
|
|
65
62
|
|
|
66
|
-
|
|
63
|
+
const filterType = getState()?.currentFilterTypes?.[header.id];
|
|
67
64
|
|
|
68
|
-
const filterTooltip =
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
// getColumnFilterValue() as string,
|
|
86
|
-
// )
|
|
87
|
-
// .replace('" "', '')
|
|
88
|
-
// : localization.showHideFilters;
|
|
65
|
+
const filterTooltip = !!column.getColumnFilterValue()
|
|
66
|
+
? localization.filteringByColumn
|
|
67
|
+
.replace('{column}', String(column.header))
|
|
68
|
+
.replace(
|
|
69
|
+
'{filterType}',
|
|
70
|
+
filterType instanceof Function
|
|
71
|
+
? ''
|
|
72
|
+
: // @ts-ignore
|
|
73
|
+
localization[
|
|
74
|
+
`filter${
|
|
75
|
+
filterType.charAt(0).toUpperCase() + filterType.slice(1)
|
|
76
|
+
}`
|
|
77
|
+
],
|
|
78
|
+
)
|
|
79
|
+
.replace('{filterValue}', column.getColumnFilterValue() as string)
|
|
80
|
+
.replace('" "', '')
|
|
81
|
+
: localization.showHideFilters;
|
|
89
82
|
|
|
90
83
|
const headerElement =
|
|
91
84
|
column?.Header?.({
|
|
@@ -15,7 +15,7 @@ export const MRT_TableHeadRow: FC<Props> = ({ headerGroup, tableInstance }) => {
|
|
|
15
15
|
|
|
16
16
|
const mTableHeadRowProps =
|
|
17
17
|
muiTableHeadRowProps instanceof Function
|
|
18
|
-
? muiTableHeadRowProps(headerGroup)
|
|
18
|
+
? muiTableHeadRowProps({ headerGroup, tableInstance })
|
|
19
19
|
: muiTableHeadRowProps;
|
|
20
20
|
|
|
21
21
|
const tableRowProps = {
|
|
@@ -1,6 +1,12 @@
|
|
|
1
|
-
import React, {
|
|
1
|
+
import React, {
|
|
2
|
+
ChangeEvent,
|
|
3
|
+
FC,
|
|
4
|
+
FocusEvent,
|
|
5
|
+
MouseEvent,
|
|
6
|
+
useState,
|
|
7
|
+
} from 'react';
|
|
2
8
|
import { TextField } from '@mui/material';
|
|
3
|
-
import type { MRT_Cell, MRT_TableInstance } from '..';
|
|
9
|
+
import type { MRT_Cell, MRT_Row, MRT_TableInstance } from '..';
|
|
4
10
|
|
|
5
11
|
interface Props {
|
|
6
12
|
cell: MRT_Cell;
|
|
@@ -10,29 +16,38 @@ interface Props {
|
|
|
10
16
|
export const MRT_EditCellTextField: FC<Props> = ({ cell, tableInstance }) => {
|
|
11
17
|
const {
|
|
12
18
|
getState,
|
|
13
|
-
options: {
|
|
19
|
+
options: {
|
|
20
|
+
enableEditing,
|
|
21
|
+
muiTableBodyCellEditTextFieldProps,
|
|
22
|
+
setCurrentEditingRow,
|
|
23
|
+
},
|
|
14
24
|
} = tableInstance;
|
|
15
25
|
|
|
26
|
+
const [value, setValue] = useState(cell.value);
|
|
27
|
+
|
|
16
28
|
const { column, row } = cell;
|
|
17
29
|
|
|
18
30
|
const handleChange = (event: ChangeEvent<HTMLInputElement>) => {
|
|
31
|
+
setValue(event.target.value);
|
|
32
|
+
column.onCellEditChange?.({ event, cell, tableInstance });
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
const handleBlur = (event: FocusEvent<HTMLInputElement>) => {
|
|
19
36
|
if (getState().currentEditingRow) {
|
|
20
|
-
row.values[column.id] =
|
|
21
|
-
|
|
22
|
-
// ...getState().currentEditingRow,
|
|
23
|
-
// });
|
|
37
|
+
row.values[column.id] = value;
|
|
38
|
+
setCurrentEditingRow({ ...getState().currentEditingRow } as MRT_Row);
|
|
24
39
|
}
|
|
25
|
-
column.
|
|
40
|
+
column.onCellEditBlur?.({ event, cell, tableInstance });
|
|
26
41
|
};
|
|
27
42
|
|
|
28
43
|
const mTableBodyCellEditTextFieldProps =
|
|
29
44
|
muiTableBodyCellEditTextFieldProps instanceof Function
|
|
30
|
-
? muiTableBodyCellEditTextFieldProps(cell)
|
|
45
|
+
? muiTableBodyCellEditTextFieldProps({ cell, tableInstance })
|
|
31
46
|
: muiTableBodyCellEditTextFieldProps;
|
|
32
47
|
|
|
33
48
|
const mcTableBodyCellEditTextFieldProps =
|
|
34
49
|
column.muiTableBodyCellEditTextFieldProps instanceof Function
|
|
35
|
-
? column.muiTableBodyCellEditTextFieldProps(cell)
|
|
50
|
+
? column.muiTableBodyCellEditTextFieldProps({ cell, tableInstance })
|
|
36
51
|
: column.muiTableBodyCellEditTextFieldProps;
|
|
37
52
|
|
|
38
53
|
const textFieldProps = {
|
|
@@ -40,17 +55,18 @@ export const MRT_EditCellTextField: FC<Props> = ({ cell, tableInstance }) => {
|
|
|
40
55
|
...mcTableBodyCellEditTextFieldProps,
|
|
41
56
|
};
|
|
42
57
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
58
|
+
if (enableEditing && column.enableEditing !== false && column.Edit) {
|
|
59
|
+
return <>{column.Edit?.({ cell, tableInstance })}</>;
|
|
60
|
+
}
|
|
46
61
|
|
|
47
62
|
return (
|
|
48
63
|
<TextField
|
|
49
64
|
margin="dense"
|
|
65
|
+
onBlur={handleBlur}
|
|
50
66
|
onChange={handleChange}
|
|
51
67
|
onClick={(e: MouseEvent<HTMLInputElement>) => e.stopPropagation()}
|
|
52
68
|
placeholder={column.header}
|
|
53
|
-
value={
|
|
69
|
+
value={value}
|
|
54
70
|
variant="standard"
|
|
55
71
|
{...textFieldProps}
|
|
56
72
|
/>
|
|
@@ -44,12 +44,12 @@ export const MRT_FilterTextField: FC<Props> = ({ header, tableInstance }) => {
|
|
|
44
44
|
|
|
45
45
|
const mTableHeadCellFilterTextFieldProps =
|
|
46
46
|
muiTableHeadCellFilterTextFieldProps instanceof Function
|
|
47
|
-
? muiTableHeadCellFilterTextFieldProps(column)
|
|
47
|
+
? muiTableHeadCellFilterTextFieldProps({ column, tableInstance })
|
|
48
48
|
: muiTableHeadCellFilterTextFieldProps;
|
|
49
49
|
|
|
50
50
|
const mcTableHeadCellFilterTextFieldProps =
|
|
51
51
|
column.muiTableHeadCellFilterTextFieldProps instanceof Function
|
|
52
|
-
? column.muiTableHeadCellFilterTextFieldProps(column)
|
|
52
|
+
? column.muiTableHeadCellFilterTextFieldProps({ column, tableInstance })
|
|
53
53
|
: column.muiTableHeadCellFilterTextFieldProps;
|
|
54
54
|
|
|
55
55
|
const textFieldProps = {
|
|
@@ -41,7 +41,7 @@ export const MRT_SearchTextField: FC<Props> = ({ tableInstance }) => {
|
|
|
41
41
|
const handleChange = useCallback(
|
|
42
42
|
debounce((event: ChangeEvent<HTMLInputElement>) => {
|
|
43
43
|
setGlobalFilter(event.target.value ?? undefined);
|
|
44
|
-
onGlobalFilterChange?.(event);
|
|
44
|
+
onGlobalFilterChange?.({ event, tableInstance });
|
|
45
45
|
}, 200),
|
|
46
46
|
[],
|
|
47
47
|
);
|
|
@@ -55,6 +55,11 @@ export const MRT_SearchTextField: FC<Props> = ({ tableInstance }) => {
|
|
|
55
55
|
setGlobalFilter(undefined);
|
|
56
56
|
};
|
|
57
57
|
|
|
58
|
+
const textFieldProps =
|
|
59
|
+
muiSearchTextFieldProps instanceof Function
|
|
60
|
+
? muiSearchTextFieldProps({ tableInstance })
|
|
61
|
+
: muiSearchTextFieldProps;
|
|
62
|
+
|
|
58
63
|
return (
|
|
59
64
|
<Collapse in={showSearch} orientation="horizontal">
|
|
60
65
|
<TextField
|
|
@@ -97,8 +102,8 @@ export const MRT_SearchTextField: FC<Props> = ({ tableInstance }) => {
|
|
|
97
102
|
</InputAdornment>
|
|
98
103
|
),
|
|
99
104
|
}}
|
|
100
|
-
{...
|
|
101
|
-
sx={{ justifySelf: 'end', ...
|
|
105
|
+
{...textFieldProps}
|
|
106
|
+
sx={{ justifySelf: 'end', ...textFieldProps?.sx }}
|
|
102
107
|
/>
|
|
103
108
|
<MRT_FilterTypeMenu
|
|
104
109
|
anchorEl={anchorEl}
|
|
@@ -32,27 +32,29 @@ export const MRT_SelectCheckbox: FC<Props> = ({
|
|
|
32
32
|
const handleSelectChange = (event: ChangeEvent<HTMLInputElement>) => {
|
|
33
33
|
if (selectAll) {
|
|
34
34
|
getToggleAllRowsSelectedProps?.()?.onChange?.(event as any);
|
|
35
|
-
onSelectAllChange?.(
|
|
35
|
+
onSelectAllChange?.({
|
|
36
36
|
event,
|
|
37
|
-
event.target.checked ? getRowModel().flatRows : [],
|
|
38
|
-
|
|
37
|
+
selectedRows: event.target.checked ? getRowModel().flatRows : [],
|
|
38
|
+
tableInstance,
|
|
39
|
+
});
|
|
39
40
|
} else if (row) {
|
|
40
41
|
row?.getToggleSelectedProps()?.onChange?.(event as any);
|
|
41
|
-
onSelectChange?.(
|
|
42
|
+
onSelectChange?.({
|
|
42
43
|
event,
|
|
43
44
|
row,
|
|
44
|
-
event.target.checked
|
|
45
|
+
selectedRows: event.target.checked
|
|
45
46
|
? [...getSelectedRowModel().flatRows, row]
|
|
46
47
|
: getSelectedRowModel().flatRows.filter(
|
|
47
48
|
(selectedRow) => selectedRow.id !== row.id,
|
|
48
49
|
),
|
|
49
|
-
|
|
50
|
+
tableInstance,
|
|
51
|
+
});
|
|
50
52
|
}
|
|
51
53
|
};
|
|
52
54
|
|
|
53
55
|
const mTableBodyRowSelectCheckboxProps =
|
|
54
56
|
muiSelectCheckboxProps instanceof Function
|
|
55
|
-
? muiSelectCheckboxProps(selectAll, row, tableInstance)
|
|
57
|
+
? muiSelectCheckboxProps({ isSelectAll: !!selectAll, row, tableInstance })
|
|
56
58
|
: muiSelectCheckboxProps;
|
|
57
59
|
|
|
58
60
|
const rtSelectCheckboxProps = selectAll
|
package/src/localization.ts
CHANGED
|
@@ -33,6 +33,7 @@ export interface MRT_Localization {
|
|
|
33
33
|
pinToLeft: string;
|
|
34
34
|
pinToRight: string;
|
|
35
35
|
rowActions: string;
|
|
36
|
+
rowNumber: string;
|
|
36
37
|
rowNumbers: string;
|
|
37
38
|
save: string;
|
|
38
39
|
search: string;
|
|
@@ -89,12 +90,12 @@ export const MRT_DefaultLocalization_EN: MRT_Localization = {
|
|
|
89
90
|
pinToLeft: 'Pin to left',
|
|
90
91
|
pinToRight: 'Pin to right',
|
|
91
92
|
rowActions: 'Row Actions',
|
|
93
|
+
rowNumber: '#',
|
|
92
94
|
rowNumbers: 'Row Numbers',
|
|
93
95
|
save: 'Save',
|
|
94
96
|
search: 'Search',
|
|
95
97
|
selectedCountOfRowCountRowsSelected:
|
|
96
98
|
'{selectedCount} of {rowCount} row(s) selected',
|
|
97
|
-
|
|
98
99
|
select: 'Select',
|
|
99
100
|
showAll: 'Show all',
|
|
100
101
|
showAllColumns: 'Show all columns',
|
|
@@ -25,7 +25,7 @@ export const MRT_RowActionMenu: FC<Props> = ({
|
|
|
25
25
|
getState,
|
|
26
26
|
options: {
|
|
27
27
|
icons: { EditIcon },
|
|
28
|
-
|
|
28
|
+
enableEditing,
|
|
29
29
|
localization,
|
|
30
30
|
renderRowActionMenuItems,
|
|
31
31
|
},
|
|
@@ -42,7 +42,7 @@ export const MRT_RowActionMenu: FC<Props> = ({
|
|
|
42
42
|
dense: isDensePadding,
|
|
43
43
|
}}
|
|
44
44
|
>
|
|
45
|
-
{
|
|
45
|
+
{enableEditing && (
|
|
46
46
|
<MenuItem onClick={handleEdit} sx={commonMenuItemStyles}>
|
|
47
47
|
<Box sx={commonListItemStyles}>
|
|
48
48
|
<ListItemIcon>
|
|
@@ -52,9 +52,11 @@ export const MRT_RowActionMenu: FC<Props> = ({
|
|
|
52
52
|
</Box>
|
|
53
53
|
</MenuItem>
|
|
54
54
|
)}
|
|
55
|
-
{renderRowActionMenuItems?.(
|
|
56
|
-
|
|
57
|
-
|
|
55
|
+
{renderRowActionMenuItems?.({
|
|
56
|
+
row,
|
|
57
|
+
tableInstance,
|
|
58
|
+
closeMenu: () => setAnchorEl(null),
|
|
59
|
+
})}
|
|
58
60
|
</Menu>
|
|
59
61
|
);
|
|
60
62
|
};
|
|
@@ -34,12 +34,11 @@ export const MRT_ShowHideColumnsMenuItems: FC<Props> = ({
|
|
|
34
34
|
} else {
|
|
35
35
|
column.toggleVisibility();
|
|
36
36
|
}
|
|
37
|
-
onColumnHide?.(
|
|
37
|
+
onColumnHide?.({
|
|
38
38
|
column,
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
);
|
|
39
|
+
columnVisibility,
|
|
40
|
+
tableInstance,
|
|
41
|
+
});
|
|
43
42
|
};
|
|
44
43
|
|
|
45
44
|
return (
|
package/src/table/MRT_Table.tsx
CHANGED