material-react-table 3.1.0 → 3.2.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/dist/index.d.ts +1 -0
- package/dist/index.esm.js +38 -13
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +38 -13
- package/dist/index.js.map +1 -1
- package/locales/ar/index.esm.js +1 -0
- package/locales/ar/index.js +1 -0
- package/locales/az/index.esm.js +1 -0
- package/locales/az/index.js +1 -0
- package/locales/bg/index.esm.js +1 -0
- package/locales/bg/index.js +1 -0
- package/locales/cs/index.esm.js +1 -0
- package/locales/cs/index.js +1 -0
- package/locales/da/index.esm.js +1 -0
- package/locales/da/index.js +1 -0
- package/locales/de/index.esm.js +1 -0
- package/locales/de/index.js +1 -0
- package/locales/el/index.esm.js +1 -0
- package/locales/el/index.js +1 -0
- package/locales/en/index.esm.js +1 -0
- package/locales/en/index.js +1 -0
- package/locales/es/index.esm.js +1 -0
- package/locales/es/index.js +1 -0
- package/locales/et/index.esm.js +1 -0
- package/locales/et/index.js +1 -0
- package/locales/fa/index.esm.js +1 -0
- package/locales/fa/index.js +1 -0
- package/locales/fi/index.esm.js +1 -0
- package/locales/fi/index.js +1 -0
- package/locales/fr/index.esm.js +1 -0
- package/locales/fr/index.js +1 -0
- package/locales/he/index.esm.js +1 -0
- package/locales/he/index.js +1 -0
- package/locales/hr/index.esm.js +1 -0
- package/locales/hr/index.js +1 -0
- package/locales/hu/index.esm.js +1 -0
- package/locales/hu/index.js +1 -0
- package/locales/hy/index.esm.js +1 -0
- package/locales/hy/index.js +1 -0
- package/locales/id/index.esm.js +1 -0
- package/locales/id/index.js +1 -0
- package/locales/it/index.esm.js +1 -0
- package/locales/it/index.js +1 -0
- package/locales/ja/index.esm.js +1 -0
- package/locales/ja/index.js +1 -0
- package/locales/ko/index.esm.js +1 -0
- package/locales/ko/index.js +1 -0
- package/locales/nl/index.esm.js +1 -0
- package/locales/nl/index.js +1 -0
- package/locales/no/index.esm.js +1 -0
- package/locales/no/index.js +1 -0
- package/locales/np/index.esm.js +1 -0
- package/locales/np/index.js +1 -0
- package/locales/pl/index.esm.js +1 -0
- package/locales/pl/index.js +1 -0
- package/locales/pt/index.esm.js +1 -0
- package/locales/pt/index.js +1 -0
- package/locales/pt-BR/index.esm.js +1 -0
- package/locales/pt-BR/index.js +1 -0
- package/locales/ro/index.esm.js +1 -0
- package/locales/ro/index.js +1 -0
- package/locales/ru/index.esm.js +1 -0
- package/locales/ru/index.js +1 -0
- package/locales/sk/index.esm.js +1 -0
- package/locales/sk/index.js +1 -0
- package/locales/sr-Cyrl-RS/index.esm.js +1 -0
- package/locales/sr-Cyrl-RS/index.js +1 -0
- package/locales/sr-Latn-RS/index.esm.js +1 -0
- package/locales/sr-Latn-RS/index.js +1 -0
- package/locales/sv/index.esm.js +1 -0
- package/locales/sv/index.js +1 -0
- package/locales/tr/index.esm.js +1 -0
- package/locales/tr/index.js +1 -0
- package/locales/uk/index.esm.js +1 -0
- package/locales/uk/index.js +1 -0
- package/locales/vi/index.esm.js +1 -0
- package/locales/vi/index.js +1 -0
- package/locales/zh-Hans/index.esm.js +1 -0
- package/locales/zh-Hans/index.js +1 -0
- package/locales/zh-Hant/index.esm.js +1 -0
- package/locales/zh-Hant/index.js +1 -0
- package/package.json +1 -1
- package/src/components/inputs/MRT_FilterTextField.tsx +18 -4
- package/src/components/toolbar/MRT_TablePagination.tsx +5 -3
- package/src/components/toolbar/MRT_ToolbarAlertBanner.tsx +2 -2
- package/src/hooks/useMRT_Effects.ts +1 -1
- package/src/hooks/useMRT_RowVirtualizer.ts +16 -4
- package/src/locales/ar.ts +1 -0
- package/src/locales/az.ts +1 -0
- package/src/locales/bg.ts +1 -0
- package/src/locales/cs.ts +1 -0
- package/src/locales/da.ts +1 -0
- package/src/locales/de.ts +1 -0
- package/src/locales/el.ts +1 -0
- package/src/locales/en.ts +1 -0
- package/src/locales/es.ts +1 -0
- package/src/locales/et.ts +1 -0
- package/src/locales/fa.ts +1 -0
- package/src/locales/fi.ts +1 -0
- package/src/locales/fr.ts +1 -0
- package/src/locales/he.ts +1 -0
- package/src/locales/hr.ts +1 -0
- package/src/locales/hu.ts +1 -0
- package/src/locales/hy.ts +1 -0
- package/src/locales/id.ts +1 -0
- package/src/locales/it.ts +1 -0
- package/src/locales/ja.ts +1 -0
- package/src/locales/ko.ts +1 -0
- package/src/locales/nl.ts +1 -0
- package/src/locales/no.ts +1 -0
- package/src/locales/np.ts +1 -0
- package/src/locales/pl.ts +1 -0
- package/src/locales/pt-BR.ts +1 -0
- package/src/locales/pt.ts +1 -0
- package/src/locales/ro.ts +1 -0
- package/src/locales/ru.ts +1 -0
- package/src/locales/sk.ts +1 -0
- package/src/locales/sr-Cyrl-RS.ts +1 -0
- package/src/locales/sr-Latn-RS.ts +1 -0
- package/src/locales/sv.ts +1 -0
- package/src/locales/tr.ts +1 -0
- package/src/locales/uk.ts +1 -0
- package/src/locales/vi.ts +1 -0
- package/src/locales/zh-Hans.ts +1 -0
- package/src/locales/zh-Hant.ts +1 -0
- package/src/types.ts +2 -0
- package/src/utils/virtualization.utils.ts +5 -0
package/dist/index.d.ts
CHANGED
package/dist/index.esm.js
CHANGED
@@ -1298,6 +1298,7 @@ const MRT_Default_Icons = {
|
|
1298
1298
|
};
|
1299
1299
|
|
1300
1300
|
const MRT_Localization_EN = {
|
1301
|
+
language: 'en',
|
1301
1302
|
actions: 'Actions',
|
1302
1303
|
and: 'and',
|
1303
1304
|
cancel: 'Cancel',
|
@@ -1583,7 +1584,7 @@ const useMRT_Effects = (table) => {
|
|
1583
1584
|
if (firstVisibleRowIndex >= totalRowCount) {
|
1584
1585
|
table.setPageIndex(Math.ceil(totalRowCount / pageSize) - 1);
|
1585
1586
|
}
|
1586
|
-
}, [totalRowCount]);
|
1587
|
+
}, [totalRowCount, enablePagination, isLoading, showSkeletons]);
|
1587
1588
|
//turn off sort when global filter is looking for ranked results
|
1588
1589
|
const appliedSort = useRef(sorting);
|
1589
1590
|
useEffect(() => {
|
@@ -1797,6 +1798,11 @@ const useMRT_TableInstance = (definedTableOptions) => {
|
|
1797
1798
|
|
1798
1799
|
const useMaterialReactTable = (tableOptions) => useMRT_TableInstance(useMRT_TableOptions(tableOptions));
|
1799
1800
|
|
1801
|
+
/**
|
1802
|
+
* When scroll, the `draggingRow` or `draggingColumn` can be removed from document because of virtualization,
|
1803
|
+
* then, the `dragEnd` event on `MRT_TableBodyRowGrabHandle` or `MRT_TableHeadCellGrabHandle` will not fire.
|
1804
|
+
* We should keep the `draggingRow` or `draggingColumn` in `getVirtualItems()` to avoid this thing.
|
1805
|
+
*/
|
1800
1806
|
const extraIndexRangeExtractor = (range, draggingIndex) => {
|
1801
1807
|
const newIndexes = defaultRangeExtractor(range);
|
1802
1808
|
if (draggingIndex === undefined)
|
@@ -1872,7 +1878,6 @@ const useMRT_ColumnVirtualizer = (table) => {
|
|
1872
1878
|
};
|
1873
1879
|
|
1874
1880
|
const useMRT_RowVirtualizer = (table, rows) => {
|
1875
|
-
var _a;
|
1876
1881
|
const { getRowModel, getState, options: { enableRowVirtualization, renderDetailPanel, rowVirtualizerInstanceRef, rowVirtualizerOptions, }, refs: { tableContainerRef }, } = table;
|
1877
1882
|
const { density, draggingRow, expanded } = getState();
|
1878
1883
|
if (!enableRowVirtualization)
|
@@ -1880,7 +1885,14 @@ const useMRT_RowVirtualizer = (table, rows) => {
|
|
1880
1885
|
const rowVirtualizerProps = parseFromValuesOrFunc(rowVirtualizerOptions, {
|
1881
1886
|
table,
|
1882
1887
|
});
|
1883
|
-
const
|
1888
|
+
const realRows = rows !== null && rows !== void 0 ? rows : getRowModel().rows;
|
1889
|
+
/**
|
1890
|
+
* when filtering, should find the correct index in filtered rows
|
1891
|
+
*/
|
1892
|
+
const draggingRowIndex = useMemo(() => (draggingRow === null || draggingRow === void 0 ? void 0 : draggingRow.id)
|
1893
|
+
? realRows.findIndex((r) => r.id === (draggingRow === null || draggingRow === void 0 ? void 0 : draggingRow.id))
|
1894
|
+
: undefined, [realRows, draggingRow === null || draggingRow === void 0 ? void 0 : draggingRow.id]);
|
1895
|
+
const rowCount = realRows.length;
|
1884
1896
|
const normalRowHeight = density === 'compact' ? 37 : density === 'comfortable' ? 58 : 73;
|
1885
1897
|
const rowVirtualizer = useVirtualizer(Object.assign({ count: renderDetailPanel ? rowCount * 2 : rowCount, estimateSize: (index) => renderDetailPanel && index % 2 === 1
|
1886
1898
|
? expanded === true
|
@@ -1890,9 +1902,8 @@ const useMRT_RowVirtualizer = (table, rows) => {
|
|
1890
1902
|
navigator.userAgent.indexOf('Firefox') === -1
|
1891
1903
|
? (element) => element === null || element === void 0 ? void 0 : element.getBoundingClientRect().height
|
1892
1904
|
: undefined, overscan: 4, rangeExtractor: useCallback((range) => {
|
1893
|
-
|
1894
|
-
|
1895
|
-
}, [draggingRow]) }, rowVirtualizerProps));
|
1905
|
+
return extraIndexRangeExtractor(range, draggingRowIndex);
|
1906
|
+
}, [draggingRowIndex]) }, rowVirtualizerProps));
|
1896
1907
|
rowVirtualizer.virtualRows = rowVirtualizer.getVirtualItems();
|
1897
1908
|
if (rowVirtualizerInstanceRef) {
|
1898
1909
|
//@ts-expect-error
|
@@ -3040,9 +3051,11 @@ const MRT_FilterTextField = (_a) => {
|
|
3040
3051
|
? column.getFilterValue() || []
|
3041
3052
|
: isRangeFilter
|
3042
3053
|
? ((_a = column.getFilterValue()) === null || _a === void 0 ? void 0 : _a[rangeFilterIndex]) || ''
|
3043
|
-
:
|
3054
|
+
: isAutocompleteFilter
|
3055
|
+
? typeof column.getFilterValue() === 'string' ? column.getFilterValue() : ''
|
3056
|
+
: ((_b = column.getFilterValue()) !== null && _b !== void 0 ? _b : '');
|
3044
3057
|
});
|
3045
|
-
const [autocompleteValue, setAutocompleteValue] = useState(isAutocompleteFilter ?
|
3058
|
+
const [autocompleteValue, setAutocompleteValue] = useState(() => isAutocompleteFilter ? (column.getFilterValue() || null) : null);
|
3046
3059
|
const handleChangeDebounced = useCallback(debounce((newValue) => {
|
3047
3060
|
if (isRangeFilter) {
|
3048
3061
|
column.setFilterValue((old) => {
|
@@ -3069,9 +3082,12 @@ const MRT_FilterTextField = (_a) => {
|
|
3069
3082
|
handleChange(newValue);
|
3070
3083
|
(_a = textFieldProps === null || textFieldProps === void 0 ? void 0 : textFieldProps.onChange) === null || _a === void 0 ? void 0 : _a.call(textFieldProps, event);
|
3071
3084
|
};
|
3085
|
+
const handleAutocompleteInputChange = (_event, newValue, _reason) => {
|
3086
|
+
handleChange(newValue);
|
3087
|
+
};
|
3072
3088
|
const handleAutocompleteChange = (newValue) => {
|
3073
3089
|
setAutocompleteValue(newValue);
|
3074
|
-
|
3090
|
+
handleChangeDebounced(getValueAndLabel(newValue).value);
|
3075
3091
|
};
|
3076
3092
|
const handleClear = () => {
|
3077
3093
|
if (isMultiSelectFilter) {
|
@@ -3086,6 +3102,13 @@ const MRT_FilterTextField = (_a) => {
|
|
3086
3102
|
return newFilterValues;
|
3087
3103
|
});
|
3088
3104
|
}
|
3105
|
+
else if (isAutocompleteFilter) {
|
3106
|
+
setAutocompleteValue(null);
|
3107
|
+
setFilterValue('');
|
3108
|
+
// when using 'autocomplete' this function is called only inside effect and only if the filterValue === undefined
|
3109
|
+
// so the following call is excessive; should be uncommented if the handleClear becomes part of the Autocomplete component callbacks
|
3110
|
+
// column.setFilterValue(undefined)
|
3111
|
+
}
|
3089
3112
|
else {
|
3090
3113
|
setFilterValue('');
|
3091
3114
|
column.setFilterValue(undefined);
|
@@ -3176,11 +3199,11 @@ const MRT_FilterTextField = (_a) => {
|
|
3176
3199
|
} }))) : (filterVariant === null || filterVariant === void 0 ? void 0 : filterVariant.startsWith('date')) ? (jsx(DatePicker, Object.assign({}, commonDatePickerProps, datePickerProps, { slotProps: {
|
3177
3200
|
field: Object.assign({ clearable: true, onClear: () => handleClear() }, (_t = datePickerProps === null || datePickerProps === void 0 ? void 0 : datePickerProps.slotProps) === null || _t === void 0 ? void 0 : _t.field),
|
3178
3201
|
textField: Object.assign(Object.assign({}, commonTextFieldProps), (_u = datePickerProps === null || datePickerProps === void 0 ? void 0 : datePickerProps.slotProps) === null || _u === void 0 ? void 0 : _u.textField),
|
3179
|
-
} }))) : isAutocompleteFilter ? (jsx(Autocomplete, Object.assign({ freeSolo: true, getOptionLabel: (option) => getValueAndLabel(option).label, onChange: (_e, newValue) => handleAutocompleteChange(newValue), options: (_v = dropdownOptions === null || dropdownOptions === void 0 ? void 0 : dropdownOptions.map((option) => getValueAndLabel(option))) !== null && _v !== void 0 ? _v : [] }, autocompleteProps, { renderInput: (builtinTextFieldProps) => {
|
3202
|
+
} }))) : isAutocompleteFilter ? (jsx(Autocomplete, Object.assign({ freeSolo: true, getOptionLabel: (option) => getValueAndLabel(option).label, onChange: (_e, newValue) => handleAutocompleteChange(newValue), options: (_v = dropdownOptions === null || dropdownOptions === void 0 ? void 0 : dropdownOptions.map((option) => getValueAndLabel(option))) !== null && _v !== void 0 ? _v : [], inputValue: filterValue, onInputChange: handleAutocompleteInputChange }, autocompleteProps, { renderInput: (builtinTextFieldProps) => {
|
3180
3203
|
var _a, _b, _c, _d, _f;
|
3181
3204
|
return (jsx(TextField, Object.assign({}, commonTextFieldProps, builtinTextFieldProps, { slotProps: Object.assign(Object.assign(Object.assign({}, builtinTextFieldProps.slotProps), commonTextFieldProps.slotProps), { input: Object.assign(Object.assign(Object.assign({}, builtinTextFieldProps.InputProps), (_a = builtinTextFieldProps.slotProps) === null || _a === void 0 ? void 0 : _a.input), { startAdornment:
|
3182
3205
|
//@ts-expect-error
|
3183
|
-
(_c = (_b = commonTextFieldProps === null || commonTextFieldProps === void 0 ? void 0 : commonTextFieldProps.slotProps) === null || _b === void 0 ? void 0 : _b.input) === null || _c === void 0 ? void 0 : _c.startAdornment }), htmlInput: Object.assign(Object.assign(Object.assign({}, builtinTextFieldProps.inputProps), (_d = builtinTextFieldProps.slotProps) === null || _d === void 0 ? void 0 : _d.htmlInput), (_f = commonTextFieldProps === null || commonTextFieldProps === void 0 ? void 0 : commonTextFieldProps.slotProps) === null || _f === void 0 ? void 0 : _f.htmlInput) }),
|
3206
|
+
(_c = (_b = commonTextFieldProps === null || commonTextFieldProps === void 0 ? void 0 : commonTextFieldProps.slotProps) === null || _b === void 0 ? void 0 : _b.input) === null || _c === void 0 ? void 0 : _c.startAdornment }), htmlInput: Object.assign(Object.assign(Object.assign({}, builtinTextFieldProps.inputProps), (_d = builtinTextFieldProps.slotProps) === null || _d === void 0 ? void 0 : _d.htmlInput), (_f = commonTextFieldProps === null || commonTextFieldProps === void 0 ? void 0 : commonTextFieldProps.slotProps) === null || _f === void 0 ? void 0 : _f.htmlInput) }), onClick: (e) => e.stopPropagation() })));
|
3184
3207
|
}, value: autocompleteValue }))) : (jsx(TextField, Object.assign({ select: isSelectFilter || isMultiSelectFilter }, commonTextFieldProps, { slotProps: Object.assign(Object.assign({}, commonTextFieldProps.slotProps), { inputLabel: Object.assign({ shrink: isSelectFilter || isMultiSelectFilter }, (_w = commonTextFieldProps.slotProps) === null || _w === void 0 ? void 0 : _w.inputLabel), select: Object.assign({ MenuProps: { disableScrollLock: true }, displayEmpty: true, multiple: isMultiSelectFilter, renderValue: isMultiSelectFilter
|
3185
3208
|
? (selected) => !Array.isArray(selected) || (selected === null || selected === void 0 ? void 0 : selected.length) === 0 ? (jsx(Box, { sx: { opacity: 0.5 }, children: filterPlaceholder })) : (jsx(Box, { sx: { display: 'flex', flexWrap: 'wrap', gap: '2px' }, children: selected.map((value) => {
|
3186
3209
|
const selectedValue = dropdownOptions === null || dropdownOptions === void 0 ? void 0 : dropdownOptions.find((option) => getValueAndLabel(option).value === value);
|
@@ -3674,7 +3697,7 @@ const MRT_ToolbarAlertBanner = (_a) => {
|
|
3674
3697
|
const selectedRowCount = useMemo(() => manualPagination
|
3675
3698
|
? Object.values(rowSelection).filter(Boolean).length
|
3676
3699
|
: getFilteredSelectedRowModel().rows.length, [rowSelection, totalRowCount, manualPagination]);
|
3677
|
-
const selectedAlert = selectedRowCount > 0 ? (jsxs(Stack, { alignItems: "center", direction: "row", gap: "16px", children: [(_c = (_b = localization.selectedCountOfRowCountRowsSelected) === null || _b === void 0 ? void 0 : _b.replace('{selectedCount}', selectedRowCount.toLocaleString())) === null || _c === void 0 ? void 0 : _c.replace('{rowCount}', totalRowCount.
|
3700
|
+
const selectedAlert = selectedRowCount > 0 ? (jsxs(Stack, { alignItems: "center", direction: "row", gap: "16px", children: [(_c = (_b = localization.selectedCountOfRowCountRowsSelected) === null || _b === void 0 ? void 0 : _b.replace('{selectedCount}', selectedRowCount.toLocaleString(localization.language))) === null || _c === void 0 ? void 0 : _c.replace('{rowCount}', totalRowCount.toLocaleString(localization.language)), jsx(Button, { onClick: (event) => getMRT_SelectAllHandler({ table })(event, false, true), size: "small", sx: { p: '2px' }, children: localization.clearSelection })] })) : null;
|
3678
3701
|
const groupedAlert = grouping.length > 0 ? (jsxs("span", { children: [localization.groupedBy, ' ', grouping.map((columnId, index) => (jsxs(Fragment$1, { children: [index > 0 ? localization.thenBy : '', jsx(Chip, Object.assign({ label: table.getColumn(columnId).columnDef.header, onDelete: () => table.getColumn(columnId).toggleGrouping() }, chipProps))] }, `${index}-${columnId}`)))] })) : null;
|
3679
3702
|
return (jsx(Collapse, { in: showAlertBanner || !!selectedAlert || !!groupedAlert, timeout: stackAlertBanner ? 200 : 0, children: jsx(Alert, Object.assign({ color: "info", icon: false }, alertProps, { sx: (theme) => {
|
3680
3703
|
var _a, _b;
|
@@ -3959,7 +3982,9 @@ const MRT_TablePagination = (_a) => {
|
|
3959
3982
|
last: LastPageIcon,
|
3960
3983
|
next: ChevronRightIcon,
|
3961
3984
|
previous: ChevronLeftIcon,
|
3962
|
-
} }, item))), showFirstButton: showFirstButton, showLastButton: showLastButton }, restPaginationProps))) : paginationDisplayMode === 'default' ? (jsxs(Fragment, { children: [jsx(Typography, { align: "center", component: "span", sx: { m: '0 4px', minWidth: '8ch' }, variant: "body2", children: `${lastRowIndex === 0
|
3985
|
+
} }, item))), showFirstButton: showFirstButton, showLastButton: showLastButton }, restPaginationProps))) : paginationDisplayMode === 'default' ? (jsxs(Fragment, { children: [jsx(Typography, { align: "center", component: "span", sx: { m: '0 4px', minWidth: '8ch' }, variant: "body2", children: `${lastRowIndex === 0
|
3986
|
+
? 0
|
3987
|
+
: (firstRowIndex + 1).toLocaleString(localization.language)}-${lastRowIndex.toLocaleString(localization.language)} ${localization.of} ${totalRowCount.toLocaleString(localization.language)}` }), jsxs(Box, { gap: "xs", children: [showFirstButton && (jsx(Tooltip, Object.assign({}, tooltipProps, { title: localization.goToFirstPage, children: jsx("span", { children: jsx(IconButton, { "aria-label": localization.goToFirstPage, disabled: disableBack, onClick: () => table.firstPage(), size: "small", children: jsx(FirstPageIcon, Object.assign({}, flipIconStyles(theme))) }) }) }))), jsx(Tooltip, Object.assign({}, tooltipProps, { title: localization.goToPreviousPage, children: jsx("span", { children: jsx(IconButton, { "aria-label": localization.goToPreviousPage, disabled: disableBack, onClick: () => table.previousPage(), size: "small", children: jsx(ChevronLeftIcon, Object.assign({}, flipIconStyles(theme))) }) }) })), jsx(Tooltip, Object.assign({}, tooltipProps, { title: localization.goToNextPage, children: jsx("span", { children: jsx(IconButton, { "aria-label": localization.goToNextPage, disabled: disableNext, onClick: () => table.nextPage(), size: "small", children: jsx(ChevronRightIcon, Object.assign({}, flipIconStyles(theme))) }) }) })), showLastButton && (jsx(Tooltip, Object.assign({}, tooltipProps, { title: localization.goToLastPage, children: jsx("span", { children: jsx(IconButton, { "aria-label": localization.goToLastPage, disabled: disableNext, onClick: () => table.lastPage(), size: "small", children: jsx(LastPageIcon, Object.assign({}, flipIconStyles(theme))) }) }) })))] })] })) : null] }));
|
3963
3988
|
};
|
3964
3989
|
|
3965
3990
|
const MRT_ToolbarDropZone = (_a) => {
|