mui-table-2026 1.0.0
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/LICENSE +21 -0
- package/README.md +82 -0
- package/package.json +115 -0
- package/src/MUIDataTable.js +2107 -0
- package/src/components/ExpandButton.js +39 -0
- package/src/components/JumpToPage.js +96 -0
- package/src/components/Popover.js +89 -0
- package/src/components/TableBody.js +338 -0
- package/src/components/TableBodyCell.js +276 -0
- package/src/components/TableBodyRow.js +98 -0
- package/src/components/TableFilter.js +421 -0
- package/src/components/TableFilterList.js +136 -0
- package/src/components/TableFilterListItem.js +20 -0
- package/src/components/TableFooter.js +74 -0
- package/src/components/TableHead.js +171 -0
- package/src/components/TableHeadCell.js +320 -0
- package/src/components/TableHeadRow.js +29 -0
- package/src/components/TablePagination.js +152 -0
- package/src/components/TableResize.js +288 -0
- package/src/components/TableSearch.js +89 -0
- package/src/components/TableSelectCell.js +163 -0
- package/src/components/TableToolbar.js +630 -0
- package/src/components/TableToolbarSelect.js +91 -0
- package/src/components/TableViewCol.js +101 -0
- package/src/hooks/useColumnDrop.js +186 -0
- package/src/index.js +44 -0
- package/src/localStorage/index.js +2 -0
- package/src/localStorage/load.js +10 -0
- package/src/localStorage/save.js +5 -0
- package/src/plug-ins/DebounceSearchRender.js +118 -0
- package/src/textLabels.js +39 -0
- package/src/utils.js +150 -0
|
@@ -0,0 +1,276 @@
|
|
|
1
|
+
import React, { useCallback } from 'react';
|
|
2
|
+
import clsx from 'clsx';
|
|
3
|
+
import { TableCell } from '@mui/material';
|
|
4
|
+
import { makeStyles } from 'tss-react/mui';
|
|
5
|
+
|
|
6
|
+
const useStyles = makeStyles({ name: 'MUIDataTableBodyCell' })((theme) => ({
|
|
7
|
+
root: {
|
|
8
|
+
// Modern cell styling
|
|
9
|
+
display: 'table-cell',
|
|
10
|
+
textAlign: 'center',
|
|
11
|
+
verticalAlign: 'middle',
|
|
12
|
+
border: 'none',
|
|
13
|
+
padding: 0,
|
|
14
|
+
height: '28px',
|
|
15
|
+
minHeight: '28px',
|
|
16
|
+
maxHeight: '28px',
|
|
17
|
+
overflow: 'hidden',
|
|
18
|
+
textOverflow: 'ellipsis',
|
|
19
|
+
whiteSpace: 'nowrap',
|
|
20
|
+
fontSize: theme.typography.body2.fontSize || '14px',
|
|
21
|
+
fontFamily: theme.typography.fontFamily || 'Inter, system-ui, sans-serif',
|
|
22
|
+
color: theme.palette.text.primary || '#374151',
|
|
23
|
+
'& > div': {
|
|
24
|
+
display: 'flex',
|
|
25
|
+
alignItems: 'center',
|
|
26
|
+
justifyContent: 'center',
|
|
27
|
+
width: '100%',
|
|
28
|
+
height: '100%',
|
|
29
|
+
},
|
|
30
|
+
// Action button styling
|
|
31
|
+
'& .MuiIconButton-root': {
|
|
32
|
+
borderRadius: '6px',
|
|
33
|
+
transition: 'background-color 0.2s ease',
|
|
34
|
+
'&:hover': {
|
|
35
|
+
backgroundColor: '#f1f5f9',
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
cellHide: {
|
|
40
|
+
display: 'none',
|
|
41
|
+
},
|
|
42
|
+
simpleHeader: {
|
|
43
|
+
[theme.breakpoints.down('sm')]: {
|
|
44
|
+
display: 'inline-block',
|
|
45
|
+
fontWeight: 'bold',
|
|
46
|
+
width: '100%',
|
|
47
|
+
boxSizing: 'border-box',
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
simpleCell: {
|
|
51
|
+
[theme.breakpoints.down('sm')]: {
|
|
52
|
+
display: 'inline-block',
|
|
53
|
+
width: '100%',
|
|
54
|
+
boxSizing: 'border-box',
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
stackedHeader: {
|
|
58
|
+
verticalAlign: 'top',
|
|
59
|
+
},
|
|
60
|
+
stackedCommon: {
|
|
61
|
+
[theme.breakpoints.down('md')]: {
|
|
62
|
+
display: 'table-cell',
|
|
63
|
+
fontSize: theme.typography.body2.fontSize || '14px',
|
|
64
|
+
height: '28px',
|
|
65
|
+
minHeight: '28px',
|
|
66
|
+
maxHeight: '28px',
|
|
67
|
+
width: 'auto',
|
|
68
|
+
boxSizing: 'border-box',
|
|
69
|
+
textAlign: 'center',
|
|
70
|
+
verticalAlign: 'middle',
|
|
71
|
+
border: 'none',
|
|
72
|
+
padding: 0,
|
|
73
|
+
overflow: 'hidden',
|
|
74
|
+
textOverflow: 'ellipsis',
|
|
75
|
+
whiteSpace: 'nowrap',
|
|
76
|
+
fontFamily: theme.typography.fontFamily || 'Inter, system-ui, sans-serif',
|
|
77
|
+
color: theme.palette.text.primary || '#374151',
|
|
78
|
+
'&:last-child': {
|
|
79
|
+
borderBottom: 'none',
|
|
80
|
+
},
|
|
81
|
+
'&:nth-last-of-type(2)': {
|
|
82
|
+
borderBottom: 'none',
|
|
83
|
+
},
|
|
84
|
+
},
|
|
85
|
+
},
|
|
86
|
+
stackedCommonAlways: {
|
|
87
|
+
display: 'inline-block',
|
|
88
|
+
fontSize: '16px',
|
|
89
|
+
height: 'auto',
|
|
90
|
+
width: 'calc(50%)',
|
|
91
|
+
boxSizing: 'border-box',
|
|
92
|
+
'&:last-child': {
|
|
93
|
+
borderBottom: 'none',
|
|
94
|
+
},
|
|
95
|
+
'&:nth-last-of-type(2)': {
|
|
96
|
+
borderBottom: 'none',
|
|
97
|
+
},
|
|
98
|
+
},
|
|
99
|
+
stackedParent: {
|
|
100
|
+
[theme.breakpoints.down('md')]: {
|
|
101
|
+
display: 'table-cell',
|
|
102
|
+
fontSize: theme.typography.body2.fontSize || '14px',
|
|
103
|
+
height: '28px',
|
|
104
|
+
minHeight: '28px',
|
|
105
|
+
maxHeight: '28px',
|
|
106
|
+
width: 'auto',
|
|
107
|
+
boxSizing: 'border-box',
|
|
108
|
+
textAlign: 'center',
|
|
109
|
+
verticalAlign: 'middle',
|
|
110
|
+
border: 'none',
|
|
111
|
+
padding: 0,
|
|
112
|
+
overflow: 'hidden',
|
|
113
|
+
textOverflow: 'ellipsis',
|
|
114
|
+
whiteSpace: 'nowrap',
|
|
115
|
+
fontFamily: theme.typography.fontFamily || 'Inter, system-ui, sans-serif',
|
|
116
|
+
color: theme.palette.text.primary || '#374151',
|
|
117
|
+
},
|
|
118
|
+
},
|
|
119
|
+
stackedParentAlways: {
|
|
120
|
+
display: 'table-cell',
|
|
121
|
+
fontSize: theme.typography.body2.fontSize || '14px',
|
|
122
|
+
height: '32px',
|
|
123
|
+
minHeight: '32px',
|
|
124
|
+
maxHeight: '32px',
|
|
125
|
+
width: 'auto',
|
|
126
|
+
boxSizing: 'border-box',
|
|
127
|
+
textAlign: 'center',
|
|
128
|
+
verticalAlign: 'middle',
|
|
129
|
+
border: 'none',
|
|
130
|
+
padding: 0,
|
|
131
|
+
overflow: 'hidden',
|
|
132
|
+
textOverflow: 'ellipsis',
|
|
133
|
+
whiteSpace: 'nowrap',
|
|
134
|
+
fontFamily: theme.typography.fontFamily || 'Inter, system-ui, sans-serif',
|
|
135
|
+
color: theme.palette.text.primary || '#374151',
|
|
136
|
+
},
|
|
137
|
+
cellStackedSmall: {
|
|
138
|
+
[theme.breakpoints.down('md')]: {
|
|
139
|
+
width: '50%',
|
|
140
|
+
boxSizing: 'border-box',
|
|
141
|
+
},
|
|
142
|
+
},
|
|
143
|
+
responsiveStackedSmall: {
|
|
144
|
+
[theme.breakpoints.down('md')]: {
|
|
145
|
+
width: '50%',
|
|
146
|
+
boxSizing: 'border-box',
|
|
147
|
+
},
|
|
148
|
+
},
|
|
149
|
+
responsiveStackedSmallParent: {
|
|
150
|
+
[theme.breakpoints.down('md')]: {
|
|
151
|
+
display: 'table-cell',
|
|
152
|
+
fontSize: theme.typography.body2.fontSize || '14px',
|
|
153
|
+
height: '28px',
|
|
154
|
+
minHeight: '28px',
|
|
155
|
+
maxHeight: '28px',
|
|
156
|
+
width: 'auto',
|
|
157
|
+
boxSizing: 'border-box',
|
|
158
|
+
textAlign: 'center',
|
|
159
|
+
verticalAlign: 'middle',
|
|
160
|
+
border: 'none',
|
|
161
|
+
padding: 0,
|
|
162
|
+
overflow: 'hidden',
|
|
163
|
+
textOverflow: 'ellipsis',
|
|
164
|
+
whiteSpace: 'nowrap',
|
|
165
|
+
fontFamily: theme.typography.fontFamily || 'Inter, system-ui, sans-serif',
|
|
166
|
+
color: theme.palette.text.primary || '#374151',
|
|
167
|
+
},
|
|
168
|
+
},
|
|
169
|
+
}));
|
|
170
|
+
|
|
171
|
+
function TableBodyCell(props) {
|
|
172
|
+
const { classes } = useStyles();
|
|
173
|
+
const { children, colIndex, columnHeader, options, dataIndex, rowIndex, className, print, tableId, ...otherProps } =
|
|
174
|
+
props;
|
|
175
|
+
const onCellClick = options.onCellClick;
|
|
176
|
+
|
|
177
|
+
const handleClick = useCallback(
|
|
178
|
+
(event) => {
|
|
179
|
+
onCellClick(children, { colIndex, rowIndex, dataIndex, event });
|
|
180
|
+
},
|
|
181
|
+
[onCellClick, children, colIndex, rowIndex, dataIndex],
|
|
182
|
+
);
|
|
183
|
+
|
|
184
|
+
// Event listeners. Avoid attaching them if they're not necessary.
|
|
185
|
+
let methods = {};
|
|
186
|
+
if (onCellClick) {
|
|
187
|
+
methods.onClick = handleClick;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
let cells = [
|
|
191
|
+
<div
|
|
192
|
+
key={1}
|
|
193
|
+
className={clsx(
|
|
194
|
+
{
|
|
195
|
+
lastColumn: colIndex === 2,
|
|
196
|
+
[classes.root]: true,
|
|
197
|
+
[classes.cellHide]: true,
|
|
198
|
+
[classes.stackedHeader]: true,
|
|
199
|
+
[classes.stackedCommon]:
|
|
200
|
+
options.responsive === 'vertical' ||
|
|
201
|
+
options.responsive === 'stacked' ||
|
|
202
|
+
options.responsive === 'stackedFullWidth',
|
|
203
|
+
[classes.stackedCommonAlways]: options.responsive === 'verticalAlways',
|
|
204
|
+
[classes.cellStackedSmall]:
|
|
205
|
+
options.responsive === 'stacked' ||
|
|
206
|
+
(options.responsive === 'stackedFullWidth' &&
|
|
207
|
+
(options.setTableProps().padding === 'none' || options.setTableProps().size === 'small')),
|
|
208
|
+
[classes.simpleHeader]: options.responsive === 'simple',
|
|
209
|
+
'datatables-noprint': !print,
|
|
210
|
+
},
|
|
211
|
+
className,
|
|
212
|
+
)}>
|
|
213
|
+
{columnHeader}
|
|
214
|
+
</div>,
|
|
215
|
+
<div
|
|
216
|
+
key={2}
|
|
217
|
+
className={clsx(
|
|
218
|
+
{
|
|
219
|
+
[classes.root]: true,
|
|
220
|
+
[classes.stackedCommon]:
|
|
221
|
+
options.responsive === 'vertical' ||
|
|
222
|
+
options.responsive === 'stacked' ||
|
|
223
|
+
options.responsive === 'stackedFullWidth',
|
|
224
|
+
[classes.stackedCommonAlways]: options.responsive === 'verticalAlways',
|
|
225
|
+
[classes.responsiveStackedSmall]:
|
|
226
|
+
options.responsive === 'stacked' ||
|
|
227
|
+
(options.responsive === 'stackedFullWidth' &&
|
|
228
|
+
(options.setTableProps().padding === 'none' || options.setTableProps().size === 'small')),
|
|
229
|
+
[classes.simpleCell]: options.responsive === 'simple',
|
|
230
|
+
'datatables-noprint': !print,
|
|
231
|
+
},
|
|
232
|
+
className,
|
|
233
|
+
)}>
|
|
234
|
+
{typeof children === 'function' ? children(dataIndex, rowIndex) : children}
|
|
235
|
+
</div>,
|
|
236
|
+
];
|
|
237
|
+
|
|
238
|
+
var innerCells;
|
|
239
|
+
if (
|
|
240
|
+
['standard', 'scrollMaxHeight', 'scrollFullHeight', 'scrollFullHeightFullWidth'].indexOf(options.responsive) !== -1
|
|
241
|
+
) {
|
|
242
|
+
innerCells = cells.slice(1, 2);
|
|
243
|
+
} else {
|
|
244
|
+
innerCells = cells;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
return (
|
|
248
|
+
<TableCell
|
|
249
|
+
{...methods}
|
|
250
|
+
data-colindex={colIndex}
|
|
251
|
+
data-tableid={tableId}
|
|
252
|
+
className={clsx(
|
|
253
|
+
{
|
|
254
|
+
[classes.root]: true,
|
|
255
|
+
[classes.stackedParent]:
|
|
256
|
+
options.responsive === 'vertical' ||
|
|
257
|
+
options.responsive === 'stacked' ||
|
|
258
|
+
options.responsive === 'stackedFullWidth',
|
|
259
|
+
[classes.stackedParentAlways]: options.responsive === 'verticalAlways',
|
|
260
|
+
[classes.responsiveStackedSmallParent]:
|
|
261
|
+
options.responsive === 'vertical' ||
|
|
262
|
+
options.responsive === 'stacked' ||
|
|
263
|
+
(options.responsive === 'stackedFullWidth' &&
|
|
264
|
+
(options.setTableProps().padding === 'none' || options.setTableProps().size === 'small')),
|
|
265
|
+
[classes.simpleCell]: options.responsive === 'simple',
|
|
266
|
+
'datatables-noprint': !print,
|
|
267
|
+
},
|
|
268
|
+
className,
|
|
269
|
+
)}
|
|
270
|
+
{...otherProps}>
|
|
271
|
+
{innerCells}
|
|
272
|
+
</TableCell>
|
|
273
|
+
);
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
export default TableBodyCell;
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
import clsx from 'clsx';
|
|
4
|
+
import { TableRow } from '@mui/material';
|
|
5
|
+
import { withStyles } from 'tss-react/mui';
|
|
6
|
+
|
|
7
|
+
const defaultBodyRowStyles = (theme) => ({
|
|
8
|
+
root: {
|
|
9
|
+
// material v4
|
|
10
|
+
'&.Mui-selected': {
|
|
11
|
+
backgroundColor: theme.palette.action.selected,
|
|
12
|
+
},
|
|
13
|
+
|
|
14
|
+
// material v3 workaround
|
|
15
|
+
'&.mui-row-selected': {
|
|
16
|
+
backgroundColor: theme.palette.action.selected,
|
|
17
|
+
},
|
|
18
|
+
|
|
19
|
+
// Modern row styling with alternating colors
|
|
20
|
+
height: '32px',
|
|
21
|
+
minHeight: '32px',
|
|
22
|
+
maxHeight: '32px',
|
|
23
|
+
'&:nth-of-type(odd)': {
|
|
24
|
+
backgroundColor: '#f8fafc',
|
|
25
|
+
},
|
|
26
|
+
'&:nth-of-type(even)': {
|
|
27
|
+
backgroundColor: '#ffffff',
|
|
28
|
+
},
|
|
29
|
+
'&:hover': {
|
|
30
|
+
backgroundColor: '#E0E3E7 !important',
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
hoverCursor: { cursor: 'pointer' },
|
|
34
|
+
responsiveStacked: {
|
|
35
|
+
[theme.breakpoints.down('md')]: {
|
|
36
|
+
borderTop: 'solid 2px rgba(0, 0, 0, 0.15)',
|
|
37
|
+
borderBottom: 'solid 2px rgba(0, 0, 0, 0.15)',
|
|
38
|
+
padding: 0,
|
|
39
|
+
margin: 0,
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
responsiveSimple: {
|
|
43
|
+
[theme.breakpoints.down('sm')]: {
|
|
44
|
+
borderTop: 'solid 2px rgba(0, 0, 0, 0.15)',
|
|
45
|
+
borderBottom: 'solid 2px rgba(0, 0, 0, 0.15)',
|
|
46
|
+
padding: 0,
|
|
47
|
+
margin: 0,
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
class TableBodyRow extends React.Component {
|
|
53
|
+
static propTypes = {
|
|
54
|
+
/** Options used to describe table */
|
|
55
|
+
options: PropTypes.object.isRequired,
|
|
56
|
+
/** Callback to execute when row is clicked */
|
|
57
|
+
onClick: PropTypes.func,
|
|
58
|
+
/** Current row selected or not */
|
|
59
|
+
rowSelected: PropTypes.bool,
|
|
60
|
+
/** Extend the style applied to components */
|
|
61
|
+
classes: PropTypes.object,
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
render() {
|
|
65
|
+
const { classes, options, rowSelected, onClick, className, isRowSelectable, ...rest } = this.props;
|
|
66
|
+
|
|
67
|
+
var methods = {};
|
|
68
|
+
if (onClick) {
|
|
69
|
+
methods.onClick = onClick;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
return (
|
|
73
|
+
<TableRow
|
|
74
|
+
hover={options.rowHover ? true : false}
|
|
75
|
+
{...methods}
|
|
76
|
+
className={clsx(
|
|
77
|
+
{
|
|
78
|
+
[classes.root]: true,
|
|
79
|
+
[classes.hover]: options.rowHover,
|
|
80
|
+
[classes.hoverCursor]: (options.selectableRowsOnClick && isRowSelectable) || options.expandableRowsOnClick,
|
|
81
|
+
[classes.responsiveSimple]: options.responsive === 'simple',
|
|
82
|
+
[classes.responsiveStacked]:
|
|
83
|
+
options.responsive === 'vertical' ||
|
|
84
|
+
options.responsive === 'stacked' ||
|
|
85
|
+
options.responsive === 'stackedFullWidth',
|
|
86
|
+
'mui-row-selected': rowSelected,
|
|
87
|
+
},
|
|
88
|
+
className,
|
|
89
|
+
)}
|
|
90
|
+
selected={rowSelected}
|
|
91
|
+
{...rest}>
|
|
92
|
+
{this.props.children}
|
|
93
|
+
</TableRow>
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export default withStyles(TableBodyRow, defaultBodyRowStyles, { name: 'MUIDataTableBodyRow' });
|