material-react-table 2.11.3 → 2.12.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +29 -22
- package/dist/index.d.ts +19 -2
- package/dist/index.esm.js +136 -105
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +137 -104
- package/dist/index.js.map +1 -1
- package/locales/hr/index.d.ts +3 -0
- package/locales/hr/index.esm.d.ts +3 -0
- package/locales/hr/index.esm.js +95 -0
- package/locales/hr/index.js +99 -0
- package/locales/hr/package.json +6 -0
- package/package.json +25 -25
- package/src/components/body/MRT_TableBodyCell.tsx +7 -0
- package/src/components/body/MRT_TableBodyRow.tsx +5 -0
- package/src/components/body/MRT_TableDetailPanel.tsx +2 -5
- package/src/components/head/MRT_TableHead.tsx +11 -11
- package/src/components/head/MRT_TableHeadCell.tsx +7 -0
- package/src/components/head/MRT_TableHeadCellFilterContainer.tsx +3 -4
- package/src/components/head/MRT_TableHeadCellFilterLabel.tsx +61 -37
- package/src/components/inputs/MRT_FilterRangeFields.tsx +8 -2
- package/src/components/inputs/MRT_FilterTextField.tsx +41 -63
- package/src/components/menus/MRT_ShowHideColumnsMenuItems.tsx +1 -4
- package/src/components/table/MRT_TablePaper.tsx +4 -4
- package/src/components/toolbar/MRT_TablePagination.tsx +10 -12
- package/src/components/toolbar/MRT_ToolbarDropZone.tsx +5 -0
- package/src/hooks/display-columns/getMRT_RowActionsColumnDef.tsx +1 -1
- package/src/hooks/display-columns/getMRT_RowDragColumnDef.tsx +1 -1
- package/src/hooks/display-columns/getMRT_RowExpandColumnDef.tsx +1 -1
- package/src/hooks/display-columns/getMRT_RowNumbersColumnDef.tsx +1 -1
- package/src/hooks/display-columns/getMRT_RowPinningColumnDef.tsx +1 -1
- package/src/hooks/display-columns/getMRT_RowSelectColumnDef.tsx +1 -1
- package/src/hooks/display-columns/getMRT_RowSpacerColumnDef.tsx +1 -1
- package/src/hooks/useMRT_ColumnVirtualizer.ts +6 -8
- package/src/locales/hr.ts +96 -0
- package/src/types.ts +0 -1
- package/src/utils/column.utils.ts +86 -0
- package/src/utils/utils.ts +1 -1
@@ -3,7 +3,6 @@ import {
|
|
3
3
|
type MouseEvent,
|
4
4
|
useCallback,
|
5
5
|
useEffect,
|
6
|
-
useMemo,
|
7
6
|
useRef,
|
8
7
|
useState,
|
9
8
|
} from 'react';
|
@@ -35,6 +34,10 @@ import {
|
|
35
34
|
type MRT_RowData,
|
36
35
|
type MRT_TableInstance,
|
37
36
|
} from '../../types';
|
37
|
+
import {
|
38
|
+
getColumnFilterInfo,
|
39
|
+
useDropdownOptions,
|
40
|
+
} from '../../utils/column.utils';
|
38
41
|
import { getValueAndLabel, parseFromValuesOrFunc } from '../../utils/utils';
|
39
42
|
import { MRT_FilterOptionMenu } from '../menus/MRT_FilterOptionMenu';
|
40
43
|
|
@@ -53,7 +56,6 @@ export const MRT_FilterTextField = <TData extends MRT_RowData>({
|
|
53
56
|
}: MRT_FilterTextFieldProps<TData>) => {
|
54
57
|
const {
|
55
58
|
options: {
|
56
|
-
columnFilterModeOptions,
|
57
59
|
enableColumnFilterModes,
|
58
60
|
icons: { CloseIcon, FilterListIcon },
|
59
61
|
localization,
|
@@ -71,58 +73,48 @@ export const MRT_FilterTextField = <TData extends MRT_RowData>({
|
|
71
73
|
const { columnDef } = column;
|
72
74
|
const { filterVariant } = columnDef;
|
73
75
|
|
76
|
+
const args = { column, rangeFilterIndex, table };
|
77
|
+
|
74
78
|
const textFieldProps: TextFieldProps = {
|
75
|
-
...parseFromValuesOrFunc(muiFilterTextFieldProps,
|
76
|
-
...parseFromValuesOrFunc(columnDef.muiFilterTextFieldProps,
|
77
|
-
column,
|
78
|
-
table,
|
79
|
-
}),
|
79
|
+
...parseFromValuesOrFunc(muiFilterTextFieldProps, args),
|
80
|
+
...parseFromValuesOrFunc(columnDef.muiFilterTextFieldProps, args),
|
80
81
|
...rest,
|
81
82
|
};
|
82
83
|
|
83
84
|
const autocompleteProps = {
|
84
|
-
...parseFromValuesOrFunc(muiFilterAutocompleteProps,
|
85
|
-
...parseFromValuesOrFunc(columnDef.muiFilterAutocompleteProps,
|
86
|
-
column,
|
87
|
-
table,
|
88
|
-
}),
|
85
|
+
...parseFromValuesOrFunc(muiFilterAutocompleteProps, args),
|
86
|
+
...parseFromValuesOrFunc(columnDef.muiFilterAutocompleteProps, args),
|
89
87
|
};
|
90
88
|
|
91
89
|
const datePickerProps: DatePickerProps<any> = {
|
92
|
-
...parseFromValuesOrFunc(muiFilterDatePickerProps,
|
93
|
-
...parseFromValuesOrFunc(columnDef.muiFilterDatePickerProps,
|
94
|
-
column,
|
95
|
-
table,
|
96
|
-
}),
|
90
|
+
...parseFromValuesOrFunc(muiFilterDatePickerProps, args),
|
91
|
+
...parseFromValuesOrFunc(columnDef.muiFilterDatePickerProps, args),
|
97
92
|
};
|
98
93
|
|
99
94
|
const dateTimePickerProps: DateTimePickerProps<any> = {
|
100
|
-
...parseFromValuesOrFunc(muiFilterDateTimePickerProps,
|
101
|
-
...parseFromValuesOrFunc(columnDef.muiFilterDateTimePickerProps,
|
102
|
-
column,
|
103
|
-
table,
|
104
|
-
}),
|
95
|
+
...parseFromValuesOrFunc(muiFilterDateTimePickerProps, args),
|
96
|
+
...parseFromValuesOrFunc(columnDef.muiFilterDateTimePickerProps, args),
|
105
97
|
};
|
106
98
|
|
107
99
|
const timePickerProps: TimePickerProps<any> = {
|
108
|
-
...parseFromValuesOrFunc(muiFilterTimePickerProps,
|
109
|
-
...parseFromValuesOrFunc(columnDef.muiFilterTimePickerProps,
|
110
|
-
column,
|
111
|
-
table,
|
112
|
-
}),
|
100
|
+
...parseFromValuesOrFunc(muiFilterTimePickerProps, args),
|
101
|
+
...parseFromValuesOrFunc(columnDef.muiFilterTimePickerProps, args),
|
113
102
|
};
|
114
103
|
|
115
|
-
const
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
104
|
+
const {
|
105
|
+
allowedColumnFilterOptions,
|
106
|
+
currentFilterOption,
|
107
|
+
facetedUniqueValues,
|
108
|
+
isAutocompleteFilter,
|
109
|
+
isDateFilter,
|
110
|
+
isMultiSelectFilter,
|
111
|
+
isRangeFilter,
|
112
|
+
isSelectFilter,
|
113
|
+
isTextboxFilter,
|
114
|
+
} = getColumnFilterInfo({ header, table });
|
115
|
+
|
116
|
+
const dropdownOptions = useDropdownOptions({ header, table });
|
117
|
+
|
126
118
|
const filterChipLabel = ['empty', 'notEmpty'].includes(currentFilterOption)
|
127
119
|
? //@ts-ignore
|
128
120
|
localization[
|
@@ -132,6 +124,7 @@ export const MRT_FilterTextField = <TData extends MRT_RowData>({
|
|
132
124
|
}`
|
133
125
|
]
|
134
126
|
: '';
|
127
|
+
|
135
128
|
const filterPlaceholder = !isRangeFilter
|
136
129
|
? textFieldProps?.placeholder ??
|
137
130
|
localization.filterByColumn?.replace('{column}', String(columnDef.header))
|
@@ -140,16 +133,14 @@ export const MRT_FilterTextField = <TData extends MRT_RowData>({
|
|
140
133
|
: rangeFilterIndex === 1
|
141
134
|
? localization.max
|
142
135
|
: '';
|
143
|
-
|
144
|
-
|
145
|
-
const showChangeModeButton =
|
136
|
+
|
137
|
+
const showChangeModeButton = !!(
|
146
138
|
enableColumnFilterModes &&
|
147
139
|
columnDef.enableColumnFilterModes !== false &&
|
148
140
|
!rangeFilterIndex &&
|
149
141
|
(allowedColumnFilterOptions === undefined ||
|
150
|
-
!!allowedColumnFilterOptions?.length)
|
151
|
-
|
152
|
-
const facetedUniqueValues = column.getFacetedUniqueValues();
|
142
|
+
!!allowedColumnFilterOptions?.length)
|
143
|
+
);
|
153
144
|
|
154
145
|
const [anchorEl, setAnchorEl] = useState<HTMLElement | null>(null);
|
155
146
|
const [filterValue, setFilterValue] = useState<string | string[]>(() =>
|
@@ -257,23 +248,6 @@ export const MRT_FilterTextField = <TData extends MRT_RowData>({
|
|
257
248
|
);
|
258
249
|
}
|
259
250
|
|
260
|
-
const dropdownOptions = useMemo(
|
261
|
-
() =>
|
262
|
-
columnDef.filterSelectOptions ??
|
263
|
-
((isSelectFilter || isMultiSelectFilter || isAutocompleteFilter) &&
|
264
|
-
facetedUniqueValues
|
265
|
-
? Array.from(facetedUniqueValues.keys())
|
266
|
-
.filter((value) => value !== null && value !== undefined)
|
267
|
-
.sort((a, b) => a.localeCompare(b))
|
268
|
-
: undefined),
|
269
|
-
[
|
270
|
-
columnDef.filterSelectOptions,
|
271
|
-
facetedUniqueValues,
|
272
|
-
isMultiSelectFilter,
|
273
|
-
isSelectFilter,
|
274
|
-
],
|
275
|
-
);
|
276
|
-
|
277
251
|
const endAdornment =
|
278
252
|
!isAutocompleteFilter && !isDateFilter && !filterChipLabel ? (
|
279
253
|
<InputAdornment
|
@@ -447,8 +421,12 @@ export const MRT_FilterTextField = <TData extends MRT_RowData>({
|
|
447
421
|
) : isAutocompleteFilter ? (
|
448
422
|
<Autocomplete
|
449
423
|
freeSolo
|
450
|
-
getOptionLabel={(option) =>
|
451
|
-
|
424
|
+
getOptionLabel={(option: DropdownOption) =>
|
425
|
+
getValueAndLabel(option).label
|
426
|
+
}
|
427
|
+
onChange={(_e, newValue: DropdownOption) =>
|
428
|
+
handleAutocompleteChange(newValue)
|
429
|
+
}
|
452
430
|
options={
|
453
431
|
dropdownOptions?.map((option) => getValueAndLabel(option)) ?? []
|
454
432
|
}
|
@@ -56,10 +56,7 @@ export const MRT_ShowHideColumnsMenuItems = <TData extends MRT_RowData>({
|
|
56
56
|
const { columnDef } = column;
|
57
57
|
const { columnDefType } = columnDef;
|
58
58
|
|
59
|
-
const switchChecked =
|
60
|
-
(columnDefType !== 'group' && column.getIsVisible()) ||
|
61
|
-
(columnDefType === 'group' &&
|
62
|
-
column.getLeafColumns().some((col) => col.getIsVisible()));
|
59
|
+
const switchChecked = column.getIsVisible();
|
63
60
|
|
64
61
|
const handleToggleColumnHidden = (column: MRT_Column<TData>) => {
|
65
62
|
if (columnDefType === 'group') {
|
@@ -48,16 +48,16 @@ export const MRT_TablePaper = <TData extends MRT_RowData>({
|
|
48
48
|
...(isFullScreen
|
49
49
|
? {
|
50
50
|
bottom: 0,
|
51
|
-
height: '
|
51
|
+
height: '100dvh',
|
52
52
|
left: 0,
|
53
53
|
margin: 0,
|
54
|
-
maxHeight: '
|
55
|
-
maxWidth: '
|
54
|
+
maxHeight: '100dvh',
|
55
|
+
maxWidth: '100dvw',
|
56
56
|
padding: 0,
|
57
57
|
position: 'fixed',
|
58
58
|
right: 0,
|
59
59
|
top: 0,
|
60
|
-
width: '
|
60
|
+
width: '100dvw',
|
61
61
|
zIndex: 999,
|
62
62
|
}
|
63
63
|
: {}),
|
@@ -37,7 +37,6 @@ export const MRT_TablePagination = <TData extends MRT_RowData>({
|
|
37
37
|
const isMobile = useMediaQuery('(max-width: 720px)');
|
38
38
|
|
39
39
|
const {
|
40
|
-
getPrePaginationRowModel,
|
41
40
|
getState,
|
42
41
|
options: {
|
43
42
|
enableToolbarInternalActions,
|
@@ -45,10 +44,7 @@ export const MRT_TablePagination = <TData extends MRT_RowData>({
|
|
45
44
|
localization,
|
46
45
|
muiPaginationProps,
|
47
46
|
paginationDisplayMode,
|
48
|
-
rowCount,
|
49
47
|
},
|
50
|
-
setPageIndex,
|
51
|
-
setPageSize,
|
52
48
|
} = table;
|
53
49
|
const {
|
54
50
|
pagination: { pageIndex = 0, pageSize = 10 },
|
@@ -62,8 +58,8 @@ export const MRT_TablePagination = <TData extends MRT_RowData>({
|
|
62
58
|
...rest,
|
63
59
|
};
|
64
60
|
|
65
|
-
const totalRowCount =
|
66
|
-
const numberOfPages =
|
61
|
+
const totalRowCount = table.getRowCount();
|
62
|
+
const numberOfPages = table.getPageCount();
|
67
63
|
const showFirstLastPageButtons = numberOfPages > 2;
|
68
64
|
const firstRowIndex = pageIndex * pageSize;
|
69
65
|
const lastRowIndex = Math.min(pageIndex * pageSize + pageSize, totalRowCount);
|
@@ -123,7 +119,9 @@ export const MRT_TablePagination = <TData extends MRT_RowData>({
|
|
123
119
|
id: 'mrt-rows-per-page',
|
124
120
|
}}
|
125
121
|
label={localization.rowsPerPage}
|
126
|
-
onChange={(event) =>
|
122
|
+
onChange={(event) =>
|
123
|
+
table.setPageSize(+(event.target.value as any))
|
124
|
+
}
|
127
125
|
sx={{ mb: 0 }}
|
128
126
|
value={pageSize}
|
129
127
|
variant="standard"
|
@@ -153,7 +151,7 @@ export const MRT_TablePagination = <TData extends MRT_RowData>({
|
|
153
151
|
<Pagination
|
154
152
|
count={numberOfPages}
|
155
153
|
disabled={disabled}
|
156
|
-
onChange={(_e, newPageIndex) => setPageIndex(newPageIndex - 1)}
|
154
|
+
onChange={(_e, newPageIndex) => table.setPageIndex(newPageIndex - 1)}
|
157
155
|
page={pageIndex + 1}
|
158
156
|
renderItem={(item) => (
|
159
157
|
<PaginationItem
|
@@ -189,7 +187,7 @@ export const MRT_TablePagination = <TData extends MRT_RowData>({
|
|
189
187
|
<IconButton
|
190
188
|
aria-label={localization.goToFirstPage}
|
191
189
|
disabled={disableBack}
|
192
|
-
onClick={() =>
|
190
|
+
onClick={() => table.firstPage()}
|
193
191
|
size="small"
|
194
192
|
>
|
195
193
|
<FirstPageIcon {...flipIconStyles(theme)} />
|
@@ -202,7 +200,7 @@ export const MRT_TablePagination = <TData extends MRT_RowData>({
|
|
202
200
|
<IconButton
|
203
201
|
aria-label={localization.goToPreviousPage}
|
204
202
|
disabled={disableBack}
|
205
|
-
onClick={() =>
|
203
|
+
onClick={() => table.previousPage()}
|
206
204
|
size="small"
|
207
205
|
>
|
208
206
|
<ChevronLeftIcon {...flipIconStyles(theme)} />
|
@@ -214,7 +212,7 @@ export const MRT_TablePagination = <TData extends MRT_RowData>({
|
|
214
212
|
<IconButton
|
215
213
|
aria-label={localization.goToNextPage}
|
216
214
|
disabled={disableNext}
|
217
|
-
onClick={() =>
|
215
|
+
onClick={() => table.nextPage()}
|
218
216
|
size="small"
|
219
217
|
>
|
220
218
|
<ChevronRightIcon {...flipIconStyles(theme)} />
|
@@ -227,7 +225,7 @@ export const MRT_TablePagination = <TData extends MRT_RowData>({
|
|
227
225
|
<IconButton
|
228
226
|
aria-label={localization.goToLastPage}
|
229
227
|
disabled={disableNext}
|
230
|
-
onClick={() =>
|
228
|
+
onClick={() => table.lastPage()}
|
231
229
|
size="small"
|
232
230
|
>
|
233
231
|
<LastPageIcon {...flipIconStyles(theme)} />
|
@@ -29,6 +29,10 @@ export const MRT_ToolbarDropZone = <TData extends MRT_RowData>({
|
|
29
29
|
setHoveredColumn({ id: 'drop-zone' });
|
30
30
|
};
|
31
31
|
|
32
|
+
const handleDragOver = (e: DragEvent) => {
|
33
|
+
e.preventDefault();
|
34
|
+
};
|
35
|
+
|
32
36
|
useEffect(() => {
|
33
37
|
if (table.options.state?.showToolbarDropZone !== undefined) {
|
34
38
|
setShowToolbarDropZone(
|
@@ -45,6 +49,7 @@ export const MRT_ToolbarDropZone = <TData extends MRT_RowData>({
|
|
45
49
|
<Box
|
46
50
|
className="Mui-ToolbarDropZone"
|
47
51
|
onDragEnter={handleDragEnter}
|
52
|
+
onDragOver={handleDragOver}
|
48
53
|
{...rest}
|
49
54
|
sx={(theme) => ({
|
50
55
|
alignItems: 'center',
|
@@ -8,7 +8,7 @@ import { defaultDisplayColumnProps } from '../../utils/displayColumn.utils';
|
|
8
8
|
|
9
9
|
export const getMRT_RowActionsColumnDef = <TData extends MRT_RowData>(
|
10
10
|
tableOptions: MRT_StatefulTableOptions<TData>,
|
11
|
-
): MRT_ColumnDef<TData>
|
11
|
+
): MRT_ColumnDef<TData> => {
|
12
12
|
return {
|
13
13
|
Cell: ({ cell, row, staticRowIndex, table }) => (
|
14
14
|
<MRT_ToggleRowActionMenuButton
|
@@ -9,7 +9,7 @@ import { defaultDisplayColumnProps } from '../../utils/displayColumn.utils';
|
|
9
9
|
|
10
10
|
export const getMRT_RowDragColumnDef = <TData extends MRT_RowData>(
|
11
11
|
tableOptions: MRT_StatefulTableOptions<TData>,
|
12
|
-
): MRT_ColumnDef<TData>
|
12
|
+
): MRT_ColumnDef<TData> => {
|
13
13
|
return {
|
14
14
|
Cell: ({ row, rowRef, table }) => (
|
15
15
|
<MRT_TableBodyRowGrabHandle
|
@@ -13,7 +13,7 @@ import { getCommonTooltipProps } from '../../utils/style.utils';
|
|
13
13
|
|
14
14
|
export const getMRT_RowExpandColumnDef = <TData extends MRT_RowData>(
|
15
15
|
tableOptions: MRT_StatefulTableOptions<TData>,
|
16
|
-
): MRT_ColumnDef<TData>
|
16
|
+
): MRT_ColumnDef<TData> => {
|
17
17
|
const {
|
18
18
|
defaultColumn,
|
19
19
|
enableExpandAll,
|
@@ -7,7 +7,7 @@ import { defaultDisplayColumnProps } from '../../utils/displayColumn.utils';
|
|
7
7
|
|
8
8
|
export const getMRT_RowNumbersColumnDef = <TData extends MRT_RowData>(
|
9
9
|
tableOptions: MRT_StatefulTableOptions<TData>,
|
10
|
-
): MRT_ColumnDef<TData>
|
10
|
+
): MRT_ColumnDef<TData> => {
|
11
11
|
const { localization, rowNumberDisplayMode } = tableOptions;
|
12
12
|
const {
|
13
13
|
pagination: { pageIndex, pageSize },
|
@@ -8,7 +8,7 @@ import { defaultDisplayColumnProps } from '../../utils/displayColumn.utils';
|
|
8
8
|
|
9
9
|
export const getMRT_RowPinningColumnDef = <TData extends MRT_RowData>(
|
10
10
|
tableOptions: MRT_StatefulTableOptions<TData>,
|
11
|
-
): MRT_ColumnDef<TData>
|
11
|
+
): MRT_ColumnDef<TData> => {
|
12
12
|
return {
|
13
13
|
Cell: ({ row, table }) => (
|
14
14
|
<MRT_TableBodyRowPinButton row={row} table={table} />
|
@@ -8,7 +8,7 @@ import { defaultDisplayColumnProps } from '../../utils/displayColumn.utils';
|
|
8
8
|
|
9
9
|
export const getMRT_RowSelectColumnDef = <TData extends MRT_RowData>(
|
10
10
|
tableOptions: MRT_StatefulTableOptions<TData>,
|
11
|
-
): MRT_ColumnDef<TData>
|
11
|
+
): MRT_ColumnDef<TData> => {
|
12
12
|
const { enableMultiRowSelection, enableSelectAll } = tableOptions;
|
13
13
|
|
14
14
|
return {
|
@@ -17,7 +17,7 @@ const blankColProps = {
|
|
17
17
|
|
18
18
|
export const getMRT_RowSpacerColumnDef = <TData extends MRT_RowData>(
|
19
19
|
tableOptions: MRT_StatefulTableOptions<TData>,
|
20
|
-
): MRT_ColumnDef<TData>
|
20
|
+
): MRT_ColumnDef<TData> => {
|
21
21
|
return {
|
22
22
|
...defaultDisplayColumnProps({
|
23
23
|
id: 'mrt-row-spacer',
|
@@ -16,10 +16,7 @@ export const useMRT_ColumnVirtualizer = <
|
|
16
16
|
table: MRT_TableInstance<TData>,
|
17
17
|
): MRT_ColumnVirtualizer | undefined => {
|
18
18
|
const {
|
19
|
-
getLeftLeafColumns,
|
20
|
-
getRightLeafColumns,
|
21
19
|
getState,
|
22
|
-
getVisibleLeafColumns,
|
23
20
|
options: {
|
24
21
|
columnVirtualizerInstanceRef,
|
25
22
|
columnVirtualizerOptions,
|
@@ -28,7 +25,7 @@ export const useMRT_ColumnVirtualizer = <
|
|
28
25
|
},
|
29
26
|
refs: { tableContainerRef },
|
30
27
|
} = table;
|
31
|
-
const { columnPinning, draggingColumn } = getState();
|
28
|
+
const { columnPinning, columnVisibility, draggingColumn } = getState();
|
32
29
|
|
33
30
|
if (!enableColumnVirtualization) return undefined;
|
34
31
|
|
@@ -39,21 +36,22 @@ export const useMRT_ColumnVirtualizer = <
|
|
39
36
|
},
|
40
37
|
);
|
41
38
|
|
42
|
-
const visibleColumns = getVisibleLeafColumns();
|
39
|
+
const visibleColumns = table.getVisibleLeafColumns();
|
43
40
|
|
44
41
|
const [leftPinnedIndexes, rightPinnedIndexes] = useMemo(
|
45
42
|
() =>
|
46
43
|
enableColumnPinning
|
47
44
|
? [
|
48
|
-
|
49
|
-
|
45
|
+
table.getLeftVisibleLeafColumns().map((c) => c.getPinnedIndex()),
|
46
|
+
table
|
47
|
+
.getRightVisibleLeafColumns()
|
50
48
|
.map(
|
51
49
|
(column) => visibleColumns.length - column.getPinnedIndex() - 1,
|
52
50
|
)
|
53
51
|
.sort((a, b) => a - b),
|
54
52
|
]
|
55
53
|
: [[], []],
|
56
|
-
[columnPinning, enableColumnPinning],
|
54
|
+
[columnPinning, columnVisibility, enableColumnPinning],
|
57
55
|
);
|
58
56
|
|
59
57
|
const numPinnedLeft = leftPinnedIndexes.length;
|
@@ -0,0 +1,96 @@
|
|
1
|
+
import { type MRT_Localization } from '..';
|
2
|
+
|
3
|
+
export const MRT_Localization_HR: MRT_Localization = {
|
4
|
+
actions: 'Radnje',
|
5
|
+
and: 'i',
|
6
|
+
cancel: 'Odustani',
|
7
|
+
changeFilterMode: 'Promijeni način filtriranja',
|
8
|
+
changeSearchMode: 'Promijeni način pretraživanja',
|
9
|
+
clearFilter: 'Očisti filtriranje',
|
10
|
+
clearSearch: 'Očisti pretragu',
|
11
|
+
clearSelection: 'Očisti odabir',
|
12
|
+
clearSort: 'Očisti sortiranje',
|
13
|
+
clickToCopy: 'Klikni za kopiranje',
|
14
|
+
copy: 'Kopiraj',
|
15
|
+
collapse: 'Sažmi',
|
16
|
+
collapseAll: 'Sažmi sve',
|
17
|
+
columnActions: 'Radnje s stupcima',
|
18
|
+
copiedToClipboard: 'Kopirano u međuspremnik',
|
19
|
+
dropToGroupBy: 'Ispusti za grupiranje po {column}',
|
20
|
+
edit: 'Uredi',
|
21
|
+
expand: 'Proširi',
|
22
|
+
expandAll: 'Proširi sve',
|
23
|
+
filterArrIncludes: 'Uključuje',
|
24
|
+
filterArrIncludesAll: 'Uključuje sve',
|
25
|
+
filterArrIncludesSome: 'Uključuje',
|
26
|
+
filterBetween: 'Između',
|
27
|
+
filterBetweenInclusive: 'Između uključivo',
|
28
|
+
filterByColumn: 'Filtriraj po {column}',
|
29
|
+
filterContains: 'Sadrži',
|
30
|
+
filterEmpty: 'Prazno',
|
31
|
+
filterEndsWith: 'Završava s',
|
32
|
+
filterEquals: 'Jednako',
|
33
|
+
filterEqualsString: 'Jednako',
|
34
|
+
filterFuzzy: 'Maglovito',
|
35
|
+
filterGreaterThan: 'Veće od',
|
36
|
+
filterGreaterThanOrEqualTo: 'Veće od ili jednako',
|
37
|
+
filterInNumberRange: 'Između',
|
38
|
+
filterIncludesString: 'Sadrži',
|
39
|
+
filterIncludesStringSensitive: 'Sadrži',
|
40
|
+
filterLessThan: 'Manje od',
|
41
|
+
filterLessThanOrEqualTo: 'Manje od ili jednako',
|
42
|
+
filterMode: 'Način filtriranja: {filterType}',
|
43
|
+
filterNotEmpty: 'Nije prazno',
|
44
|
+
filterNotEquals: 'Nije jednako',
|
45
|
+
filterStartsWith: 'Počinje s',
|
46
|
+
filterWeakEquals: 'Jednako',
|
47
|
+
filteringByColumn: 'Filtriranje po {column} - {filterType} {filterValue}',
|
48
|
+
goToFirstPage: 'Idi na prvu stranicu',
|
49
|
+
goToLastPage: 'Idi na zadnju stranicu',
|
50
|
+
goToNextPage: 'Idi na sljedeću stranicu',
|
51
|
+
goToPreviousPage: 'Idi na prethodnu stranicu',
|
52
|
+
grab: 'Uhvati',
|
53
|
+
groupByColumn: 'Grupiraj po {column}',
|
54
|
+
groupedBy: 'Grupirano po ',
|
55
|
+
hideAll: 'Sakrij sve',
|
56
|
+
hideColumn: 'Sakrij stupac {column}',
|
57
|
+
max: 'Maks.',
|
58
|
+
min: 'Min.',
|
59
|
+
move: 'Premjesti',
|
60
|
+
noRecordsToDisplay: 'Nema zapisa za prikaz',
|
61
|
+
noResultsFound: 'Nema pronađenih rezultata',
|
62
|
+
of: 'od',
|
63
|
+
or: 'ili',
|
64
|
+
pin: 'Prikači',
|
65
|
+
pinToLeft: 'Prikači na lijevo',
|
66
|
+
pinToRight: 'Prikači na desno',
|
67
|
+
resetColumnSize: 'Resetiraj veličinu stupca',
|
68
|
+
resetOrder: 'Resetiraj redoslijed',
|
69
|
+
rowActions: 'Radnje retka',
|
70
|
+
rowNumber: '#',
|
71
|
+
rowNumbers: 'Brojevi redaka',
|
72
|
+
rowsPerPage: 'Redaka po stranici',
|
73
|
+
save: 'Spremi',
|
74
|
+
search: 'Pretraži',
|
75
|
+
selectedCountOfRowCountRowsSelected:
|
76
|
+
'{selectedCount} od {rowCount} odabranih redaka',
|
77
|
+
select: 'Odaberi',
|
78
|
+
showAll: 'Prikaži sve',
|
79
|
+
showAllColumns: 'Prikaži sve stupce',
|
80
|
+
showHideColumns: 'Prikaži/sakrij stupce',
|
81
|
+
showHideFilters: 'Prikaži/sakrij filtere',
|
82
|
+
showHideSearch: 'Prikaži/sakrij pretragu',
|
83
|
+
sortByColumnAsc: 'Sortiraj po {column} uzlazno',
|
84
|
+
sortByColumnDesc: 'Sortiraj po {column} silazno',
|
85
|
+
sortedByColumnAsc: 'Sortirano po {column} uzlazno',
|
86
|
+
sortedByColumnDesc: 'Sortirano po {column} silazno',
|
87
|
+
thenBy: ', zatim po ',
|
88
|
+
toggleDensity: 'Promijeni gustoću',
|
89
|
+
toggleFullScreen: 'Prebaci u puni zaslon',
|
90
|
+
toggleSelectAll: 'Prebaci odabir svih',
|
91
|
+
toggleSelectRow: 'Prebaci odabir retka',
|
92
|
+
toggleVisibility: 'Prebaci vidljivost',
|
93
|
+
ungroupByColumn: 'Razgrupiraj po {column}',
|
94
|
+
unpin: 'Odkači',
|
95
|
+
unpinAll: 'Odkači sve',
|
96
|
+
};
|
package/src/types.ts
CHANGED
@@ -1267,7 +1267,6 @@ export type MRT_TableOptions<TData extends MRT_RowData> = Omit<
|
|
1267
1267
|
renderTopToolbarCustomActions?: (props: {
|
1268
1268
|
table: MRT_TableInstance<TData>;
|
1269
1269
|
}) => ReactNode;
|
1270
|
-
rowCount?: number;
|
1271
1270
|
rowNumberDisplayMode?: 'original' | 'static';
|
1272
1271
|
rowPinningDisplayMode?:
|
1273
1272
|
| 'bottom'
|
@@ -1,12 +1,16 @@
|
|
1
|
+
import { useMemo } from 'react';
|
1
2
|
import { type Row } from '@tanstack/react-table';
|
2
3
|
import {
|
4
|
+
type DropdownOption,
|
3
5
|
type MRT_Column,
|
4
6
|
type MRT_ColumnDef,
|
5
7
|
type MRT_ColumnOrderState,
|
6
8
|
type MRT_DefinedColumnDef,
|
7
9
|
type MRT_DefinedTableOptions,
|
8
10
|
type MRT_FilterOption,
|
11
|
+
type MRT_Header,
|
9
12
|
type MRT_RowData,
|
13
|
+
type MRT_TableInstance,
|
10
14
|
} from '../types';
|
11
15
|
|
12
16
|
export const getColumnId = <TData extends MRT_RowData>(
|
@@ -121,3 +125,85 @@ export const getDefaultColumnFilterFn = <TData extends MRT_RowData>(
|
|
121
125
|
return 'equals';
|
122
126
|
return 'fuzzy';
|
123
127
|
};
|
128
|
+
|
129
|
+
export const getColumnFilterInfo = <TData extends MRT_RowData>({
|
130
|
+
header,
|
131
|
+
table,
|
132
|
+
}: {
|
133
|
+
header: MRT_Header<TData>;
|
134
|
+
table: MRT_TableInstance<TData>;
|
135
|
+
}) => {
|
136
|
+
const {
|
137
|
+
options: { columnFilterModeOptions },
|
138
|
+
} = table;
|
139
|
+
const { column } = header;
|
140
|
+
const { columnDef } = column;
|
141
|
+
const { filterVariant } = columnDef;
|
142
|
+
|
143
|
+
const isDateFilter = !!(
|
144
|
+
filterVariant?.startsWith('date') || filterVariant?.startsWith('time')
|
145
|
+
);
|
146
|
+
const isAutocompleteFilter = filterVariant === 'autocomplete';
|
147
|
+
const isRangeFilter =
|
148
|
+
filterVariant?.includes('range') ||
|
149
|
+
['between', 'betweenInclusive', 'inNumberRange'].includes(
|
150
|
+
columnDef._filterFn,
|
151
|
+
);
|
152
|
+
const isSelectFilter = filterVariant === 'select';
|
153
|
+
const isMultiSelectFilter = filterVariant === 'multi-select';
|
154
|
+
const isTextboxFilter =
|
155
|
+
['autocomplete', 'text'].includes(filterVariant!) ||
|
156
|
+
(!isSelectFilter && !isMultiSelectFilter);
|
157
|
+
const currentFilterOption = columnDef._filterFn;
|
158
|
+
|
159
|
+
const allowedColumnFilterOptions =
|
160
|
+
columnDef?.columnFilterModeOptions ?? columnFilterModeOptions;
|
161
|
+
|
162
|
+
const facetedUniqueValues = column.getFacetedUniqueValues();
|
163
|
+
|
164
|
+
return {
|
165
|
+
allowedColumnFilterOptions,
|
166
|
+
currentFilterOption,
|
167
|
+
facetedUniqueValues,
|
168
|
+
isAutocompleteFilter,
|
169
|
+
isDateFilter,
|
170
|
+
isMultiSelectFilter,
|
171
|
+
isRangeFilter,
|
172
|
+
isSelectFilter,
|
173
|
+
isTextboxFilter,
|
174
|
+
} as const;
|
175
|
+
};
|
176
|
+
|
177
|
+
export const useDropdownOptions = <TData extends MRT_RowData>({
|
178
|
+
header,
|
179
|
+
table,
|
180
|
+
}: {
|
181
|
+
header: MRT_Header<TData>;
|
182
|
+
table: MRT_TableInstance<TData>;
|
183
|
+
}): DropdownOption[] | undefined => {
|
184
|
+
const { column } = header;
|
185
|
+
const { columnDef } = column;
|
186
|
+
const {
|
187
|
+
facetedUniqueValues,
|
188
|
+
isAutocompleteFilter,
|
189
|
+
isMultiSelectFilter,
|
190
|
+
isSelectFilter,
|
191
|
+
} = getColumnFilterInfo({ header, table });
|
192
|
+
|
193
|
+
return useMemo<DropdownOption[] | undefined>(
|
194
|
+
() =>
|
195
|
+
columnDef.filterSelectOptions ??
|
196
|
+
((isSelectFilter || isMultiSelectFilter || isAutocompleteFilter) &&
|
197
|
+
facetedUniqueValues
|
198
|
+
? Array.from(facetedUniqueValues.keys())
|
199
|
+
.filter((value) => value !== null && value !== undefined)
|
200
|
+
.sort((a, b) => a.localeCompare(b))
|
201
|
+
: undefined),
|
202
|
+
[
|
203
|
+
columnDef.filterSelectOptions,
|
204
|
+
facetedUniqueValues,
|
205
|
+
isMultiSelectFilter,
|
206
|
+
isSelectFilter,
|
207
|
+
],
|
208
|
+
);
|
209
|
+
};
|
package/src/utils/utils.ts
CHANGED
@@ -6,7 +6,7 @@ export const parseFromValuesOrFunc = <T, U>(
|
|
6
6
|
): T | undefined => (fn instanceof Function ? fn(arg) : fn);
|
7
7
|
|
8
8
|
export const getValueAndLabel = (
|
9
|
-
option
|
9
|
+
option?: DropdownOption,
|
10
10
|
): { label: string; value: string } => {
|
11
11
|
let label: string = '';
|
12
12
|
let value: string = '';
|