@ackplus/react-tanstack-data-table 1.0.19-beta-0.10 → 1.0.19-beta-0.13
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 +2 -2
- package/package.json +1 -1
- package/src/lib/components/table/data-table.d.ts +2 -1
- package/src/lib/components/table/data-table.js +128 -125
- package/src/lib/components/table/data-table.types.d.ts +9 -9
- package/src/lib/components/toolbar/bulk-actions-toolbar.d.ts +1 -1
- package/src/lib/components/toolbar/column-filter-control.d.ts +1 -0
- package/src/lib/components/toolbar/{column-custom-filter-control.js → column-filter-control.js} +22 -20
- package/src/lib/components/toolbar/data-table-toolbar.js +2 -2
- package/src/lib/components/toolbar/index.d.ts +1 -0
- package/src/lib/components/toolbar/index.js +3 -1
- package/src/lib/components/toolbar/table-export-control.d.ts +4 -4
- package/src/lib/contexts/data-table-context.d.ts +8 -8
- package/src/lib/contexts/data-table-context.js +5 -5
- package/src/lib/examples/server-side-fetching-example.js +12 -3
- package/src/lib/features/{custom-column-filter.feature.d.ts → column-filter.feature.d.ts} +14 -14
- package/src/lib/features/{custom-column-filter.feature.js → column-filter.feature.js} +51 -26
- package/src/lib/features/index.d.ts +2 -2
- package/src/lib/features/index.js +6 -6
- package/src/lib/features/{custom-selection.feature.d.ts → selection.feature.d.ts} +8 -8
- package/src/lib/features/{custom-selection.feature.js → selection.feature.js} +20 -8
- package/src/lib/hooks/use-data-table-api.d.ts +7 -19
- package/src/lib/hooks/use-data-table-api.js +84 -104
- package/src/lib/types/data-table-api.d.ts +4 -4
- package/src/lib/types/table.types.d.ts +4 -4
- package/src/lib/utils/column-helpers.d.ts +1 -2
- package/src/lib/utils/column-helpers.js +3 -2
- package/src/lib/utils/export-utils.d.ts +4 -4
- package/src/lib/utils/export-utils.js +32 -15
- package/src/lib/components/toolbar/column-custom-filter-control.d.ts +0 -1
package/README.md
CHANGED
|
@@ -7,7 +7,7 @@ A powerful, feature-rich, and highly customizable React data table component bui
|
|
|
7
7
|
- 🚀 **High Performance**: Built on TanStack Table for excellent performance with large datasets
|
|
8
8
|
- 🎨 **Material Design**: Beautiful UI components using MUI with consistent design system
|
|
9
9
|
- 📱 **Responsive**: Mobile-friendly responsive design with adaptive layouts
|
|
10
|
-
- 🔍 **Advanced Filtering**: Global search, column filters, and
|
|
10
|
+
- 🔍 **Advanced Filtering**: Global search, column filters, and filter components
|
|
11
11
|
- 📊 **Multi-Column Sorting**: Powerful sorting with multiple columns support
|
|
12
12
|
- 📄 **Flexible Pagination**: Client-side and server-side pagination options
|
|
13
13
|
- 🎯 **Column Management**: Show/hide, resize, reorder, and pin columns
|
|
@@ -328,7 +328,7 @@ function SelectableTable() {
|
|
|
328
328
|
}
|
|
329
329
|
```
|
|
330
330
|
|
|
331
|
-
###
|
|
331
|
+
### Column Filters
|
|
332
332
|
|
|
333
333
|
```tsx
|
|
334
334
|
const columns = [
|
package/package.json
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import React from 'react';
|
|
1
2
|
import { DataTableProps } from './data-table.types';
|
|
2
3
|
import { DataTableApi } from '../../types/data-table-api';
|
|
3
|
-
export declare const DataTable:
|
|
4
|
+
export declare const DataTable: React.ForwardRefExoticComponent<DataTableProps<any> & React.RefAttributes<DataTableApi<any>>>;
|
|
@@ -5,7 +5,7 @@ const tslib_1 = require("tslib");
|
|
|
5
5
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
6
6
|
const material_1 = require("@mui/material");
|
|
7
7
|
const react_table_1 = require("@tanstack/react-table");
|
|
8
|
-
const
|
|
8
|
+
const column_filter_feature_1 = require("../../features/column-filter.feature");
|
|
9
9
|
const features_1 = require("../../features");
|
|
10
10
|
const react_virtual_1 = require("@tanstack/react-virtual");
|
|
11
11
|
const react_1 = require("react");
|
|
@@ -40,40 +40,108 @@ const DEFAULT_INITIAL_STATE = {
|
|
|
40
40
|
pendingLogic: 'AND',
|
|
41
41
|
},
|
|
42
42
|
};
|
|
43
|
-
exports.DataTable = (0, react_1.forwardRef)(function DataTable({ initialState, columns, data = [], totalRow = 0, idKey = 'id', extraFilter = null, footerFilter = null, dataMode = 'client', initialLoadData = true, onFetchData, onDataStateChange, enableRowSelection = false, enableMultiRowSelection = true, selectMode = 'page', isRowSelectable, onSelectionChange, enableBulkActions = false, bulkActions
|
|
43
|
+
exports.DataTable = (0, react_1.forwardRef)(function DataTable({ initialState, columns, data = [], totalRow = 0, idKey = 'id', extraFilter = null, footerFilter = null, dataMode = 'client', initialLoadData = true, onFetchData, onDataStateChange, enableRowSelection = false, enableMultiRowSelection = true, selectMode = 'page', isRowSelectable, onSelectionChange, enableBulkActions = false, bulkActions, enableColumnResizing = false, columnResizeMode = 'onChange', enableColumnDragging = false, onColumnDragEnd, enableColumnPinning = false, onColumnPinningChange, enableExpanding = false, getRowCanExpand, renderSubComponent, enablePagination = true, paginationMode = 'client', enableGlobalFilter = true, enableColumnFilter = false, filterMode = 'client', enableSorting = true, sortingMode = 'client', onSortingChange, exportFilename = 'export', onExportProgress, onExportComplete, onExportError, onServerExport, onExportCancel, enableHover = true, enableStripes = false, tableContainerProps = {}, tableProps = {}, fitToScreen = true, tableSize: initialTableSize = 'medium', enableStickyHeaderOrFooter = false, maxHeight = '400px', enableVirtualization = false, estimateRowHeight = 52, enableColumnVisibility = true, enableTableSizeControl = true, enableExport = true, enableReset = true, loading = false, emptyMessage = 'No data available', skeletonRows = 5, onColumnFiltersChange, slots = {}, slotProps = {}, }, ref) {
|
|
44
44
|
var _a;
|
|
45
45
|
const isServerMode = dataMode === 'server';
|
|
46
46
|
const isServerPagination = paginationMode === 'server' || isServerMode;
|
|
47
47
|
const isServerFiltering = filterMode === 'server' || isServerMode;
|
|
48
48
|
const isServerSorting = sortingMode === 'server' || isServerMode;
|
|
49
|
-
const
|
|
50
|
-
const
|
|
51
|
-
|
|
52
|
-
}, [initialState]);
|
|
53
|
-
const [sorting, setSorting] = (0, react_1.useState)(initialStateConfig.sorting);
|
|
54
|
-
const [pagination, setPagination] = (0, react_1.useState)(initialStateConfig.pagination);
|
|
55
|
-
const [globalFilter, setGlobalFilter] = (0, react_1.useState)(initialStateConfig.globalFilter);
|
|
49
|
+
const [sorting, setSorting] = (0, react_1.useState)(DEFAULT_INITIAL_STATE.sorting);
|
|
50
|
+
const [pagination, setPagination] = (0, react_1.useState)(DEFAULT_INITIAL_STATE.pagination);
|
|
51
|
+
const [globalFilter, setGlobalFilter] = (0, react_1.useState)(DEFAULT_INITIAL_STATE.globalFilter);
|
|
56
52
|
const [selectionState, setSelectionState] = (0, react_1.useState)((initialState === null || initialState === void 0 ? void 0 : initialState.selectionState) || { ids: [], type: 'include' });
|
|
57
|
-
const [
|
|
53
|
+
const [columnFilter, setColumnFilter] = (0, react_1.useState)({
|
|
58
54
|
filters: [],
|
|
59
55
|
logic: 'AND',
|
|
60
56
|
pendingFilters: [],
|
|
61
57
|
pendingLogic: 'AND'
|
|
62
58
|
});
|
|
63
|
-
const [expanded, setExpanded] = (0, react_1.useState)(
|
|
59
|
+
const [expanded, setExpanded] = (0, react_1.useState)(DEFAULT_INITIAL_STATE.expanded);
|
|
64
60
|
const [tableSize, setTableSize] = (0, react_1.useState)(initialTableSize);
|
|
65
|
-
const [columnOrder, setColumnOrder] = (0, react_1.useState)(
|
|
66
|
-
const [columnPinning, setColumnPinning] = (0, react_1.useState)(
|
|
61
|
+
const [columnOrder, setColumnOrder] = (0, react_1.useState)(DEFAULT_INITIAL_STATE.columnOrder);
|
|
62
|
+
const [columnPinning, setColumnPinning] = (0, react_1.useState)(DEFAULT_INITIAL_STATE.columnPinning);
|
|
63
|
+
const [serverData, setServerData] = (0, react_1.useState)(null);
|
|
64
|
+
const [serverTotal, setServerTotal] = (0, react_1.useState)(0);
|
|
65
|
+
const [exportController, setExportController] = (0, react_1.useState)(null);
|
|
66
|
+
const tableContainerRef = (0, react_1.useRef)(null);
|
|
67
67
|
const internalApiRef = (0, react_1.useRef)(null);
|
|
68
|
+
const initialStateConfig = (0, react_1.useMemo)(() => {
|
|
69
|
+
return Object.assign(Object.assign({}, DEFAULT_INITIAL_STATE), initialState);
|
|
70
|
+
}, [initialState]);
|
|
71
|
+
(0, react_1.useEffect)(() => {
|
|
72
|
+
setSorting(initialStateConfig.sorting);
|
|
73
|
+
setPagination(initialStateConfig.pagination);
|
|
74
|
+
setGlobalFilter(initialStateConfig.globalFilter);
|
|
75
|
+
setExpanded(initialStateConfig.expanded);
|
|
76
|
+
setColumnOrder(initialStateConfig.columnOrder);
|
|
77
|
+
setColumnPinning(initialStateConfig.columnPinning);
|
|
78
|
+
}, [initialStateConfig]);
|
|
68
79
|
const { debouncedFetch, isLoading: fetchLoading } = (0, debounced_fetch_utils_1.useDebouncedFetch)(onFetchData);
|
|
69
|
-
const
|
|
70
|
-
const
|
|
80
|
+
const tableData = (0, react_1.useMemo)(() => serverData ? serverData : data, [onFetchData, serverData, data]);
|
|
81
|
+
const tableTotalRow = (0, react_1.useMemo)(() => serverData ? serverTotal : totalRow, [onFetchData, serverTotal, totalRow]);
|
|
82
|
+
const tableLoading = (0, react_1.useMemo)(() => onFetchData ? (loading || fetchLoading) : loading, [onFetchData, loading, fetchLoading]);
|
|
83
|
+
const enhancedColumns = (0, react_1.useMemo)(() => {
|
|
84
|
+
let columnsMap = [...columns];
|
|
85
|
+
if (enableExpanding) {
|
|
86
|
+
const expandingColumnMap = (0, special_columns_utils_1.createExpandingColumn)(Object.assign({}, ((slotProps === null || slotProps === void 0 ? void 0 : slotProps.expandColumn) || {})));
|
|
87
|
+
columnsMap = [expandingColumnMap, ...columnsMap];
|
|
88
|
+
}
|
|
89
|
+
if (enableRowSelection) {
|
|
90
|
+
const selectionColumnMap = (0, special_columns_utils_1.createSelectionColumn)(Object.assign(Object.assign({}, ((slotProps === null || slotProps === void 0 ? void 0 : slotProps.selectionColumn) || {})), { multiSelect: enableMultiRowSelection }));
|
|
91
|
+
columnsMap = [selectionColumnMap, ...columnsMap];
|
|
92
|
+
}
|
|
93
|
+
return columnsMap;
|
|
94
|
+
}, [
|
|
95
|
+
columns,
|
|
96
|
+
slotProps === null || slotProps === void 0 ? void 0 : slotProps.selectionColumn,
|
|
97
|
+
slotProps === null || slotProps === void 0 ? void 0 : slotProps.expandColumn,
|
|
98
|
+
enableRowSelection,
|
|
99
|
+
enableExpanding,
|
|
100
|
+
enableMultiRowSelection,
|
|
101
|
+
]);
|
|
102
|
+
const isExporting = (0, react_1.useMemo)(() => exportController !== null, [exportController]);
|
|
103
|
+
const isSomeRowsSelected = (0, react_1.useMemo)(() => {
|
|
104
|
+
if (!enableBulkActions || !enableRowSelection)
|
|
105
|
+
return false;
|
|
106
|
+
if (selectionState.type === 'exclude') {
|
|
107
|
+
return selectionState.ids.length < tableTotalRow;
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
return selectionState.ids.length > 0;
|
|
111
|
+
}
|
|
112
|
+
}, [enableBulkActions, enableRowSelection, selectionState, tableTotalRow]);
|
|
113
|
+
const selectedRowCount = (0, react_1.useMemo)(() => {
|
|
114
|
+
if (!enableBulkActions || !enableRowSelection)
|
|
115
|
+
return 0;
|
|
116
|
+
if (selectionState.type === 'exclude') {
|
|
117
|
+
return tableTotalRow - selectionState.ids.length;
|
|
118
|
+
}
|
|
119
|
+
else {
|
|
120
|
+
return selectionState.ids.length;
|
|
121
|
+
}
|
|
122
|
+
}, [enableBulkActions, enableRowSelection, selectionState, tableTotalRow]);
|
|
123
|
+
const tableWidth = (0, react_1.useMemo)(() => {
|
|
124
|
+
if (fitToScreen) {
|
|
125
|
+
return '100%';
|
|
126
|
+
}
|
|
127
|
+
if (enableColumnResizing) {
|
|
128
|
+
return table.getCenterTotalSize();
|
|
129
|
+
}
|
|
130
|
+
return '100%';
|
|
131
|
+
}, [
|
|
132
|
+
fitToScreen,
|
|
133
|
+
enableColumnResizing,
|
|
134
|
+
]);
|
|
135
|
+
const tableStyle = (0, react_1.useMemo)(() => ({
|
|
136
|
+
width: tableWidth,
|
|
137
|
+
minWidth: '100%',
|
|
138
|
+
}), [tableWidth]);
|
|
71
139
|
const fetchData = (0, react_1.useCallback)((...args_1) => tslib_1.__awaiter(this, [...args_1], void 0, function* (overrides = {}) {
|
|
72
140
|
if (!onFetchData)
|
|
73
141
|
return;
|
|
74
142
|
const filters = Object.assign({ globalFilter,
|
|
75
143
|
pagination,
|
|
76
|
-
|
|
144
|
+
columnFilter,
|
|
77
145
|
sorting }, overrides);
|
|
78
146
|
const result = yield debouncedFetch(filters);
|
|
79
147
|
if ((result === null || result === void 0 ? void 0 : result.data) && (result === null || result === void 0 ? void 0 : result.total) !== undefined) {
|
|
@@ -84,59 +152,39 @@ exports.DataTable = (0, react_1.forwardRef)(function DataTable({ initialState, c
|
|
|
84
152
|
onFetchData,
|
|
85
153
|
globalFilter,
|
|
86
154
|
pagination,
|
|
87
|
-
|
|
155
|
+
columnFilter,
|
|
88
156
|
sorting,
|
|
89
157
|
debouncedFetch,
|
|
90
158
|
]);
|
|
91
159
|
const fetchDataRef = (0, react_1.useRef)(fetchData);
|
|
92
160
|
fetchDataRef.current = fetchData;
|
|
93
|
-
const tableData = (0, react_1.useMemo)(() => onFetchData ? serverData : data, [onFetchData, serverData, data]);
|
|
94
|
-
const tableTotalRow = (0, react_1.useMemo)(() => onFetchData ? serverTotal : totalRow, [onFetchData, serverTotal, totalRow]);
|
|
95
|
-
const tableLoading = (0, react_1.useMemo)(() => onFetchData ? (loading || fetchLoading) : loading, [onFetchData, loading, fetchLoading]);
|
|
96
161
|
const handleSelectionStateChange = (0, react_1.useCallback)((updaterOrValue) => {
|
|
97
162
|
setSelectionState((prevState) => {
|
|
98
163
|
const newSelectionState = typeof updaterOrValue === 'function'
|
|
99
164
|
? updaterOrValue(prevState)
|
|
100
165
|
: updaterOrValue;
|
|
101
|
-
|
|
102
|
-
onSelectionChange
|
|
103
|
-
|
|
166
|
+
setTimeout(() => {
|
|
167
|
+
if (onSelectionChange) {
|
|
168
|
+
onSelectionChange(newSelectionState);
|
|
169
|
+
}
|
|
170
|
+
}, 0);
|
|
104
171
|
return newSelectionState;
|
|
105
172
|
});
|
|
106
173
|
}, [onSelectionChange]);
|
|
107
174
|
const handleColumnFilterStateChange = (0, react_1.useCallback)((filterState) => {
|
|
108
175
|
if (filterState && typeof filterState === 'object') {
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
onColumnFiltersChange
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
onColumnFiltersChange,
|
|
116
|
-
]);
|
|
117
|
-
const enhancedColumns = (0, react_1.useMemo)(() => {
|
|
118
|
-
let columnsMap = [...columns];
|
|
119
|
-
if (enableExpanding) {
|
|
120
|
-
const expandingColumnMap = (0, special_columns_utils_1.createExpandingColumn)(Object.assign({}, ((slotProps === null || slotProps === void 0 ? void 0 : slotProps.expandColumn) || {})));
|
|
121
|
-
columnsMap = [expandingColumnMap, ...columnsMap];
|
|
122
|
-
}
|
|
123
|
-
if (enableRowSelection) {
|
|
124
|
-
const selectionColumnMap = (0, special_columns_utils_1.createSelectionColumn)(Object.assign(Object.assign({}, ((slotProps === null || slotProps === void 0 ? void 0 : slotProps.selectionColumn) || {})), { multiSelect: enableMultiRowSelection }));
|
|
125
|
-
columnsMap = [selectionColumnMap, ...columnsMap];
|
|
176
|
+
setColumnFilter(filterState);
|
|
177
|
+
setTimeout(() => {
|
|
178
|
+
if (onColumnFiltersChange) {
|
|
179
|
+
onColumnFiltersChange(filterState);
|
|
180
|
+
}
|
|
181
|
+
}, 0);
|
|
126
182
|
}
|
|
127
|
-
|
|
128
|
-
}, [
|
|
129
|
-
columns,
|
|
130
|
-
slotProps === null || slotProps === void 0 ? void 0 : slotProps.selectionColumn,
|
|
131
|
-
slotProps === null || slotProps === void 0 ? void 0 : slotProps.expandColumn,
|
|
132
|
-
enableRowSelection,
|
|
133
|
-
enableExpanding,
|
|
134
|
-
enableMultiRowSelection,
|
|
135
|
-
]);
|
|
183
|
+
}, [onColumnFiltersChange]);
|
|
136
184
|
const notifyDataStateChange = (0, react_1.useCallback)((overrides = {}) => {
|
|
137
185
|
if (onDataStateChange) {
|
|
138
186
|
const currentState = Object.assign({ globalFilter,
|
|
139
|
-
|
|
187
|
+
columnFilter,
|
|
140
188
|
sorting,
|
|
141
189
|
pagination,
|
|
142
190
|
columnOrder,
|
|
@@ -146,7 +194,7 @@ exports.DataTable = (0, react_1.forwardRef)(function DataTable({ initialState, c
|
|
|
146
194
|
}, [
|
|
147
195
|
onDataStateChange,
|
|
148
196
|
globalFilter,
|
|
149
|
-
|
|
197
|
+
columnFilter,
|
|
150
198
|
sorting,
|
|
151
199
|
pagination,
|
|
152
200
|
columnOrder,
|
|
@@ -171,7 +219,9 @@ exports.DataTable = (0, react_1.forwardRef)(function DataTable({ initialState, c
|
|
|
171
219
|
});
|
|
172
220
|
}
|
|
173
221
|
else if (onDataStateChange) {
|
|
174
|
-
|
|
222
|
+
setTimeout(() => {
|
|
223
|
+
stateChangeRef.current({ sorting: newSorting });
|
|
224
|
+
}, 0);
|
|
175
225
|
}
|
|
176
226
|
}, [
|
|
177
227
|
sorting,
|
|
@@ -219,15 +269,19 @@ exports.DataTable = (0, react_1.forwardRef)(function DataTable({ initialState, c
|
|
|
219
269
|
: updaterOrValue;
|
|
220
270
|
setGlobalFilter(newFilter);
|
|
221
271
|
if (isServerMode || isServerFiltering) {
|
|
222
|
-
|
|
223
|
-
|
|
272
|
+
setTimeout(() => {
|
|
273
|
+
stateChangeRef.current({ globalFilter: newFilter });
|
|
274
|
+
fetchDataRef === null || fetchDataRef === void 0 ? void 0 : fetchDataRef.current({ globalFilter: newFilter });
|
|
275
|
+
}, 0);
|
|
224
276
|
}
|
|
225
277
|
else if (onDataStateChange) {
|
|
226
|
-
|
|
278
|
+
setTimeout(() => {
|
|
279
|
+
stateChangeRef.current({ globalFilter: newFilter });
|
|
280
|
+
}, 0);
|
|
227
281
|
}
|
|
228
282
|
}, [globalFilter, isServerMode, isServerFiltering, onDataStateChange]);
|
|
229
|
-
const
|
|
230
|
-
const currentState =
|
|
283
|
+
const onColumnFilterChangeHandler = (0, react_1.useCallback)((updater) => {
|
|
284
|
+
const currentState = columnFilter;
|
|
231
285
|
const newState = typeof updater === 'function'
|
|
232
286
|
? updater(currentState)
|
|
233
287
|
: updater;
|
|
@@ -238,8 +292,8 @@ exports.DataTable = (0, react_1.forwardRef)(function DataTable({ initialState, c
|
|
|
238
292
|
pendingLogic: newState.pendingLogic
|
|
239
293
|
};
|
|
240
294
|
handleColumnFilterStateChange(legacyFilterState);
|
|
241
|
-
}, [
|
|
242
|
-
const
|
|
295
|
+
}, [columnFilter, handleColumnFilterStateChange]);
|
|
296
|
+
const onColumnFilterApplyHandler = (0, react_1.useCallback)((appliedState) => {
|
|
243
297
|
if (isServerFiltering) {
|
|
244
298
|
const serverFilterState = {
|
|
245
299
|
filters: appliedState.filters,
|
|
@@ -248,23 +302,26 @@ exports.DataTable = (0, react_1.forwardRef)(function DataTable({ initialState, c
|
|
|
248
302
|
pendingLogic: appliedState.pendingLogic,
|
|
249
303
|
};
|
|
250
304
|
stateChangeRef.current({
|
|
251
|
-
|
|
305
|
+
columnFilter: serverFilterState,
|
|
252
306
|
});
|
|
253
307
|
fetchDataRef === null || fetchDataRef === void 0 ? void 0 : fetchDataRef.current({
|
|
254
|
-
|
|
308
|
+
columnFilter: serverFilterState,
|
|
255
309
|
});
|
|
256
310
|
}
|
|
257
311
|
}, [isServerFiltering]);
|
|
258
312
|
const table = (0, react_table_1.useReactTable)({
|
|
259
|
-
_features: [
|
|
313
|
+
_features: [column_filter_feature_1.ColumnFilterFeature, features_1.SelectionFeature],
|
|
260
314
|
data: tableData,
|
|
261
315
|
columns: enhancedColumns,
|
|
262
316
|
initialState: Object.assign({}, initialStateConfig),
|
|
263
|
-
state: Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({ sorting }, (enablePagination ? { pagination } : {})), (enableGlobalFilter ? { globalFilter } : {})), (enableExpanding ? { expanded } : {})), (enableColumnDragging ? { columnOrder } : {})), (enableColumnPinning ? { columnPinning } : {})), (enableColumnFilter ? {
|
|
317
|
+
state: Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({ sorting }, (enablePagination ? { pagination } : {})), (enableGlobalFilter ? { globalFilter } : {})), (enableExpanding ? { expanded } : {})), (enableColumnDragging ? { columnOrder } : {})), (enableColumnPinning ? { columnPinning } : {})), (enableColumnFilter ? { columnFilter } : {})), (enableRowSelection ? { selectionState } : {})),
|
|
264
318
|
selectMode: selectMode,
|
|
265
|
-
|
|
319
|
+
enableAdvanceSelection: !!enableRowSelection,
|
|
266
320
|
isRowSelectable: isRowSelectable,
|
|
267
321
|
onSelectionStateChange: enableRowSelection ? handleSelectionStateChange : undefined,
|
|
322
|
+
enableAdvanceColumnFilter: enableColumnFilter,
|
|
323
|
+
onColumnFilterChange: onColumnFilterChangeHandler,
|
|
324
|
+
onColumnFilterApply: onColumnFilterApplyHandler,
|
|
268
325
|
onSortingChange: enableSorting ? handleSortingChange : undefined,
|
|
269
326
|
onPaginationChange: enablePagination ? handlePaginationChange : undefined,
|
|
270
327
|
onRowSelectionChange: enableRowSelection ? handleSelectionStateChange : undefined,
|
|
@@ -272,11 +329,9 @@ exports.DataTable = (0, react_1.forwardRef)(function DataTable({ initialState, c
|
|
|
272
329
|
onExpandedChange: enableExpanding ? setExpanded : undefined,
|
|
273
330
|
onColumnOrderChange: enableColumnDragging ? handleColumnOrderChange : undefined,
|
|
274
331
|
onColumnPinningChange: enableColumnPinning ? handleColumnPinningChange : undefined,
|
|
275
|
-
onCustomColumnFilterChange: onCustomColumnFilterChangeHandler,
|
|
276
|
-
onCustomColumnFilterApply: onCustomColumnFilterApplyHandler,
|
|
277
332
|
getCoreRowModel: (0, react_table_1.getCoreRowModel)(),
|
|
278
333
|
getSortedRowModel: (enableSorting && !isServerSorting) ? (0, react_table_1.getSortedRowModel)() : undefined,
|
|
279
|
-
getFilteredRowModel: (enableColumnFilter && !isServerFiltering) ? (0,
|
|
334
|
+
getFilteredRowModel: (enableColumnFilter && !isServerFiltering) ? (0, column_filter_feature_1.getCombinedFilteredRowModel)() : undefined,
|
|
280
335
|
getPaginationRowModel: (enablePagination && !isServerPagination) ? (0, react_table_1.getPaginationRowModel)() : undefined,
|
|
281
336
|
enableSorting: enableSorting,
|
|
282
337
|
manualSorting: isServerSorting,
|
|
@@ -299,23 +354,6 @@ exports.DataTable = (0, react_1.forwardRef)(function DataTable({ initialState, c
|
|
|
299
354
|
overscan: 10,
|
|
300
355
|
enabled: enableVirtualization && !enablePagination && rows.length > 0,
|
|
301
356
|
});
|
|
302
|
-
const tableWidth = (0, react_1.useMemo)(() => {
|
|
303
|
-
if (fitToScreen) {
|
|
304
|
-
return '100%';
|
|
305
|
-
}
|
|
306
|
-
if (enableColumnResizing) {
|
|
307
|
-
return table.getCenterTotalSize();
|
|
308
|
-
}
|
|
309
|
-
return '100%';
|
|
310
|
-
}, [
|
|
311
|
-
table,
|
|
312
|
-
enableColumnResizing,
|
|
313
|
-
fitToScreen,
|
|
314
|
-
]);
|
|
315
|
-
const tableStyle = (0, react_1.useMemo)(() => ({
|
|
316
|
-
width: tableWidth,
|
|
317
|
-
minWidth: '100%',
|
|
318
|
-
}), [tableWidth]);
|
|
319
357
|
const handleColumnReorder = (0, react_1.useCallback)((draggedColumnId, targetColumnId) => {
|
|
320
358
|
const currentOrder = columnOrder.length > 0 ? columnOrder : enhancedColumns.map((col, index) => {
|
|
321
359
|
if (col.id)
|
|
@@ -339,7 +377,7 @@ exports.DataTable = (0, react_1.forwardRef)(function DataTable({ initialState, c
|
|
|
339
377
|
if (initialLoadData && onFetchData) {
|
|
340
378
|
fetchDataRef.current();
|
|
341
379
|
}
|
|
342
|
-
}, [initialLoadData]);
|
|
380
|
+
}, [initialLoadData, onFetchData]);
|
|
343
381
|
(0, react_1.useEffect)(() => {
|
|
344
382
|
if (enableColumnDragging && columnOrder.length === 0) {
|
|
345
383
|
const initialOrder = enhancedColumns.map((col, index) => {
|
|
@@ -353,11 +391,7 @@ exports.DataTable = (0, react_1.forwardRef)(function DataTable({ initialState, c
|
|
|
353
391
|
});
|
|
354
392
|
setColumnOrder(initialOrder);
|
|
355
393
|
}
|
|
356
|
-
}, [
|
|
357
|
-
enableColumnDragging,
|
|
358
|
-
enhancedColumns,
|
|
359
|
-
columnOrder.length,
|
|
360
|
-
]);
|
|
394
|
+
}, [enableColumnDragging, enhancedColumns, columnOrder.length]);
|
|
361
395
|
const LoadingRowSlot = (0, slot_helpers_1.getSlotComponent)(slots, 'loadingRow', rows_1.LoadingRows);
|
|
362
396
|
const EmptyRowSlot = (0, slot_helpers_1.getSlotComponent)(slots, 'emptyRow', rows_1.EmptyDataRow);
|
|
363
397
|
const renderTableRows = (0, react_1.useCallback)(() => {
|
|
@@ -406,8 +440,6 @@ exports.DataTable = (0, react_1.forwardRef)(function DataTable({ initialState, c
|
|
|
406
440
|
enableStickyHeaderOrFooter,
|
|
407
441
|
slots,
|
|
408
442
|
]);
|
|
409
|
-
const [exportController, setExportController] = (0, react_1.useState)(null);
|
|
410
|
-
const isExporting = (0, react_1.useMemo)(() => exportController !== null, [exportController]);
|
|
411
443
|
const handleCancelExport = (0, react_1.useCallback)(() => {
|
|
412
444
|
if (exportController) {
|
|
413
445
|
exportController.abort();
|
|
@@ -419,26 +451,16 @@ exports.DataTable = (0, react_1.forwardRef)(function DataTable({ initialState, c
|
|
|
419
451
|
}, [exportController, onExportCancel]);
|
|
420
452
|
(0, use_data_table_api_1.useDataTableApi)({
|
|
421
453
|
table,
|
|
422
|
-
data: tableData,
|
|
423
454
|
idKey,
|
|
424
|
-
globalFilter,
|
|
425
|
-
customColumnsFilter,
|
|
426
|
-
sorting,
|
|
427
|
-
pagination,
|
|
428
|
-
columnOrder,
|
|
429
|
-
columnPinning,
|
|
430
455
|
enhancedColumns,
|
|
431
456
|
enablePagination,
|
|
432
457
|
enableColumnPinning,
|
|
433
|
-
|
|
434
|
-
initialPageSize: pagination.pageSize,
|
|
435
|
-
pageSize: pagination.pageSize,
|
|
458
|
+
initialStateConfig,
|
|
436
459
|
selectMode,
|
|
437
460
|
onSelectionChange: handleSelectionStateChange,
|
|
438
461
|
handleColumnFilterStateChange,
|
|
439
462
|
onDataStateChange,
|
|
440
|
-
onFetchData:
|
|
441
|
-
onDataChange,
|
|
463
|
+
onFetchData: fetchData,
|
|
442
464
|
exportFilename,
|
|
443
465
|
onExportProgress,
|
|
444
466
|
onExportComplete,
|
|
@@ -447,29 +469,10 @@ exports.DataTable = (0, react_1.forwardRef)(function DataTable({ initialState, c
|
|
|
447
469
|
exportController,
|
|
448
470
|
setExportController,
|
|
449
471
|
isExporting,
|
|
472
|
+
onDataChange: setServerData,
|
|
450
473
|
dataMode,
|
|
451
474
|
}, internalApiRef);
|
|
452
475
|
(0, react_1.useImperativeHandle)(ref, () => internalApiRef.current, []);
|
|
453
|
-
const isSomeRowsSelected = (0, react_1.useMemo)(() => {
|
|
454
|
-
if (!enableBulkActions || !enableRowSelection)
|
|
455
|
-
return false;
|
|
456
|
-
if (selectionState.type === 'exclude') {
|
|
457
|
-
return selectionState.ids.length < tableTotalRow;
|
|
458
|
-
}
|
|
459
|
-
else {
|
|
460
|
-
return selectionState.ids.length > 0;
|
|
461
|
-
}
|
|
462
|
-
}, [enableBulkActions, enableRowSelection, selectionState, tableTotalRow]);
|
|
463
|
-
const selectedRowCount = (0, react_1.useMemo)(() => {
|
|
464
|
-
if (!enableBulkActions || !enableRowSelection)
|
|
465
|
-
return 0;
|
|
466
|
-
if (selectionState.type === 'exclude') {
|
|
467
|
-
return tableTotalRow - selectionState.ids.length;
|
|
468
|
-
}
|
|
469
|
-
else {
|
|
470
|
-
return selectionState.ids.length;
|
|
471
|
-
}
|
|
472
|
-
}, [enableBulkActions, enableRowSelection, selectionState, tableTotalRow]);
|
|
473
476
|
const RootSlot = (0, slot_helpers_1.getSlotComponent)(slots, 'root', material_1.Box);
|
|
474
477
|
const ToolbarSlot = (0, slot_helpers_1.getSlotComponent)(slots, 'toolbar', toolbar_1.DataTableToolbar);
|
|
475
478
|
const BulkActionsSlot = (0, slot_helpers_1.getSlotComponent)(slots, 'bulkActionsToolbar', toolbar_1.BulkActionsToolbar);
|
|
@@ -480,7 +483,7 @@ exports.DataTable = (0, react_1.forwardRef)(function DataTable({ initialState, c
|
|
|
480
483
|
const PaginationSlot = (0, slot_helpers_1.getSlotComponent)(slots, 'pagination', pagination_1.DataTablePagination);
|
|
481
484
|
return ((0, jsx_runtime_1.jsx)(data_table_context_1.DataTableProvider, { table: table, apiRef: internalApiRef, dataMode: dataMode, tableSize: tableSize, onTableSizeChange: (size) => {
|
|
482
485
|
setTableSize(size);
|
|
483
|
-
},
|
|
486
|
+
}, columnFilter: columnFilter, onChangeColumnFilter: handleColumnFilterStateChange, slots: slots, slotProps: slotProps, isExporting: isExporting, exportController: exportController, onCancelExport: handleCancelExport, exportFilename: exportFilename, onExportProgress: onExportProgress, onExportComplete: onExportComplete, onExportError: onExportError, onServerExport: onServerExport, children: (0, jsx_runtime_1.jsxs)(RootSlot, Object.assign({}, slotProps === null || slotProps === void 0 ? void 0 : slotProps.root, { children: [(enableGlobalFilter || extraFilter) ? ((0, jsx_runtime_1.jsx)(ToolbarSlot, Object.assign({ extraFilter: extraFilter, enableGlobalFilter: enableGlobalFilter, enableColumnVisibility: enableColumnVisibility, enableColumnFilter: enableColumnFilter, enableExport: enableExport, enableReset: enableReset, enableTableSizeControl: enableTableSizeControl, enableColumnPinning: enableColumnPinning }, slotProps === null || slotProps === void 0 ? void 0 : slotProps.toolbar))) : null, enableBulkActions && enableRowSelection && isSomeRowsSelected ? ((0, jsx_runtime_1.jsx)(BulkActionsSlot, Object.assign({ selectionState: selectionState, selectedRowCount: selectedRowCount, bulkActions: bulkActions, sx: {
|
|
484
487
|
position: 'relative',
|
|
485
488
|
zIndex: 2,
|
|
486
489
|
} }, slotProps === null || slotProps === void 0 ? void 0 : slotProps.bulkActionsToolbar))) : null, (0, jsx_runtime_1.jsx)(TableContainerSlot, Object.assign({ component: material_1.Paper, ref: tableContainerRef, sx: Object.assign(Object.assign(Object.assign({ width: '100%', overflowX: 'auto' }, (enableStickyHeaderOrFooter && {
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { Row, SortingState, ColumnResizeMode, ColumnPinningState, RowData } from '@tanstack/react-table';
|
|
2
2
|
import { ReactNode } from 'react';
|
|
3
|
-
import type {
|
|
3
|
+
import type { ColumnFilterState, TableFilters, TableState } from '../../types';
|
|
4
4
|
import { DataTableColumn } from '../../types';
|
|
5
5
|
import { DataTableSlots, PartialSlotProps } from '../../types/slots.types';
|
|
6
6
|
import { DataTableSize } from '../../utils/table-helpers';
|
|
7
|
-
import { SelectionState } from '../../features
|
|
7
|
+
import { SelectionState } from '../../features';
|
|
8
8
|
export type SelectMode = 'page' | 'all';
|
|
9
9
|
declare module '@tanstack/table-core' {
|
|
10
10
|
interface ColumnMeta<TData extends RowData, TValue> {
|
|
@@ -27,9 +27,9 @@ export interface DataTableProps<T> {
|
|
|
27
27
|
}>;
|
|
28
28
|
exportFilename?: string;
|
|
29
29
|
onExportProgress?: (progress: {
|
|
30
|
-
processedRows
|
|
31
|
-
totalRows
|
|
32
|
-
percentage
|
|
30
|
+
processedRows?: number;
|
|
31
|
+
totalRows?: number;
|
|
32
|
+
percentage?: number;
|
|
33
33
|
}) => void;
|
|
34
34
|
onExportComplete?: (result: {
|
|
35
35
|
success: boolean;
|
|
@@ -90,23 +90,23 @@ export interface DataTableProps<T> {
|
|
|
90
90
|
loading?: boolean;
|
|
91
91
|
emptyMessage?: string;
|
|
92
92
|
skeletonRows?: number;
|
|
93
|
-
onColumnFiltersChange?: (filterState:
|
|
93
|
+
onColumnFiltersChange?: (filterState: ColumnFilterState) => void;
|
|
94
94
|
onDataChange?: (data: T[]) => void;
|
|
95
95
|
selectionColumn?: {
|
|
96
96
|
width?: number;
|
|
97
97
|
pinLeft?: boolean;
|
|
98
|
-
customColumn?: DataTableColumn<
|
|
98
|
+
customColumn?: DataTableColumn<T>;
|
|
99
99
|
id?: string;
|
|
100
100
|
};
|
|
101
101
|
actionColumn?: {
|
|
102
102
|
pinRight?: boolean;
|
|
103
|
-
customColumn?: DataTableColumn<
|
|
103
|
+
customColumn?: DataTableColumn<T>;
|
|
104
104
|
id?: string;
|
|
105
105
|
};
|
|
106
106
|
expandingColumn?: {
|
|
107
107
|
width?: number;
|
|
108
108
|
pinLeft?: boolean;
|
|
109
|
-
customColumn?: DataTableColumn<
|
|
109
|
+
customColumn?: DataTableColumn<T>;
|
|
110
110
|
id?: string;
|
|
111
111
|
};
|
|
112
112
|
slots?: Partial<DataTableSlots<T>>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ReactNode } from 'react';
|
|
2
|
-
import { SelectionState } from '../../features
|
|
2
|
+
import { SelectionState } from '../../features';
|
|
3
3
|
export interface BulkActionsToolbarProps<T = any> {
|
|
4
4
|
selectionState: SelectionState;
|
|
5
5
|
selectedRowCount: number;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function ColumnFilterControl(): import("react/jsx-runtime").JSX.Element;
|