@ackplus/react-tanstack-data-table 1.0.19-beta-0.6
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 +599 -0
- package/index.d.ts.map +1 -0
- package/index.js +42 -0
- package/lib/components/droupdown/menu-dropdown.d.ts.map +1 -0
- package/lib/components/droupdown/menu-dropdown.js +47 -0
- package/lib/components/export-progress-dialog.d.ts.map +1 -0
- package/lib/components/export-progress-dialog.js +30 -0
- package/lib/components/filters/filter-value-input.d.ts.map +1 -0
- package/lib/components/filters/filter-value-input.js +64 -0
- package/lib/components/filters/index.d.ts.map +1 -0
- package/lib/components/filters/index.js +125 -0
- package/lib/components/headers/draggable-header.d.ts.map +1 -0
- package/lib/components/headers/draggable-header.js +226 -0
- package/lib/components/headers/index.d.ts.map +1 -0
- package/lib/components/headers/index.js +5 -0
- package/lib/components/headers/table-header.d.ts.map +1 -0
- package/lib/components/headers/table-header.js +59 -0
- package/lib/components/index.d.ts.map +1 -0
- package/lib/components/index.js +18 -0
- package/lib/components/pagination/data-table-pagination.d.ts.map +1 -0
- package/lib/components/pagination/data-table-pagination.js +24 -0
- package/lib/components/pagination/index.d.ts.map +1 -0
- package/lib/components/pagination/index.js +4 -0
- package/lib/components/rows/data-table-row.d.ts.map +1 -0
- package/lib/components/rows/data-table-row.js +42 -0
- package/lib/components/rows/empty-data-row.d.ts.map +1 -0
- package/lib/components/rows/empty-data-row.js +8 -0
- package/lib/components/rows/index.d.ts.map +1 -0
- package/lib/components/rows/index.js +6 -0
- package/lib/components/rows/loading-rows.d.ts.map +1 -0
- package/lib/components/rows/loading-rows.js +46 -0
- package/lib/components/table/data-table.d.ts.map +1 -0
- package/lib/components/table/data-table.js +663 -0
- package/lib/components/table/data-table.types.d.ts.map +1 -0
- package/lib/components/table/data-table.types.js +6 -0
- package/lib/components/table/index.d.ts.map +1 -0
- package/lib/components/table/index.js +5 -0
- package/lib/components/toolbar/bulk-actions-toolbar.d.ts.map +1 -0
- package/lib/components/toolbar/bulk-actions-toolbar.js +31 -0
- package/lib/components/toolbar/column-custom-filter-control.d.ts.map +1 -0
- package/lib/components/toolbar/column-custom-filter-control.js +149 -0
- package/lib/components/toolbar/column-custum-filter-control.d.ts.map +1 -0
- package/lib/components/toolbar/column-custum-filter-control.js +150 -0
- package/lib/components/toolbar/column-pinning-control.d.ts.map +1 -0
- package/lib/components/toolbar/column-pinning-control.js +103 -0
- package/lib/components/toolbar/column-reset-control.d.ts.map +1 -0
- package/lib/components/toolbar/column-reset-control.js +13 -0
- package/lib/components/toolbar/column-visibility-control.d.ts.map +1 -0
- package/lib/components/toolbar/column-visibility-control.js +27 -0
- package/lib/components/toolbar/data-table-toolbar.d.ts.map +1 -0
- package/lib/components/toolbar/data-table-toolbar.js +23 -0
- package/lib/components/toolbar/index.d.ts.map +1 -0
- package/lib/components/toolbar/index.js +13 -0
- package/lib/components/toolbar/table-export-control.d.ts.map +1 -0
- package/lib/components/toolbar/table-export-control.js +94 -0
- package/lib/components/toolbar/table-search-control.d.ts.map +1 -0
- package/lib/components/toolbar/table-search-control.js +61 -0
- package/lib/components/toolbar/table-size-control.d.ts.map +1 -0
- package/lib/components/toolbar/table-size-control.js +33 -0
- package/lib/contexts/data-table-context.d.ts.map +1 -0
- package/lib/contexts/data-table-context.js +50 -0
- package/lib/examples/advanced-features-example.d.ts.map +1 -0
- package/lib/examples/advanced-features-example.js +282 -0
- package/lib/examples/basic-example.d.ts.map +1 -0
- package/lib/examples/basic-example.js +323 -0
- package/lib/examples/bulk-actions-test.d.ts.map +1 -0
- package/lib/examples/bulk-actions-test.js +47 -0
- package/lib/examples/crud-api-example.d.ts.map +1 -0
- package/lib/examples/crud-api-example.js +321 -0
- package/lib/examples/custom-column-filter-example.d.ts.map +1 -0
- package/lib/examples/custom-column-filter-example.js +60 -0
- package/lib/examples/custom-selection-example.d.ts.map +1 -0
- package/lib/examples/custom-selection-example.js +184 -0
- package/lib/examples/export-callbacks-example.d.ts.map +1 -0
- package/lib/examples/export-callbacks-example.js +155 -0
- package/lib/examples/improved-export-example.d.ts.map +1 -0
- package/lib/examples/improved-export-example.js +153 -0
- package/lib/examples/improved-server-selection-example.d.ts.map +1 -0
- package/lib/examples/improved-server-selection-example.js +118 -0
- package/lib/examples/index.d.ts.map +1 -0
- package/lib/examples/index.js +5 -0
- package/lib/examples/selection-test-example.d.ts.map +1 -0
- package/lib/examples/selection-test-example.js +111 -0
- package/lib/examples/simple-local-example.d.ts.map +1 -0
- package/lib/examples/simple-local-example.js +101 -0
- package/lib/examples/simple-server-selection-example.d.ts.map +1 -0
- package/lib/examples/simple-server-selection-example.js +178 -0
- package/lib/examples/virtualized-example.d.ts.map +1 -0
- package/lib/examples/virtualized-example.js +119 -0
- package/lib/features/custom-column-filter.feature.d.ts.map +1 -0
- package/lib/features/custom-column-filter.feature.js +306 -0
- package/lib/features/custom-selection.feature.d.ts.map +1 -0
- package/lib/features/custom-selection.feature.js +224 -0
- package/lib/features/index.d.ts.map +1 -0
- package/lib/features/index.js +9 -0
- package/lib/hooks/index.d.ts.map +1 -0
- package/lib/hooks/index.js +6 -0
- package/lib/hooks/use-data-table-api.d.ts.map +1 -0
- package/lib/hooks/use-data-table-api.js +673 -0
- package/lib/hooks/use-table-state.d.ts.map +1 -0
- package/lib/hooks/use-table-state.js +74 -0
- package/lib/icons/add-icon.d.ts.map +1 -0
- package/lib/icons/add-icon.js +5 -0
- package/lib/icons/csv-icon.d.ts.map +1 -0
- package/lib/icons/csv-icon.js +5 -0
- package/lib/icons/delete-icon.d.ts.map +1 -0
- package/lib/icons/delete-icon.js +5 -0
- package/lib/icons/excel-icon.d.ts.map +1 -0
- package/lib/icons/excel-icon.js +5 -0
- package/lib/icons/index.d.ts.map +1 -0
- package/lib/icons/index.js +7 -0
- package/lib/icons/unpin-icon.d.ts.map +1 -0
- package/lib/icons/unpin-icon.js +5 -0
- package/lib/icons/view-comfortable-icon.d.ts.map +1 -0
- package/lib/icons/view-comfortable-icon.js +5 -0
- package/lib/icons/view-compact-icon.d.ts.map +1 -0
- package/lib/icons/view-compact-icon.js +5 -0
- package/lib/types/column.types.d.ts.map +1 -0
- package/lib/types/column.types.js +2 -0
- package/lib/types/data-table-api.d.ts.map +1 -0
- package/lib/types/data-table-api.js +1 -0
- package/lib/types/export.types.d.ts.map +1 -0
- package/lib/types/export.types.js +5 -0
- package/lib/types/hooks.types.d.ts.map +1 -0
- package/lib/types/hooks.types.js +1 -0
- package/lib/types/index.d.ts.map +1 -0
- package/lib/types/index.js +14 -0
- package/lib/types/slots.types.d.ts.map +1 -0
- package/lib/types/slots.types.js +1 -0
- package/lib/types/table.types.d.ts.map +1 -0
- package/lib/types/table.types.js +1 -0
- package/lib/utils/column-helpers.d.ts.map +1 -0
- package/lib/utils/column-helpers.js +46 -0
- package/lib/utils/debounced-fetch.utils.d.ts.map +1 -0
- package/lib/utils/debounced-fetch.utils.js +51 -0
- package/lib/utils/export-utils.d.ts.map +1 -0
- package/lib/utils/export-utils.js +181 -0
- package/lib/utils/index.d.ts.map +1 -0
- package/lib/utils/index.js +17 -0
- package/lib/utils/selection-helpers.d.ts.map +1 -0
- package/lib/utils/selection-helpers.js +162 -0
- package/lib/utils/slot-helpers.d.ts.map +1 -0
- package/lib/utils/slot-helpers.js +27 -0
- package/lib/utils/special-columns.utils.d.ts.map +1 -0
- package/lib/utils/special-columns.utils.js +77 -0
- package/lib/utils/styling-helpers.d.ts.map +1 -0
- package/lib/utils/styling-helpers.js +97 -0
- package/lib/utils/table-helpers.d.ts.map +1 -0
- package/lib/utils/table-helpers.js +72 -0
- package/lib/utils/value-helpers.d.ts.map +1 -0
- package/lib/utils/value-helpers.js +48 -0
- package/package.json +57 -0
- package/tsconfig.lib.tsbuildinfo +1 -0
|
@@ -0,0 +1,663 @@
|
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* Main DataTable Component
|
|
4
|
+
*
|
|
5
|
+
* A comprehensive, highly customizable data table component built with:
|
|
6
|
+
* - Material-UI (MUI) for styling
|
|
7
|
+
* - TanStack Table for table logic
|
|
8
|
+
* - TypeScript for type safety
|
|
9
|
+
*/
|
|
10
|
+
import { Table, TableContainer, TableBody, Box, Paper, } from '@mui/material';
|
|
11
|
+
import { getCoreRowModel, useReactTable, getSortedRowModel, getPaginationRowModel, } from '@tanstack/react-table';
|
|
12
|
+
// Import custom features
|
|
13
|
+
import { CustomColumnFilterFeature, getCombinedFilteredRowModel } from '../../features/custom-column-filter.feature';
|
|
14
|
+
import { CustomSelectionFeature } from '../../features';
|
|
15
|
+
import { useVirtualizer } from '@tanstack/react-virtual';
|
|
16
|
+
import { useState, useCallback, useMemo, useRef, useEffect, forwardRef, useImperativeHandle } from 'react';
|
|
17
|
+
// Import from new organized structure
|
|
18
|
+
import { DataTableProvider } from '../../contexts/data-table-context';
|
|
19
|
+
import { useDataTableApi } from '../../hooks/use-data-table-api';
|
|
20
|
+
import { generateRowId } from '../../utils';
|
|
21
|
+
import { useDebouncedFetch } from '../../utils/debounced-fetch.utils';
|
|
22
|
+
import { getSlotComponent } from '../../utils/slot-helpers';
|
|
23
|
+
import { TableHeader } from '../headers';
|
|
24
|
+
import { DataTablePagination } from '../pagination';
|
|
25
|
+
import { DataTableRow, LoadingRows, EmptyDataRow } from '../rows';
|
|
26
|
+
import { DataTableToolbar, BulkActionsToolbar } from '../toolbar';
|
|
27
|
+
import { createExpandingColumn, createSelectionColumn, } from '../../utils/special-columns.utils';
|
|
28
|
+
// Static default initial state - defined outside component
|
|
29
|
+
const DEFAULT_INITIAL_STATE = {
|
|
30
|
+
sorting: [],
|
|
31
|
+
pagination: {
|
|
32
|
+
pageIndex: 0,
|
|
33
|
+
pageSize: 10,
|
|
34
|
+
},
|
|
35
|
+
rowSelection: {},
|
|
36
|
+
globalFilter: '',
|
|
37
|
+
expanded: {},
|
|
38
|
+
columnOrder: [],
|
|
39
|
+
columnPinning: {
|
|
40
|
+
left: [],
|
|
41
|
+
right: [],
|
|
42
|
+
},
|
|
43
|
+
customColumnFilter: {
|
|
44
|
+
filters: [],
|
|
45
|
+
logic: 'AND',
|
|
46
|
+
pendingFilters: [],
|
|
47
|
+
pendingLogic: 'AND',
|
|
48
|
+
},
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* Main DataTable component with all features
|
|
52
|
+
*/
|
|
53
|
+
export const DataTable = forwardRef(function DataTable({ initialState, columns, data = [], totalRow = 0, idKey = 'id', extraFilter = null, footerFilter = null,
|
|
54
|
+
// Data management mode (MUI DataGrid style)
|
|
55
|
+
dataMode = 'client', initialLoadData = true, onFetchData, onDataStateChange,
|
|
56
|
+
// Selection props
|
|
57
|
+
enableRowSelection = false, enableMultiRowSelection = true, selectMode = 'page', isRowSelectable, onSelectionChange,
|
|
58
|
+
// Bulk action props
|
|
59
|
+
enableBulkActions = false, bulkActions = null,
|
|
60
|
+
// Column resizing props
|
|
61
|
+
enableColumnResizing = false, columnResizeMode = 'onChange',
|
|
62
|
+
// Column ordering props
|
|
63
|
+
enableColumnDragging = false, onColumnDragEnd,
|
|
64
|
+
// Column pinning props
|
|
65
|
+
enableColumnPinning = false, onColumnPinningChange,
|
|
66
|
+
// Expandable rows props
|
|
67
|
+
enableExpanding = false, getRowCanExpand, renderSubComponent,
|
|
68
|
+
// Pagination props
|
|
69
|
+
enablePagination = true, paginationMode = 'client',
|
|
70
|
+
// Filtering props
|
|
71
|
+
enableGlobalFilter = true, enableColumnFilter = false, filterMode = 'client',
|
|
72
|
+
// Sorting props
|
|
73
|
+
enableSorting = true, sortingMode = 'client', onSortingChange, exportFilename = 'export', onExportProgress, onExportComplete, onExportError, onServerExport, onExportCancel,
|
|
74
|
+
// Styling props
|
|
75
|
+
enableHover = true, enableStripes = false, tableContainerProps = {}, tableProps = {}, fitToScreen = true, tableSize: initialTableSize = 'medium',
|
|
76
|
+
// Sticky header/footer props
|
|
77
|
+
enableStickyHeaderOrFooter = false, maxHeight = '400px',
|
|
78
|
+
// Virtualization props
|
|
79
|
+
enableVirtualization = false, estimateRowHeight = 52,
|
|
80
|
+
// Toolbar props
|
|
81
|
+
enableColumnVisibility = true, enableTableSizeControl = true, enableExport = true, enableReset = true,
|
|
82
|
+
// Loading and empty states
|
|
83
|
+
loading = false, emptyMessage = 'No data available', skeletonRows = 5,
|
|
84
|
+
// Column filters props
|
|
85
|
+
onColumnFiltersChange,
|
|
86
|
+
// Data CRUD callbacks
|
|
87
|
+
onDataChange,
|
|
88
|
+
// Slots
|
|
89
|
+
slots = {}, slotProps = {}, }, ref) {
|
|
90
|
+
// Convert mode-based props to boolean flags for internal use
|
|
91
|
+
const isServerMode = dataMode === 'server';
|
|
92
|
+
const isServerPagination = paginationMode === 'server' || isServerMode;
|
|
93
|
+
const isServerFiltering = filterMode === 'server' || isServerMode;
|
|
94
|
+
const isServerSorting = sortingMode === 'server' || isServerMode;
|
|
95
|
+
// Virtualization setup
|
|
96
|
+
const tableContainerRef = useRef(null);
|
|
97
|
+
const initialStateConfig = useMemo(() => {
|
|
98
|
+
return {
|
|
99
|
+
...DEFAULT_INITIAL_STATE,
|
|
100
|
+
...initialState,
|
|
101
|
+
};
|
|
102
|
+
}, [initialState]);
|
|
103
|
+
// Local state management - using the initial state
|
|
104
|
+
const [sorting, setSorting] = useState(initialStateConfig.sorting);
|
|
105
|
+
const [pagination, setPagination] = useState(initialStateConfig.pagination);
|
|
106
|
+
const [globalFilter, setGlobalFilter] = useState(initialStateConfig.globalFilter);
|
|
107
|
+
// Selection state - same pattern as other table states
|
|
108
|
+
const [selectionState, setSelectionState] = useState(initialState?.selectionState || { ids: [], type: 'include' });
|
|
109
|
+
const [customColumnsFilter, setCustomColumnsFilter] = useState({
|
|
110
|
+
filters: [],
|
|
111
|
+
logic: 'AND',
|
|
112
|
+
pendingFilters: [],
|
|
113
|
+
pendingLogic: 'AND'
|
|
114
|
+
});
|
|
115
|
+
const [expanded, setExpanded] = useState(initialStateConfig.expanded);
|
|
116
|
+
const [tableSize, setTableSize] = useState(initialTableSize);
|
|
117
|
+
const [columnOrder, setColumnOrder] = useState(initialStateConfig.columnOrder);
|
|
118
|
+
const [columnPinning, setColumnPinning] = useState(initialStateConfig.columnPinning);
|
|
119
|
+
// Create internal ref for API (needs to be before enhancedColumns)
|
|
120
|
+
const internalApiRef = useRef(null);
|
|
121
|
+
const { debouncedFetch, isLoading: fetchLoading } = useDebouncedFetch(onFetchData);
|
|
122
|
+
// Server data state (only used when onFetchData is provided)
|
|
123
|
+
const [serverData, setServerData] = useState([]);
|
|
124
|
+
const [serverTotal, setServerTotal] = useState(0);
|
|
125
|
+
const fetchData = useCallback(async (overrides = {}) => {
|
|
126
|
+
if (!onFetchData)
|
|
127
|
+
return;
|
|
128
|
+
const filters = {
|
|
129
|
+
globalFilter,
|
|
130
|
+
pagination,
|
|
131
|
+
customColumnsFilter,
|
|
132
|
+
sorting,
|
|
133
|
+
...overrides,
|
|
134
|
+
};
|
|
135
|
+
const result = await debouncedFetch(filters);
|
|
136
|
+
if (result?.data && result?.total !== undefined) {
|
|
137
|
+
setServerData(result.data);
|
|
138
|
+
setServerTotal(result.total);
|
|
139
|
+
// if (result.data.length > 0) {
|
|
140
|
+
// const newPageIndex filters.pageIndex;
|
|
141
|
+
// const newPageSize = filters.pageSize;
|
|
142
|
+
// if (
|
|
143
|
+
// newPageIndex !== pagination.pageIndex ||
|
|
144
|
+
// newPageSize !== pagination.pageSize
|
|
145
|
+
// ) {
|
|
146
|
+
// setPagination(result.pagination);
|
|
147
|
+
// }
|
|
148
|
+
// }
|
|
149
|
+
}
|
|
150
|
+
}, [
|
|
151
|
+
onFetchData,
|
|
152
|
+
globalFilter,
|
|
153
|
+
pagination, // Added pagination to dependencies
|
|
154
|
+
customColumnsFilter,
|
|
155
|
+
sorting,
|
|
156
|
+
debouncedFetch,
|
|
157
|
+
]);
|
|
158
|
+
const fetchDataRef = useRef(fetchData);
|
|
159
|
+
fetchDataRef.current = fetchData; // Always keep ref updated with latest function
|
|
160
|
+
// Use server data when available, otherwise use props data
|
|
161
|
+
const tableData = useMemo(() => onFetchData ? serverData : data, [onFetchData, serverData, data]);
|
|
162
|
+
const tableTotalRow = useMemo(() => onFetchData ? serverTotal : totalRow, [onFetchData, serverTotal, totalRow]);
|
|
163
|
+
const tableLoading = useMemo(() => onFetchData ? (loading || fetchLoading) : loading, [onFetchData, loading, fetchLoading]);
|
|
164
|
+
// Handle selection state changes - same pattern as other table states
|
|
165
|
+
const handleSelectionStateChange = useCallback((updaterOrValue) => {
|
|
166
|
+
// Use React state updater pattern (same as pagination, sorting in TanStack)
|
|
167
|
+
setSelectionState((prevState) => {
|
|
168
|
+
// Handle both updater function and direct value
|
|
169
|
+
const newSelectionState = typeof updaterOrValue === 'function'
|
|
170
|
+
? updaterOrValue(prevState) // ✅ Use React's current state, not stale closure
|
|
171
|
+
: updaterOrValue;
|
|
172
|
+
// Trigger callback with new state
|
|
173
|
+
if (onSelectionChange) {
|
|
174
|
+
onSelectionChange(newSelectionState);
|
|
175
|
+
}
|
|
176
|
+
return newSelectionState;
|
|
177
|
+
});
|
|
178
|
+
}, [onSelectionChange]);
|
|
179
|
+
// Handle column filter changes with logic from ColumnFilter component
|
|
180
|
+
const handleColumnFilterStateChange = useCallback((filterState) => {
|
|
181
|
+
if (filterState && typeof filterState === 'object') {
|
|
182
|
+
setCustomColumnsFilter(filterState);
|
|
183
|
+
// Call external column filters handler
|
|
184
|
+
if (onColumnFiltersChange) {
|
|
185
|
+
onColumnFiltersChange(filterState);
|
|
186
|
+
}
|
|
187
|
+
// For server-side filtering, don't fetch here - only on apply
|
|
188
|
+
// Client-side filtering will happen through filterFns automatically
|
|
189
|
+
}
|
|
190
|
+
}, [
|
|
191
|
+
onColumnFiltersChange,
|
|
192
|
+
]); // ✅ Only onSelectionChange needed
|
|
193
|
+
// Build enhanced columns with special columns (after tableTotalRow is defined)
|
|
194
|
+
const enhancedColumns = useMemo(() => {
|
|
195
|
+
let columnsMap = [...columns];
|
|
196
|
+
// Add expanding column first if enabled
|
|
197
|
+
if (enableExpanding) {
|
|
198
|
+
const expandingColumnMap = createExpandingColumn({
|
|
199
|
+
...(slotProps?.expandColumn || {}),
|
|
200
|
+
});
|
|
201
|
+
columnsMap = [expandingColumnMap, ...columnsMap];
|
|
202
|
+
}
|
|
203
|
+
// Add selection column second if enabled
|
|
204
|
+
if (enableRowSelection) {
|
|
205
|
+
const selectionColumnMap = createSelectionColumn({
|
|
206
|
+
...(slotProps?.selectionColumn || {}),
|
|
207
|
+
multiSelect: enableMultiRowSelection,
|
|
208
|
+
// Note: isRowSelectable is handled by table options, not column config
|
|
209
|
+
});
|
|
210
|
+
columnsMap = [selectionColumnMap, ...columnsMap];
|
|
211
|
+
}
|
|
212
|
+
return columnsMap;
|
|
213
|
+
}, [
|
|
214
|
+
columns,
|
|
215
|
+
slotProps?.selectionColumn,
|
|
216
|
+
slotProps?.expandColumn,
|
|
217
|
+
enableRowSelection,
|
|
218
|
+
enableExpanding,
|
|
219
|
+
enableMultiRowSelection,
|
|
220
|
+
]);
|
|
221
|
+
// Common function to notify data state changes
|
|
222
|
+
const notifyDataStateChange = useCallback((overrides = {}) => {
|
|
223
|
+
if (onDataStateChange) {
|
|
224
|
+
const currentState = {
|
|
225
|
+
globalFilter,
|
|
226
|
+
customColumnsFilter,
|
|
227
|
+
sorting,
|
|
228
|
+
pagination,
|
|
229
|
+
columnOrder,
|
|
230
|
+
columnPinning,
|
|
231
|
+
...overrides, // Allow overriding specific parts of the state
|
|
232
|
+
};
|
|
233
|
+
onDataStateChange(currentState);
|
|
234
|
+
}
|
|
235
|
+
}, [
|
|
236
|
+
onDataStateChange,
|
|
237
|
+
globalFilter,
|
|
238
|
+
customColumnsFilter,
|
|
239
|
+
sorting,
|
|
240
|
+
pagination,
|
|
241
|
+
columnOrder,
|
|
242
|
+
columnPinning,
|
|
243
|
+
]);
|
|
244
|
+
const stateChangeRef = useRef(notifyDataStateChange);
|
|
245
|
+
stateChangeRef.current = notifyDataStateChange; // Always keep ref updated with latest function
|
|
246
|
+
// Handle sorting change with custom logic for three-state sorting
|
|
247
|
+
const handleSortingChange = useCallback((updaterOrValue) => {
|
|
248
|
+
// Handle both updater function and direct value
|
|
249
|
+
let newSorting = typeof updaterOrValue === 'function'
|
|
250
|
+
? updaterOrValue(sorting)
|
|
251
|
+
: updaterOrValue;
|
|
252
|
+
console.log('handleSortingChange', newSorting);
|
|
253
|
+
newSorting = newSorting.filter((sort) => sort.id);
|
|
254
|
+
setSorting(newSorting);
|
|
255
|
+
// Call external sorting handler for server-side sorting
|
|
256
|
+
if (onSortingChange) {
|
|
257
|
+
onSortingChange(newSorting);
|
|
258
|
+
}
|
|
259
|
+
// Only notify state change and fetch data for server-side operations
|
|
260
|
+
if (isServerMode || isServerSorting) {
|
|
261
|
+
stateChangeRef.current({ sorting: newSorting });
|
|
262
|
+
fetchDataRef?.current({
|
|
263
|
+
sorting: newSorting,
|
|
264
|
+
});
|
|
265
|
+
}
|
|
266
|
+
else if (onDataStateChange) {
|
|
267
|
+
// For client-side, only notify state change if callback is provided
|
|
268
|
+
stateChangeRef.current({ sorting: newSorting });
|
|
269
|
+
}
|
|
270
|
+
}, [
|
|
271
|
+
sorting,
|
|
272
|
+
onSortingChange,
|
|
273
|
+
isServerMode,
|
|
274
|
+
isServerSorting,
|
|
275
|
+
onDataStateChange,
|
|
276
|
+
]);
|
|
277
|
+
// Handle column order change
|
|
278
|
+
const handleColumnOrderChange = useCallback((updatedColumnOrder) => {
|
|
279
|
+
setColumnOrder(updatedColumnOrder);
|
|
280
|
+
// Call external column order handler
|
|
281
|
+
if (onColumnDragEnd) {
|
|
282
|
+
onColumnDragEnd(updatedColumnOrder);
|
|
283
|
+
}
|
|
284
|
+
}, [onColumnDragEnd]);
|
|
285
|
+
// Handle column pinning change with special columns logic
|
|
286
|
+
const handleColumnPinningChange = useCallback((updatedColumnPinning) => {
|
|
287
|
+
setColumnPinning(updatedColumnPinning);
|
|
288
|
+
// Call external column pinning handler
|
|
289
|
+
if (onColumnPinningChange) {
|
|
290
|
+
onColumnPinningChange(updatedColumnPinning);
|
|
291
|
+
}
|
|
292
|
+
}, [onColumnPinningChange]);
|
|
293
|
+
// TanStack-style pagination handler - keep it simple
|
|
294
|
+
const handlePaginationChange = useCallback((updater) => {
|
|
295
|
+
// Standard TanStack pattern - direct state update
|
|
296
|
+
setPagination(updater);
|
|
297
|
+
// Handle side effects after state is set
|
|
298
|
+
// Get the new pagination value for side effects
|
|
299
|
+
const newPagination = typeof updater === 'function' ? updater(pagination) : updater;
|
|
300
|
+
// Only trigger side effects for server mode or when explicitly requested
|
|
301
|
+
if (isServerMode || isServerPagination) {
|
|
302
|
+
// Schedule side effects to run after state update
|
|
303
|
+
setTimeout(() => {
|
|
304
|
+
stateChangeRef.current({ pagination: newPagination });
|
|
305
|
+
fetchDataRef?.current({ pagination: newPagination });
|
|
306
|
+
}, 0);
|
|
307
|
+
}
|
|
308
|
+
else if (onDataStateChange) {
|
|
309
|
+
setTimeout(() => {
|
|
310
|
+
stateChangeRef.current({ pagination: newPagination });
|
|
311
|
+
}, 0);
|
|
312
|
+
}
|
|
313
|
+
}, [pagination, isServerMode, isServerPagination, onDataStateChange]);
|
|
314
|
+
// Memoized global filter handler to prevent table recreation
|
|
315
|
+
const handleGlobalFilterChange = useCallback((updaterOrValue) => {
|
|
316
|
+
// Handle both updater function and direct value
|
|
317
|
+
const newFilter = typeof updaterOrValue === 'function'
|
|
318
|
+
? updaterOrValue(globalFilter)
|
|
319
|
+
: updaterOrValue;
|
|
320
|
+
// Apply the new filter state
|
|
321
|
+
setGlobalFilter(newFilter);
|
|
322
|
+
// Only notify state change and fetch data for server-side operations
|
|
323
|
+
if (isServerMode || isServerFiltering) {
|
|
324
|
+
stateChangeRef.current({ globalFilter: newFilter });
|
|
325
|
+
fetchDataRef?.current({ globalFilter: newFilter });
|
|
326
|
+
}
|
|
327
|
+
else if (onDataStateChange) {
|
|
328
|
+
// For client-side, only notify state change if callback is provided
|
|
329
|
+
stateChangeRef.current({ globalFilter: newFilter });
|
|
330
|
+
}
|
|
331
|
+
}, [globalFilter, isServerMode, isServerFiltering, onDataStateChange]);
|
|
332
|
+
// Memoized custom column filter handler to prevent table recreation
|
|
333
|
+
const onCustomColumnFilterChangeHandler = useCallback((updater) => {
|
|
334
|
+
// Get current state from the stable reference instead of the table
|
|
335
|
+
const currentState = customColumnsFilter;
|
|
336
|
+
const newState = typeof updater === 'function'
|
|
337
|
+
? updater(currentState)
|
|
338
|
+
: updater;
|
|
339
|
+
// Convert the custom feature state to the expected CustomColumnFilterState format
|
|
340
|
+
const legacyFilterState = {
|
|
341
|
+
filters: newState.filters,
|
|
342
|
+
logic: newState.logic,
|
|
343
|
+
pendingFilters: newState.pendingFilters,
|
|
344
|
+
pendingLogic: newState.pendingLogic
|
|
345
|
+
};
|
|
346
|
+
handleColumnFilterStateChange(legacyFilterState);
|
|
347
|
+
}, [customColumnsFilter, handleColumnFilterStateChange]);
|
|
348
|
+
// Memoized custom column filter apply handler
|
|
349
|
+
const onCustomColumnFilterApplyHandler = useCallback((appliedState) => {
|
|
350
|
+
if (isServerFiltering) {
|
|
351
|
+
const serverFilterState = {
|
|
352
|
+
filters: appliedState.filters,
|
|
353
|
+
logic: appliedState.logic,
|
|
354
|
+
pendingFilters: appliedState.pendingFilters,
|
|
355
|
+
pendingLogic: appliedState.pendingLogic,
|
|
356
|
+
};
|
|
357
|
+
stateChangeRef.current({
|
|
358
|
+
customColumnsFilter: serverFilterState,
|
|
359
|
+
});
|
|
360
|
+
fetchDataRef?.current({
|
|
361
|
+
customColumnsFilter: serverFilterState,
|
|
362
|
+
});
|
|
363
|
+
}
|
|
364
|
+
}, [isServerFiltering]);
|
|
365
|
+
const table = useReactTable({
|
|
366
|
+
_features: [CustomColumnFilterFeature, CustomSelectionFeature],
|
|
367
|
+
data: tableData,
|
|
368
|
+
columns: enhancedColumns,
|
|
369
|
+
initialState: {
|
|
370
|
+
...initialStateConfig,
|
|
371
|
+
},
|
|
372
|
+
state: {
|
|
373
|
+
sorting,
|
|
374
|
+
...(enablePagination ? { pagination } : {}),
|
|
375
|
+
...(enableGlobalFilter ? { globalFilter } : {}),
|
|
376
|
+
...(enableExpanding ? { expanded } : {}),
|
|
377
|
+
...(enableColumnDragging ? { columnOrder } : {}),
|
|
378
|
+
...(enableColumnPinning ? { columnPinning } : {}),
|
|
379
|
+
...(enableColumnFilter ? { customColumnFilter: customColumnsFilter } : {}),
|
|
380
|
+
...(enableRowSelection ? { selectionState } : {}),
|
|
381
|
+
},
|
|
382
|
+
// Selection options (same pattern as column filter)
|
|
383
|
+
// Add custom features
|
|
384
|
+
selectMode: selectMode,
|
|
385
|
+
enableCustomSelection: !!enableRowSelection,
|
|
386
|
+
isRowSelectable: isRowSelectable,
|
|
387
|
+
onSelectionStateChange: enableRowSelection ? handleSelectionStateChange : undefined,
|
|
388
|
+
// Sorting
|
|
389
|
+
onSortingChange: enableSorting ? handleSortingChange : undefined,
|
|
390
|
+
onPaginationChange: enablePagination ? handlePaginationChange : undefined,
|
|
391
|
+
onRowSelectionChange: enableRowSelection ? handleSelectionStateChange : undefined,
|
|
392
|
+
onGlobalFilterChange: enableGlobalFilter ? handleGlobalFilterChange : undefined,
|
|
393
|
+
onExpandedChange: enableExpanding ? setExpanded : undefined,
|
|
394
|
+
onColumnOrderChange: enableColumnDragging ? handleColumnOrderChange : undefined,
|
|
395
|
+
onColumnPinningChange: enableColumnPinning ? handleColumnPinningChange : undefined,
|
|
396
|
+
// Handle column filters change (this will be triggered by our custom feature)
|
|
397
|
+
onCustomColumnFilterChange: onCustomColumnFilterChangeHandler,
|
|
398
|
+
// // Handle when filters are actually applied (only then fetch data)
|
|
399
|
+
onCustomColumnFilterApply: onCustomColumnFilterApplyHandler,
|
|
400
|
+
// Row model
|
|
401
|
+
getCoreRowModel: getCoreRowModel(),
|
|
402
|
+
getSortedRowModel: (enableSorting && !isServerSorting) ? getSortedRowModel() : undefined,
|
|
403
|
+
getFilteredRowModel: (enableColumnFilter && !isServerFiltering) ? getCombinedFilteredRowModel() : undefined,
|
|
404
|
+
getPaginationRowModel: (enablePagination && !isServerPagination) ? getPaginationRowModel() : undefined,
|
|
405
|
+
// Sorting
|
|
406
|
+
enableSorting: enableSorting,
|
|
407
|
+
manualSorting: isServerSorting,
|
|
408
|
+
// Filtering
|
|
409
|
+
manualFiltering: isServerFiltering,
|
|
410
|
+
// Note: Using standard TanStack features, custom selection handled separately
|
|
411
|
+
// Column resizing
|
|
412
|
+
enableColumnResizing: enableColumnResizing,
|
|
413
|
+
columnResizeMode: columnResizeMode,
|
|
414
|
+
// Column pinning
|
|
415
|
+
enableColumnPinning: enableColumnPinning,
|
|
416
|
+
// Expanding
|
|
417
|
+
getRowCanExpand: enableExpanding ? getRowCanExpand : undefined,
|
|
418
|
+
// Pagination
|
|
419
|
+
manualPagination: isServerPagination,
|
|
420
|
+
autoResetPageIndex: false, // Prevent automatic page reset on state changes
|
|
421
|
+
// pageCount: enablePagination ? Math.ceil(tableTotalRow / pagination.pageSize) : -1,
|
|
422
|
+
rowCount: tableTotalRow,
|
|
423
|
+
// Row ID
|
|
424
|
+
getRowId: (row, index) => generateRowId(row, index, idKey),
|
|
425
|
+
// Debug
|
|
426
|
+
debugAll: false, // Disabled for production
|
|
427
|
+
});
|
|
428
|
+
// Virtualization setup - with safety checks
|
|
429
|
+
const rows = table.getRowModel()?.rows || [];
|
|
430
|
+
const rowVirtualizer = useVirtualizer({
|
|
431
|
+
count: rows.length,
|
|
432
|
+
getScrollElement: () => tableContainerRef.current,
|
|
433
|
+
estimateSize: () => estimateRowHeight,
|
|
434
|
+
overscan: 10,
|
|
435
|
+
enabled: enableVirtualization && !enablePagination && rows.length > 0, // Disable with pagination or empty data
|
|
436
|
+
});
|
|
437
|
+
const tableWidth = useMemo(() => {
|
|
438
|
+
if (fitToScreen) {
|
|
439
|
+
return '100%';
|
|
440
|
+
}
|
|
441
|
+
if (enableColumnResizing) {
|
|
442
|
+
return table.getCenterTotalSize();
|
|
443
|
+
}
|
|
444
|
+
return '100%';
|
|
445
|
+
}, [
|
|
446
|
+
table,
|
|
447
|
+
enableColumnResizing,
|
|
448
|
+
fitToScreen,
|
|
449
|
+
]);
|
|
450
|
+
const tableStyle = useMemo(() => ({
|
|
451
|
+
width: tableWidth,
|
|
452
|
+
minWidth: '100%',
|
|
453
|
+
}), [tableWidth]);
|
|
454
|
+
// Handle column reorder via drag and drop
|
|
455
|
+
const handleColumnReorder = useCallback((draggedColumnId, targetColumnId) => {
|
|
456
|
+
const currentOrder = columnOrder.length > 0 ? columnOrder : enhancedColumns.map((col, index) => {
|
|
457
|
+
if (col.id)
|
|
458
|
+
return col.id;
|
|
459
|
+
const anyCol = col;
|
|
460
|
+
if (anyCol.accessorKey && typeof anyCol.accessorKey === 'string') {
|
|
461
|
+
return anyCol.accessorKey;
|
|
462
|
+
}
|
|
463
|
+
return `column_${index}`;
|
|
464
|
+
});
|
|
465
|
+
const draggedIndex = currentOrder.indexOf(draggedColumnId);
|
|
466
|
+
const targetIndex = currentOrder.indexOf(targetColumnId);
|
|
467
|
+
if (draggedIndex === -1 || targetIndex === -1)
|
|
468
|
+
return;
|
|
469
|
+
const newOrder = [...currentOrder];
|
|
470
|
+
newOrder.splice(draggedIndex, 1);
|
|
471
|
+
newOrder.splice(targetIndex, 0, draggedColumnId);
|
|
472
|
+
handleColumnOrderChange(newOrder);
|
|
473
|
+
}, [columnOrder, enhancedColumns, handleColumnOrderChange]);
|
|
474
|
+
useEffect(() => {
|
|
475
|
+
if (initialLoadData && onFetchData) {
|
|
476
|
+
fetchDataRef.current();
|
|
477
|
+
}
|
|
478
|
+
}, [initialLoadData]);
|
|
479
|
+
// Initialize column order when columns change
|
|
480
|
+
useEffect(() => {
|
|
481
|
+
if (enableColumnDragging && columnOrder.length === 0) {
|
|
482
|
+
const initialOrder = enhancedColumns.map((col, index) => {
|
|
483
|
+
// Use id if available, otherwise use accessorKey, otherwise generate unique id
|
|
484
|
+
if (col.id)
|
|
485
|
+
return col.id;
|
|
486
|
+
const anyCol = col;
|
|
487
|
+
if (anyCol.accessorKey && typeof anyCol.accessorKey === 'string') {
|
|
488
|
+
return anyCol.accessorKey;
|
|
489
|
+
}
|
|
490
|
+
return `column_${index}`;
|
|
491
|
+
});
|
|
492
|
+
setColumnOrder(initialOrder);
|
|
493
|
+
}
|
|
494
|
+
}, [
|
|
495
|
+
enableColumnDragging,
|
|
496
|
+
enhancedColumns,
|
|
497
|
+
columnOrder.length,
|
|
498
|
+
]);
|
|
499
|
+
// Get slot components for rows and cells
|
|
500
|
+
const LoadingRowSlot = getSlotComponent(slots, 'loadingRow', LoadingRows);
|
|
501
|
+
const EmptyRowSlot = getSlotComponent(slots, 'emptyRow', EmptyDataRow);
|
|
502
|
+
// Render table rows with slot support
|
|
503
|
+
const renderTableRows = useCallback(() => {
|
|
504
|
+
if (tableLoading) {
|
|
505
|
+
return (_jsx(LoadingRowSlot, { rowCount: enablePagination ? Math.min(pagination.pageSize, skeletonRows) : skeletonRows, colSpan: table.getAllColumns().length, slots: slots, slotProps: slotProps, ...slotProps?.loadingRow }));
|
|
506
|
+
}
|
|
507
|
+
if (rows.length === 0) {
|
|
508
|
+
return (_jsx(EmptyRowSlot, { colSpan: table.getAllColumns().length, message: emptyMessage, slots: slots, slotProps: slotProps, ...slotProps?.emptyRow }));
|
|
509
|
+
}
|
|
510
|
+
// Virtualized rendering
|
|
511
|
+
if (enableVirtualization && !enablePagination && rows.length > 0) {
|
|
512
|
+
const virtualItems = rowVirtualizer.getVirtualItems();
|
|
513
|
+
return (_jsxs(_Fragment, { children: [virtualItems.length > 0 && (_jsx("tr", { children: _jsx("td", { colSpan: table.getAllColumns().length, style: {
|
|
514
|
+
height: `${virtualItems[0]?.start ?? 0}px`,
|
|
515
|
+
padding: 0,
|
|
516
|
+
border: 0,
|
|
517
|
+
} }) })), virtualItems.map((virtualRow) => {
|
|
518
|
+
const row = rows[virtualRow.index];
|
|
519
|
+
if (!row)
|
|
520
|
+
return null; // Safety check
|
|
521
|
+
return (_jsx(DataTableRow, { row: row, enableHover: enableHover, enableStripes: enableStripes, isOdd: virtualRow.index % 2 === 1, renderSubComponent: renderSubComponent, disableStickyHeader: enableStickyHeaderOrFooter, ...slotProps?.row }, row.id));
|
|
522
|
+
}), virtualItems.length > 0 && (_jsx("tr", { children: _jsx("td", { colSpan: table.getAllColumns().length, style: {
|
|
523
|
+
height: `${rowVirtualizer.getTotalSize() -
|
|
524
|
+
(virtualItems[virtualItems.length - 1]?.end ?? 0)}px`,
|
|
525
|
+
padding: 0,
|
|
526
|
+
border: 0,
|
|
527
|
+
} }) }))] }));
|
|
528
|
+
}
|
|
529
|
+
// Regular rendering (non-virtualized)
|
|
530
|
+
return rows.map((row, index) => (_jsx(DataTableRow, { row: row, enableHover: enableHover, enableStripes: enableStripes, isOdd: index % 2 === 1, renderSubComponent: renderSubComponent, disableStickyHeader: enableStickyHeaderOrFooter, slots: slots, slotProps: slotProps }, row.id)));
|
|
531
|
+
}, [
|
|
532
|
+
tableLoading,
|
|
533
|
+
rows,
|
|
534
|
+
enableVirtualization,
|
|
535
|
+
enablePagination,
|
|
536
|
+
LoadingRowSlot,
|
|
537
|
+
pagination.pageSize,
|
|
538
|
+
skeletonRows,
|
|
539
|
+
table,
|
|
540
|
+
slotProps,
|
|
541
|
+
EmptyRowSlot,
|
|
542
|
+
emptyMessage,
|
|
543
|
+
rowVirtualizer,
|
|
544
|
+
enableHover,
|
|
545
|
+
enableStripes,
|
|
546
|
+
renderSubComponent,
|
|
547
|
+
enableStickyHeaderOrFooter,
|
|
548
|
+
slots,
|
|
549
|
+
]);
|
|
550
|
+
// Export state management
|
|
551
|
+
const [exportController, setExportController] = useState(null);
|
|
552
|
+
const isExporting = useMemo(() => exportController !== null, [exportController]);
|
|
553
|
+
const handleCancelExport = useCallback(() => {
|
|
554
|
+
if (exportController) {
|
|
555
|
+
exportController.abort();
|
|
556
|
+
setExportController(null);
|
|
557
|
+
if (onExportCancel) {
|
|
558
|
+
onExportCancel();
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
}, [exportController, onExportCancel]);
|
|
562
|
+
// Expose imperative API via ref using custom hook
|
|
563
|
+
useDataTableApi({
|
|
564
|
+
table,
|
|
565
|
+
data: tableData,
|
|
566
|
+
idKey,
|
|
567
|
+
globalFilter,
|
|
568
|
+
customColumnsFilter,
|
|
569
|
+
sorting,
|
|
570
|
+
pagination,
|
|
571
|
+
columnOrder,
|
|
572
|
+
columnPinning,
|
|
573
|
+
enhancedColumns,
|
|
574
|
+
enablePagination,
|
|
575
|
+
enableColumnPinning,
|
|
576
|
+
initialPageIndex: pagination.pageIndex,
|
|
577
|
+
initialPageSize: pagination.pageSize,
|
|
578
|
+
pageSize: pagination.pageSize,
|
|
579
|
+
// Selection props
|
|
580
|
+
selectMode,
|
|
581
|
+
onSelectionChange: handleSelectionStateChange,
|
|
582
|
+
handleColumnFilterStateChange,
|
|
583
|
+
onDataStateChange,
|
|
584
|
+
onFetchData: onFetchData,
|
|
585
|
+
onDataChange,
|
|
586
|
+
// Export props
|
|
587
|
+
exportFilename,
|
|
588
|
+
onExportProgress,
|
|
589
|
+
onExportComplete,
|
|
590
|
+
onExportError,
|
|
591
|
+
onServerExport,
|
|
592
|
+
exportController,
|
|
593
|
+
setExportController,
|
|
594
|
+
isExporting,
|
|
595
|
+
dataMode,
|
|
596
|
+
}, internalApiRef);
|
|
597
|
+
// Forward the internal ref to the external ref
|
|
598
|
+
useImperativeHandle(ref, () => internalApiRef.current, []);
|
|
599
|
+
// Calculate bulk actions values directly from selection state to prevent infinite re-renders
|
|
600
|
+
const isSomeRowsSelected = useMemo(() => {
|
|
601
|
+
if (!enableBulkActions || !enableRowSelection)
|
|
602
|
+
return false;
|
|
603
|
+
if (selectionState.type === 'exclude') {
|
|
604
|
+
// In exclude mode, we have some selected if not all are excluded
|
|
605
|
+
return selectionState.ids.length < tableTotalRow;
|
|
606
|
+
}
|
|
607
|
+
else {
|
|
608
|
+
// In include mode, we have some selected if list has items
|
|
609
|
+
return selectionState.ids.length > 0;
|
|
610
|
+
}
|
|
611
|
+
}, [enableBulkActions, enableRowSelection, selectionState, tableTotalRow]);
|
|
612
|
+
const selectedRowCount = useMemo(() => {
|
|
613
|
+
if (!enableBulkActions || !enableRowSelection)
|
|
614
|
+
return 0;
|
|
615
|
+
if (selectionState.type === 'exclude') {
|
|
616
|
+
// In exclude mode, selected count is total minus excluded
|
|
617
|
+
return tableTotalRow - selectionState.ids.length;
|
|
618
|
+
}
|
|
619
|
+
else {
|
|
620
|
+
// In include mode, selected count is the length of included list
|
|
621
|
+
return selectionState.ids.length;
|
|
622
|
+
}
|
|
623
|
+
}, [enableBulkActions, enableRowSelection, selectionState, tableTotalRow]);
|
|
624
|
+
// Get slot components with fallbacks
|
|
625
|
+
const RootSlot = getSlotComponent(slots, 'root', Box);
|
|
626
|
+
const ToolbarSlot = getSlotComponent(slots, 'toolbar', DataTableToolbar);
|
|
627
|
+
const BulkActionsSlot = getSlotComponent(slots, 'bulkActionsToolbar', BulkActionsToolbar);
|
|
628
|
+
const TableContainerSlot = getSlotComponent(slots, 'tableContainer', TableContainer);
|
|
629
|
+
const TableSlot = getSlotComponent(slots, 'table', Table);
|
|
630
|
+
const BodySlot = getSlotComponent(slots, 'body', TableBody);
|
|
631
|
+
const FooterSlot = getSlotComponent(slots, 'footer', Box);
|
|
632
|
+
const PaginationSlot = getSlotComponent(slots, 'pagination', DataTablePagination);
|
|
633
|
+
// Base props for all slots
|
|
634
|
+
return (_jsx(DataTableProvider, { table: table, children: _jsxs(RootSlot, { ...slotProps?.root, children: [(enableGlobalFilter || extraFilter) ? (_jsx(ToolbarSlot, { extraFilter: extraFilter, enableGlobalFilter: enableGlobalFilter, enableColumnVisibility: enableColumnVisibility, enableColumnFilter: enableColumnFilter, enableExport: enableExport, enableReset: enableReset, enableTableSizeControl: enableTableSizeControl, enableColumnPinning: enableColumnPinning, ...slotProps?.toolbar })) : null, enableBulkActions && enableRowSelection && isSomeRowsSelected ? (_jsx(BulkActionsSlot, { selectionState: selectionState, selectedRowCount: selectedRowCount, bulkActions: bulkActions, sx: {
|
|
635
|
+
position: 'relative',
|
|
636
|
+
zIndex: 2, // Higher than sticky header
|
|
637
|
+
}, ...slotProps?.bulkActionsToolbar })) : null, _jsx(TableContainerSlot, { component: Paper, ref: tableContainerRef, sx: {
|
|
638
|
+
width: '100%',
|
|
639
|
+
overflowX: 'auto',
|
|
640
|
+
...(enableStickyHeaderOrFooter && {
|
|
641
|
+
maxHeight: maxHeight,
|
|
642
|
+
overflowY: 'auto',
|
|
643
|
+
}),
|
|
644
|
+
...(enableVirtualization && {
|
|
645
|
+
maxHeight: maxHeight,
|
|
646
|
+
overflowY: 'auto',
|
|
647
|
+
}),
|
|
648
|
+
...tableContainerProps?.sx,
|
|
649
|
+
}, ...tableContainerProps, ...slotProps?.tableContainer, children: _jsxs(TableSlot, { size: tableSize, stickyHeader: enableStickyHeaderOrFooter, style: {
|
|
650
|
+
...tableStyle,
|
|
651
|
+
tableLayout: fitToScreen ? 'fixed' : 'auto',
|
|
652
|
+
...tableProps?.style,
|
|
653
|
+
}, ...tableProps, ...slotProps?.table, children: [_jsx(TableHeader, { draggable: enableColumnDragging, enableColumnResizing: enableColumnResizing, enableStickyHeader: enableStickyHeaderOrFooter, fitToScreen: fitToScreen, onColumnReorder: handleColumnReorder, slots: slots, slotProps: slotProps }), _jsx(BodySlot, { ...slotProps?.body, children: renderTableRows() })] }) }), enablePagination ? (_jsx(FooterSlot, { sx: {
|
|
654
|
+
...(enableStickyHeaderOrFooter && {
|
|
655
|
+
position: 'sticky',
|
|
656
|
+
bottom: 0,
|
|
657
|
+
backgroundColor: 'background.paper',
|
|
658
|
+
borderTop: '1px solid',
|
|
659
|
+
borderColor: 'divider',
|
|
660
|
+
zIndex: 1,
|
|
661
|
+
}),
|
|
662
|
+
}, ...slotProps?.footer, children: _jsx(PaginationSlot, { footerFilter: footerFilter, ...slotProps?.pagination, pagination: pagination, totalRow: tableTotalRow }) })) : null] }) }));
|
|
663
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"data-table.types.d.ts","sourceRoot":"","sources":["../../../../src/lib/components/table/data-table.types.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EAAE,GAAG,EAAE,YAAY,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AACzG,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAElC,OAAO,KAAK,EAAE,uBAAuB,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACrF,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAC3E,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC1D,OAAO,EAAE,cAAc,EAAE,MAAM,yCAAyC,CAAC;AAGzE,MAAM,MAAM,UAAU,GAAG,MAAM,GAAG,KAAK,CAAC;AAIxC,OAAO,QAAQ,sBAAsB,CAAC;IAClC,UAAU,UAAU,CAAC,KAAK,SAAS,OAAO,EAAE,MAAM;KACjD;CACJ;AAKD,MAAM,WAAW,cAAc,CAAC,CAAC;IAE7B,OAAO,EAAE,eAAe,CAAC,CAAC,CAAC,EAAE,CAAC;IAC9B,IAAI,CAAC,EAAE,CAAC,EAAE,CAAC;IACX,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC,CAAC;IAChB,WAAW,CAAC,EAAE,SAAS,GAAG,IAAI,CAAC;IAC/B,YAAY,CAAC,EAAE,SAAS,GAAG,IAAI,CAAC;IAGhC,QAAQ,CAAC,EAAE,QAAQ,GAAG,QAAQ,CAAC;IAC/B,YAAY,CAAC,EAAE,OAAO,CAAC,UAAU,CAAC,CAAC;IACnC,eAA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