@ackplus/react-tanstack-data-table 1.1.20 → 1.1.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/lib/hooks/use-data-table-engine.d.ts.map +1 -1
- package/dist/lib/hooks/use-data-table-engine.js +4 -0
- package/package.json +3 -4
- package/src/index.ts +0 -75
- package/src/lib/components/data-table-view.tsx +0 -386
- package/src/lib/components/droupdown/menu-dropdown.tsx +0 -103
- package/src/lib/components/filters/filter-value-input.tsx +0 -225
- package/src/lib/components/filters/index.ts +0 -126
- package/src/lib/components/headers/draggable-header.tsx +0 -326
- package/src/lib/components/headers/index.ts +0 -6
- package/src/lib/components/headers/table-header.tsx +0 -175
- package/src/lib/components/index.ts +0 -21
- package/src/lib/components/pagination/data-table-pagination.tsx +0 -111
- package/src/lib/components/pagination/index.ts +0 -5
- package/src/lib/components/rows/data-table-row.tsx +0 -218
- package/src/lib/components/rows/empty-data-row.tsx +0 -69
- package/src/lib/components/rows/index.ts +0 -7
- package/src/lib/components/rows/loading-rows.tsx +0 -164
- package/src/lib/components/toolbar/bulk-actions-toolbar.tsx +0 -125
- package/src/lib/components/toolbar/column-filter-control.tsx +0 -432
- package/src/lib/components/toolbar/column-pinning-control.tsx +0 -275
- package/src/lib/components/toolbar/column-reset-control.tsx +0 -74
- package/src/lib/components/toolbar/column-visibility-control.tsx +0 -105
- package/src/lib/components/toolbar/data-table-toolbar.tsx +0 -257
- package/src/lib/components/toolbar/index.ts +0 -17
- package/src/lib/components/toolbar/table-export-control.tsx +0 -233
- package/src/lib/components/toolbar/table-refresh-control.tsx +0 -62
- package/src/lib/components/toolbar/table-search-control.tsx +0 -155
- package/src/lib/components/toolbar/table-size-control.tsx +0 -102
- package/src/lib/contexts/data-table-context.tsx +0 -126
- package/src/lib/data-table.tsx +0 -29
- package/src/lib/features/README.md +0 -161
- package/src/lib/features/column-filter.feature.ts +0 -493
- package/src/lib/features/index.ts +0 -23
- package/src/lib/features/selection.feature.ts +0 -322
- package/src/lib/hooks/index.ts +0 -2
- package/src/lib/hooks/use-data-table-engine.ts +0 -1552
- package/src/lib/icons/add-icon.tsx +0 -23
- package/src/lib/icons/csv-icon.tsx +0 -15
- package/src/lib/icons/delete-icon.tsx +0 -30
- package/src/lib/icons/excel-icon.tsx +0 -15
- package/src/lib/icons/index.ts +0 -7
- package/src/lib/icons/unpin-icon.tsx +0 -18
- package/src/lib/icons/view-comfortable-icon.tsx +0 -45
- package/src/lib/icons/view-compact-icon.tsx +0 -55
- package/src/lib/types/column.types.ts +0 -63
- package/src/lib/types/data-table-api.ts +0 -191
- package/src/lib/types/data-table.types.ts +0 -193
- package/src/lib/types/export.types.ts +0 -223
- package/src/lib/types/index.ts +0 -24
- package/src/lib/types/slots.types.ts +0 -342
- package/src/lib/types/table.types.ts +0 -88
- package/src/lib/utils/column-helpers.ts +0 -72
- package/src/lib/utils/debounced-fetch.utils.ts +0 -131
- package/src/lib/utils/export-utils.ts +0 -712
- package/src/lib/utils/index.ts +0 -27
- package/src/lib/utils/logger.ts +0 -203
- package/src/lib/utils/slot-helpers.tsx +0 -194
- package/src/lib/utils/special-columns.utils.ts +0 -101
- package/src/lib/utils/styling-helpers.ts +0 -126
- package/src/lib/utils/table-helpers.ts +0 -106
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-data-table-engine.d.ts","sourceRoot":"","sources":["../../../src/lib/hooks/use-data-table-engine.ts"],"names":[],"mappings":"AAAA,OAAO,EAKH,aAAa,EACb,KAAK,gBAAgB,EACrB,KAAK,kBAAkB,EACvB,KAAK,YAAY,EACjB,KAAK,OAAO,EACf,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAEzD,OAAO,EAAiE,SAAS,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAGhH,OAAO,KAAK,EACR,iBAAiB,EACjB,aAAa,EACb,kBAAkB,EAClB,cAAc,EACd,WAAW,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GAAG,IAAI,CAAC;QAChC,cAAc,EAAE,qBAAqB,CAAC;QACtC,cAAc,EAAE,MAAM,IAAI,CAAC;QAC3B,cAAc,EAAE,MAAM,CAAC;QACvB,gBAAgB,CAAC,EAAE,CAAC,QAAQ,EAAE,qBAAqB,KAAK,IAAI,CAAC;QAC7D,gBAAgB,CAAC,EAAE,CAAC,MAAM,EAAE;YAAE,OAAO,EAAE,OAAO,CAAC;YAAC,QAAQ,EAAE,MAAM,CAAC;YAAC,SAAS,EAAE,MAAM,CAAA;SAAE,KAAK,IAAI,CAAC;QAC/F,aAAa,CAAC,EAAE,CAAC,KAAK,EAAE;YAAE,OAAO,EAAE,MAAM,CAAC;YAAC,IAAI,EAAE,MAAM,CAAA;SAAE,KAAK,IAAI,CAAC;QACnE,cAAc,CAAC,EAAE,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC,GAAG,CAAC,EAAE,SAAS,CAAC,EAAE,cAAc,EAAE,MAAM,CAAC,EAAE,WAAW,KAAK,OAAO,CAAC,GAAG,CAAC,CAAC;KAC/G,CAAC;CACL;AAED,wBAAgB,kBAAkB,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAC5D,KAAK,EAAE,cAAc,CAAC,CAAC,CAAC,GACzB,YAAY,CAAC,CAAC,CAAC,CAk0CjB"}
|
|
@@ -29,6 +29,7 @@ const DEFAULT_INITIAL_STATE = {
|
|
|
29
29
|
},
|
|
30
30
|
};
|
|
31
31
|
function uiReducer(state, action) {
|
|
32
|
+
console.log('uiReducer', action === null || action === void 0 ? void 0 : action.type, state);
|
|
32
33
|
switch (action.type) {
|
|
33
34
|
case "SET_SORTING_RESET_PAGE":
|
|
34
35
|
return { ...state, sorting: action.payload, pagination: { pageIndex: 0, pageSize: state.pagination.pageSize } };
|
|
@@ -191,6 +192,7 @@ function useDataTableEngine(props) {
|
|
|
191
192
|
const fetchData = useEvent(async (overrides = {}, options) => {
|
|
192
193
|
var _a, _b;
|
|
193
194
|
const s = uiRef.current;
|
|
195
|
+
console.log('fetchData', s, overrides, options);
|
|
194
196
|
const filters = {
|
|
195
197
|
globalFilter: s.globalFilter,
|
|
196
198
|
pagination: s.pagination,
|
|
@@ -285,6 +287,7 @@ function useDataTableEngine(props) {
|
|
|
285
287
|
var _a;
|
|
286
288
|
const prev = uiRef.current.pagination;
|
|
287
289
|
const next = typeof updater === "function" ? updater(prev) : updater;
|
|
290
|
+
console.log('onPaginationChange', next);
|
|
288
291
|
(_a = onPaginationChangeRef.current) === null || _a === void 0 ? void 0 : _a.call(onPaginationChangeRef, next);
|
|
289
292
|
dispatch({ type: "SET_PAGINATION", payload: next });
|
|
290
293
|
},
|
|
@@ -420,6 +423,7 @@ function useDataTableEngine(props) {
|
|
|
420
423
|
const delay = (_a = nextFetchDelayRef.current) !== null && _a !== void 0 ? _a : 0;
|
|
421
424
|
nextFetchDelayRef.current = 0; // reset after using
|
|
422
425
|
const timeoutId = setTimeout(() => {
|
|
426
|
+
console.log('stateChange fetch', delay, serverKey);
|
|
423
427
|
void fetchData({}, { delay, meta: { reason: "stateChange" } });
|
|
424
428
|
}, 0);
|
|
425
429
|
return () => clearTimeout(timeoutId);
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ackplus/react-tanstack-data-table",
|
|
3
3
|
"type": "commonjs",
|
|
4
|
-
"version": "1.1.
|
|
4
|
+
"version": "1.1.21",
|
|
5
5
|
"description": "A powerful React data table component built with MUI and TanStack Table",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"react",
|
|
@@ -38,8 +38,7 @@
|
|
|
38
38
|
"./package.json": "./package.json"
|
|
39
39
|
},
|
|
40
40
|
"files": [
|
|
41
|
-
"dist"
|
|
42
|
-
"src"
|
|
41
|
+
"dist"
|
|
43
42
|
],
|
|
44
43
|
"scripts": {
|
|
45
44
|
"build": "tsc -p tsconfig.build.json",
|
|
@@ -52,7 +51,7 @@
|
|
|
52
51
|
"rxjs": "^7.8.0",
|
|
53
52
|
"xlsx": "^0.18.5",
|
|
54
53
|
"@tanstack/react-table": "^8.21.3",
|
|
55
|
-
"@tanstack/react-virtual": "^3.13.
|
|
54
|
+
"@tanstack/react-virtual": "^3.13.18"
|
|
56
55
|
},
|
|
57
56
|
"peerDependencies": {
|
|
58
57
|
"@emotion/react": ">=11.0.0",
|
package/src/index.ts
DELETED
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* MUI TanStack DataTable
|
|
3
|
-
*
|
|
4
|
-
* A comprehensive, highly customizable data table component built with:
|
|
5
|
-
* - Material-UI (MUI) for styling
|
|
6
|
-
* - TanStack Table for table logic
|
|
7
|
-
* - TypeScript for type safety
|
|
8
|
-
*
|
|
9
|
-
* Features:
|
|
10
|
-
* - Column sorting, filtering, resizing, reordering, and pinning
|
|
11
|
-
* - Row selection, expansion, and virtualization
|
|
12
|
-
* - Pagination with customizable page sizes
|
|
13
|
-
* - Global and column-specific search/filtering
|
|
14
|
-
* - Export functionality (CSV, XLSX, JSON)
|
|
15
|
-
* - Responsive design with mobile support
|
|
16
|
-
* - Accessibility features
|
|
17
|
-
* - Customizable toolbar and actions
|
|
18
|
-
* - Loading states and empty data handling
|
|
19
|
-
*/
|
|
20
|
-
|
|
21
|
-
// Main components - be specific to avoid conflicts
|
|
22
|
-
export { DataTable } from './lib/data-table';
|
|
23
|
-
export { DataTableView } from './lib/components/data-table-view';
|
|
24
|
-
export type { DataTableViewProps } from './lib/components/data-table-view';
|
|
25
|
-
export { useDataTableEngine } from './lib/hooks';
|
|
26
|
-
export type { EngineResult } from './lib/hooks';
|
|
27
|
-
|
|
28
|
-
// Other component exports
|
|
29
|
-
export * from './lib/components/headers';
|
|
30
|
-
export * from './lib/components/rows';
|
|
31
|
-
export * from './lib/components/filters';
|
|
32
|
-
export * from './lib/components/pagination';
|
|
33
|
-
export * from './lib/components/droupdown/menu-dropdown';
|
|
34
|
-
|
|
35
|
-
// Individual toolbar components for custom toolbars
|
|
36
|
-
export {
|
|
37
|
-
ColumnVisibilityControl,
|
|
38
|
-
ColumnPinningControl,
|
|
39
|
-
ColumnResetControl,
|
|
40
|
-
TableExportControl,
|
|
41
|
-
TableSizeControl,
|
|
42
|
-
BulkActionsToolbar,
|
|
43
|
-
DataTableToolbar,
|
|
44
|
-
} from './lib/components/toolbar';
|
|
45
|
-
|
|
46
|
-
// Export bulk action types
|
|
47
|
-
export type { BulkActionsToolbarProps } from './lib/components/toolbar';
|
|
48
|
-
|
|
49
|
-
// Utilities and helpers
|
|
50
|
-
export * from './lib/utils/styling-helpers';
|
|
51
|
-
export * from './lib/utils/column-helpers';
|
|
52
|
-
export * from './lib/utils/table-helpers';
|
|
53
|
-
export * from './lib/utils/logger';
|
|
54
|
-
|
|
55
|
-
// Custom hooks
|
|
56
|
-
export * from './lib/types';
|
|
57
|
-
|
|
58
|
-
// Re-export commonly used types from TanStack Table
|
|
59
|
-
export type {
|
|
60
|
-
Column,
|
|
61
|
-
ColumnDef,
|
|
62
|
-
Row,
|
|
63
|
-
Table,
|
|
64
|
-
Header,
|
|
65
|
-
Cell,
|
|
66
|
-
SortingState,
|
|
67
|
-
ColumnFiltersState,
|
|
68
|
-
VisibilityState,
|
|
69
|
-
ColumnOrderState,
|
|
70
|
-
ColumnPinningState,
|
|
71
|
-
PaginationState,
|
|
72
|
-
} from '@tanstack/react-table';
|
|
73
|
-
|
|
74
|
-
// Custom features (this includes SelectMode from features)
|
|
75
|
-
export * from './lib/features';
|
|
@@ -1,386 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* DataTableView – presentational layer for DataTable.
|
|
3
|
-
* Renders based on engine result; no fetch, export, or API logic.
|
|
4
|
-
*/
|
|
5
|
-
import { Table, TableContainer, TableBody, Box, Paper } from '@mui/material';
|
|
6
|
-
import React, { useCallback } from 'react';
|
|
7
|
-
|
|
8
|
-
import { getSlotComponentWithProps, mergeSlotProps } from '../utils/slot-helpers';
|
|
9
|
-
import { TableHeader } from './headers';
|
|
10
|
-
import { DataTablePagination } from './pagination';
|
|
11
|
-
import { DataTableRow, LoadingRows, EmptyDataRow } from './rows';
|
|
12
|
-
import { DataTableToolbar, BulkActionsToolbar } from './toolbar';
|
|
13
|
-
import type { DataTableProps } from '../types/data-table.types';
|
|
14
|
-
import type { EngineResult } from '../hooks/use-data-table-engine';
|
|
15
|
-
|
|
16
|
-
export interface DataTableViewProps<T = any> extends DataTableProps<T> {
|
|
17
|
-
engine: EngineResult<T>;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export function DataTableView<T extends Record<string, any>>({
|
|
21
|
-
engine,
|
|
22
|
-
extraFilter = null,
|
|
23
|
-
footerFilter = null,
|
|
24
|
-
enableGlobalFilter = true,
|
|
25
|
-
enableColumnVisibility = true,
|
|
26
|
-
enableColumnFilter = false,
|
|
27
|
-
enableExport = false,
|
|
28
|
-
enableReset = true,
|
|
29
|
-
enableTableSizeControl = true,
|
|
30
|
-
enableColumnPinning = false,
|
|
31
|
-
enableRefresh = false,
|
|
32
|
-
enableBulkActions = false,
|
|
33
|
-
bulkActions,
|
|
34
|
-
enableRowSelection = false,
|
|
35
|
-
enableColumnDragging = false,
|
|
36
|
-
enableColumnResizing = false,
|
|
37
|
-
enableStickyHeaderOrFooter = false,
|
|
38
|
-
maxHeight = '400px',
|
|
39
|
-
enableVirtualization = false,
|
|
40
|
-
enablePagination = false,
|
|
41
|
-
tableProps = {},
|
|
42
|
-
enableHover = true,
|
|
43
|
-
enableStripes = false,
|
|
44
|
-
emptyMessage = 'No data available',
|
|
45
|
-
skeletonRows = 5,
|
|
46
|
-
onRowClick,
|
|
47
|
-
selectOnRowClick = false,
|
|
48
|
-
renderSubComponent,
|
|
49
|
-
slots = {},
|
|
50
|
-
slotProps = {},
|
|
51
|
-
}: DataTableViewProps<T>) {
|
|
52
|
-
const {
|
|
53
|
-
table,
|
|
54
|
-
refs,
|
|
55
|
-
derived,
|
|
56
|
-
state,
|
|
57
|
-
actions,
|
|
58
|
-
} = engine;
|
|
59
|
-
|
|
60
|
-
const {
|
|
61
|
-
tableContainerRef,
|
|
62
|
-
apiRef,
|
|
63
|
-
} = refs;
|
|
64
|
-
|
|
65
|
-
const {
|
|
66
|
-
tableLoading,
|
|
67
|
-
rows,
|
|
68
|
-
visibleLeafColumns,
|
|
69
|
-
useFixedLayout,
|
|
70
|
-
tableStyle,
|
|
71
|
-
isSomeRowsSelected,
|
|
72
|
-
selectedRowCount,
|
|
73
|
-
tableTotalRow,
|
|
74
|
-
} = derived;
|
|
75
|
-
|
|
76
|
-
const {
|
|
77
|
-
pagination,
|
|
78
|
-
selectionState,
|
|
79
|
-
tableSize,
|
|
80
|
-
} = state;
|
|
81
|
-
|
|
82
|
-
const {
|
|
83
|
-
handleColumnReorder,
|
|
84
|
-
renderRowModel,
|
|
85
|
-
} = actions;
|
|
86
|
-
|
|
87
|
-
const rowVirtualizer = renderRowModel.rowVirtualizer;
|
|
88
|
-
|
|
89
|
-
const renderTableRows = useCallback(() => {
|
|
90
|
-
if (tableLoading) {
|
|
91
|
-
const { component: LoadingRowComponent, props: loadingRowProps } = getSlotComponentWithProps(
|
|
92
|
-
slots,
|
|
93
|
-
slotProps || {},
|
|
94
|
-
'loadingRow',
|
|
95
|
-
LoadingRows,
|
|
96
|
-
{}
|
|
97
|
-
);
|
|
98
|
-
return (
|
|
99
|
-
<LoadingRowComponent
|
|
100
|
-
rowCount={enablePagination ? Math.min(pagination.pageSize, skeletonRows) : skeletonRows}
|
|
101
|
-
colSpan={table.getAllColumns().length}
|
|
102
|
-
slots={slots}
|
|
103
|
-
slotProps={slotProps}
|
|
104
|
-
{...loadingRowProps}
|
|
105
|
-
/>
|
|
106
|
-
);
|
|
107
|
-
}
|
|
108
|
-
if (rows.length === 0) {
|
|
109
|
-
const { component: EmptyRowComponent, props: emptyRowProps } = getSlotComponentWithProps(
|
|
110
|
-
slots,
|
|
111
|
-
slotProps || {},
|
|
112
|
-
'emptyRow',
|
|
113
|
-
EmptyDataRow,
|
|
114
|
-
{}
|
|
115
|
-
);
|
|
116
|
-
return (
|
|
117
|
-
<EmptyRowComponent
|
|
118
|
-
colSpan={table.getAllColumns().length}
|
|
119
|
-
message={emptyMessage}
|
|
120
|
-
slots={slots}
|
|
121
|
-
slotProps={slotProps}
|
|
122
|
-
{...emptyRowProps}
|
|
123
|
-
/>
|
|
124
|
-
);
|
|
125
|
-
}
|
|
126
|
-
if (enableVirtualization && !enablePagination && rows.length > 0) {
|
|
127
|
-
const virtualItems = rowVirtualizer.getVirtualItems();
|
|
128
|
-
return (
|
|
129
|
-
<>
|
|
130
|
-
{virtualItems.length > 0 && (
|
|
131
|
-
<tr>
|
|
132
|
-
<td
|
|
133
|
-
colSpan={table.getAllColumns().length}
|
|
134
|
-
style={{
|
|
135
|
-
height: `${virtualItems[0]?.start ?? 0}px`,
|
|
136
|
-
padding: 0,
|
|
137
|
-
border: 0,
|
|
138
|
-
}}
|
|
139
|
-
/>
|
|
140
|
-
</tr>
|
|
141
|
-
)}
|
|
142
|
-
{virtualItems.map((virtualRow) => {
|
|
143
|
-
const row = rows[virtualRow.index];
|
|
144
|
-
if (!row) return null;
|
|
145
|
-
return (
|
|
146
|
-
<DataTableRow
|
|
147
|
-
key={row.id}
|
|
148
|
-
row={row}
|
|
149
|
-
enableHover={enableHover}
|
|
150
|
-
enableStripes={enableStripes}
|
|
151
|
-
isOdd={virtualRow.index % 2 === 1}
|
|
152
|
-
renderSubComponent={renderSubComponent}
|
|
153
|
-
disableStickyHeader={enableStickyHeaderOrFooter}
|
|
154
|
-
onRowClick={onRowClick}
|
|
155
|
-
selectOnRowClick={selectOnRowClick}
|
|
156
|
-
slots={slots}
|
|
157
|
-
slotProps={slotProps}
|
|
158
|
-
/>
|
|
159
|
-
);
|
|
160
|
-
})}
|
|
161
|
-
{virtualItems.length > 0 && (
|
|
162
|
-
<tr>
|
|
163
|
-
<td
|
|
164
|
-
colSpan={table.getAllColumns().length}
|
|
165
|
-
style={{
|
|
166
|
-
height: `${rowVirtualizer.getTotalSize() -
|
|
167
|
-
(virtualItems[virtualItems.length - 1]?.end ?? 0)}px`,
|
|
168
|
-
padding: 0,
|
|
169
|
-
border: 0,
|
|
170
|
-
}}
|
|
171
|
-
/>
|
|
172
|
-
</tr>
|
|
173
|
-
)}
|
|
174
|
-
</>
|
|
175
|
-
);
|
|
176
|
-
}
|
|
177
|
-
return rows.map((row, index) => (
|
|
178
|
-
<DataTableRow
|
|
179
|
-
key={row.id}
|
|
180
|
-
row={row}
|
|
181
|
-
enableHover={enableHover}
|
|
182
|
-
enableStripes={enableStripes}
|
|
183
|
-
isOdd={index % 2 === 1}
|
|
184
|
-
renderSubComponent={renderSubComponent}
|
|
185
|
-
disableStickyHeader={enableStickyHeaderOrFooter}
|
|
186
|
-
onRowClick={onRowClick}
|
|
187
|
-
selectOnRowClick={selectOnRowClick}
|
|
188
|
-
slots={slots}
|
|
189
|
-
slotProps={slotProps}
|
|
190
|
-
/>
|
|
191
|
-
));
|
|
192
|
-
}, [
|
|
193
|
-
tableLoading,
|
|
194
|
-
rows,
|
|
195
|
-
enableVirtualization,
|
|
196
|
-
enablePagination,
|
|
197
|
-
pagination.pageSize,
|
|
198
|
-
skeletonRows,
|
|
199
|
-
table,
|
|
200
|
-
slotProps,
|
|
201
|
-
emptyMessage,
|
|
202
|
-
rowVirtualizer,
|
|
203
|
-
enableHover,
|
|
204
|
-
enableStripes,
|
|
205
|
-
renderSubComponent,
|
|
206
|
-
enableStickyHeaderOrFooter,
|
|
207
|
-
onRowClick,
|
|
208
|
-
selectOnRowClick,
|
|
209
|
-
slots,
|
|
210
|
-
]);
|
|
211
|
-
|
|
212
|
-
const { component: RootComponent, props: rootSlotProps } = getSlotComponentWithProps(
|
|
213
|
-
slots,
|
|
214
|
-
slotProps || {},
|
|
215
|
-
'root',
|
|
216
|
-
Box,
|
|
217
|
-
{}
|
|
218
|
-
);
|
|
219
|
-
const { component: ToolbarComponent, props: toolbarSlotProps } = getSlotComponentWithProps(
|
|
220
|
-
slots,
|
|
221
|
-
slotProps || {},
|
|
222
|
-
'toolbar',
|
|
223
|
-
DataTableToolbar,
|
|
224
|
-
{}
|
|
225
|
-
);
|
|
226
|
-
const { component: BulkActionsComponent, props: bulkActionsSlotProps } = getSlotComponentWithProps(
|
|
227
|
-
slots,
|
|
228
|
-
slotProps || {},
|
|
229
|
-
'bulkActionsToolbar',
|
|
230
|
-
BulkActionsToolbar,
|
|
231
|
-
{}
|
|
232
|
-
);
|
|
233
|
-
const { component: TableContainerComponent, props: tableContainerSlotProps } = getSlotComponentWithProps(
|
|
234
|
-
slots,
|
|
235
|
-
slotProps || {},
|
|
236
|
-
'tableContainer',
|
|
237
|
-
TableContainer,
|
|
238
|
-
{}
|
|
239
|
-
);
|
|
240
|
-
const { component: TableComponent, props: tableComponentSlotProps } = getSlotComponentWithProps(
|
|
241
|
-
slots,
|
|
242
|
-
slotProps || {},
|
|
243
|
-
'table',
|
|
244
|
-
Table,
|
|
245
|
-
{}
|
|
246
|
-
);
|
|
247
|
-
const { component: BodyComponent, props: bodySlotProps } = getSlotComponentWithProps(
|
|
248
|
-
slots,
|
|
249
|
-
slotProps || {},
|
|
250
|
-
'body',
|
|
251
|
-
TableBody,
|
|
252
|
-
{}
|
|
253
|
-
);
|
|
254
|
-
const { component: FooterComponent, props: footerSlotProps } = getSlotComponentWithProps(
|
|
255
|
-
slots,
|
|
256
|
-
slotProps || {},
|
|
257
|
-
'footer',
|
|
258
|
-
Box,
|
|
259
|
-
{}
|
|
260
|
-
);
|
|
261
|
-
const { component: PaginationComponent, props: paginationSlotProps } = getSlotComponentWithProps(
|
|
262
|
-
slots,
|
|
263
|
-
slotProps || {},
|
|
264
|
-
'pagination',
|
|
265
|
-
DataTablePagination,
|
|
266
|
-
{}
|
|
267
|
-
);
|
|
268
|
-
|
|
269
|
-
return (
|
|
270
|
-
<RootComponent {...rootSlotProps}>
|
|
271
|
-
{(enableGlobalFilter || extraFilter) ? (
|
|
272
|
-
<ToolbarComponent
|
|
273
|
-
extraFilter={extraFilter}
|
|
274
|
-
enableGlobalFilter={enableGlobalFilter}
|
|
275
|
-
enableColumnVisibility={enableColumnVisibility}
|
|
276
|
-
enableColumnFilter={enableColumnFilter}
|
|
277
|
-
enableExport={enableExport}
|
|
278
|
-
enableReset={enableReset}
|
|
279
|
-
enableTableSizeControl={enableTableSizeControl}
|
|
280
|
-
enableColumnPinning={enableColumnPinning}
|
|
281
|
-
enableRefresh={enableRefresh}
|
|
282
|
-
{...toolbarSlotProps}
|
|
283
|
-
refreshButtonProps={{
|
|
284
|
-
loading: tableLoading,
|
|
285
|
-
showSpinnerWhileLoading: false,
|
|
286
|
-
onRefresh: () => apiRef.current?.data?.refresh?.(true),
|
|
287
|
-
...toolbarSlotProps.refreshButtonProps,
|
|
288
|
-
}}
|
|
289
|
-
/>
|
|
290
|
-
) : null}
|
|
291
|
-
|
|
292
|
-
{enableBulkActions && enableRowSelection && isSomeRowsSelected ? (
|
|
293
|
-
<BulkActionsComponent
|
|
294
|
-
selectionState={selectionState}
|
|
295
|
-
selectedRowCount={selectedRowCount}
|
|
296
|
-
bulkActions={bulkActions}
|
|
297
|
-
sx={{
|
|
298
|
-
position: 'relative',
|
|
299
|
-
zIndex: 2,
|
|
300
|
-
...bulkActionsSlotProps.sx,
|
|
301
|
-
}}
|
|
302
|
-
{...bulkActionsSlotProps}
|
|
303
|
-
/>
|
|
304
|
-
) : null}
|
|
305
|
-
|
|
306
|
-
<TableContainerComponent
|
|
307
|
-
component={Paper}
|
|
308
|
-
ref={tableContainerRef}
|
|
309
|
-
sx={{
|
|
310
|
-
width: '100%',
|
|
311
|
-
overflowX: 'auto',
|
|
312
|
-
...(enableStickyHeaderOrFooter && {
|
|
313
|
-
maxHeight,
|
|
314
|
-
overflowY: 'auto',
|
|
315
|
-
}),
|
|
316
|
-
...(enableVirtualization && {
|
|
317
|
-
maxHeight,
|
|
318
|
-
overflowY: 'auto',
|
|
319
|
-
}),
|
|
320
|
-
...tableContainerSlotProps?.sx,
|
|
321
|
-
}}
|
|
322
|
-
{...tableContainerSlotProps}
|
|
323
|
-
>
|
|
324
|
-
<TableComponent
|
|
325
|
-
size={tableSize}
|
|
326
|
-
stickyHeader={enableStickyHeaderOrFooter}
|
|
327
|
-
style={{
|
|
328
|
-
...tableStyle,
|
|
329
|
-
...tableProps?.style,
|
|
330
|
-
}}
|
|
331
|
-
{...mergeSlotProps(tableProps || {}, tableComponentSlotProps)}
|
|
332
|
-
>
|
|
333
|
-
{useFixedLayout ? (
|
|
334
|
-
<colgroup>
|
|
335
|
-
{visibleLeafColumns().map((column) => (
|
|
336
|
-
<col
|
|
337
|
-
key={column.id}
|
|
338
|
-
style={{
|
|
339
|
-
width: column.getSize(),
|
|
340
|
-
minWidth: column.columnDef.minSize,
|
|
341
|
-
maxWidth: column.columnDef.maxSize,
|
|
342
|
-
}}
|
|
343
|
-
/>
|
|
344
|
-
))}
|
|
345
|
-
</colgroup>
|
|
346
|
-
) : null}
|
|
347
|
-
<TableHeader
|
|
348
|
-
draggable={enableColumnDragging}
|
|
349
|
-
enableColumnResizing={enableColumnResizing}
|
|
350
|
-
enableStickyHeader={enableStickyHeaderOrFooter}
|
|
351
|
-
onColumnReorder={handleColumnReorder}
|
|
352
|
-
slots={slots}
|
|
353
|
-
slotProps={slotProps}
|
|
354
|
-
/>
|
|
355
|
-
<BodyComponent {...bodySlotProps}>
|
|
356
|
-
{renderTableRows()}
|
|
357
|
-
</BodyComponent>
|
|
358
|
-
</TableComponent>
|
|
359
|
-
</TableContainerComponent>
|
|
360
|
-
|
|
361
|
-
{enablePagination ? (
|
|
362
|
-
<FooterComponent
|
|
363
|
-
sx={{
|
|
364
|
-
...(enableStickyHeaderOrFooter && {
|
|
365
|
-
position: 'sticky',
|
|
366
|
-
bottom: 0,
|
|
367
|
-
backgroundColor: 'background.paper',
|
|
368
|
-
borderTop: '1px solid',
|
|
369
|
-
borderColor: 'divider',
|
|
370
|
-
zIndex: 1,
|
|
371
|
-
}),
|
|
372
|
-
...footerSlotProps.sx,
|
|
373
|
-
}}
|
|
374
|
-
{...footerSlotProps}
|
|
375
|
-
>
|
|
376
|
-
<PaginationComponent
|
|
377
|
-
footerFilter={footerFilter}
|
|
378
|
-
pagination={pagination}
|
|
379
|
-
totalRow={tableTotalRow}
|
|
380
|
-
{...paginationSlotProps}
|
|
381
|
-
/>
|
|
382
|
-
</FooterComponent>
|
|
383
|
-
) : null}
|
|
384
|
-
</RootComponent>
|
|
385
|
-
);
|
|
386
|
-
}
|
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
import { Button, Menu, MenuProps, Popover } from '@mui/material';
|
|
2
|
-
import React, {
|
|
3
|
-
cloneElement,
|
|
4
|
-
ReactElement,
|
|
5
|
-
ReactNode,
|
|
6
|
-
useCallback,
|
|
7
|
-
useMemo,
|
|
8
|
-
useState,
|
|
9
|
-
} from 'react';
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
type ChildrenEvent = {
|
|
13
|
-
handleClose: () => void;
|
|
14
|
-
open: boolean;
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
type AnchorEvent = {
|
|
18
|
-
isOpen: boolean;
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
export interface MenuDropdownProps
|
|
22
|
-
extends Omit<MenuProps, 'children' | 'open'> {
|
|
23
|
-
children?: ((event: ChildrenEvent) => ReactNode) | ReactNode | any;
|
|
24
|
-
anchor?: ((event: AnchorEvent) => ReactElement<any>) | ReactElement<any>;
|
|
25
|
-
label?: ReactNode;
|
|
26
|
-
component?: typeof Popover | typeof Menu;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export function MenuDropdown({
|
|
30
|
-
children,
|
|
31
|
-
anchor,
|
|
32
|
-
label,
|
|
33
|
-
component,
|
|
34
|
-
...props
|
|
35
|
-
}: MenuDropdownProps): ReactElement {
|
|
36
|
-
const [anchorEl, setAnchorEl] = useState<null | HTMLElement>(null);
|
|
37
|
-
const isOpen = useMemo(() => Boolean(anchorEl), [anchorEl]);
|
|
38
|
-
const handleClick = useCallback(
|
|
39
|
-
(event: React.MouseEvent<HTMLElement>) => {
|
|
40
|
-
event.preventDefault();
|
|
41
|
-
event.stopPropagation();
|
|
42
|
-
setAnchorEl(event.currentTarget as HTMLElement);
|
|
43
|
-
},
|
|
44
|
-
[],
|
|
45
|
-
);
|
|
46
|
-
const handleClose = useCallback((event:any) => {
|
|
47
|
-
event?.preventDefault();
|
|
48
|
-
event?.stopPropagation();
|
|
49
|
-
setAnchorEl(null);
|
|
50
|
-
}, []);
|
|
51
|
-
const anchorNode = useMemo(() => {
|
|
52
|
-
if (anchor) {
|
|
53
|
-
let node = anchor;
|
|
54
|
-
if (typeof anchor === 'function') {
|
|
55
|
-
node = anchor({ isOpen: isOpen });
|
|
56
|
-
}
|
|
57
|
-
const existingOnClick = (node as ReactElement<any>).props?.onClick;
|
|
58
|
-
return cloneElement(node as ReactElement<any>, {
|
|
59
|
-
onClick: (event: React.MouseEvent<HTMLElement>) => {
|
|
60
|
-
existingOnClick?.(event);
|
|
61
|
-
if (!event.defaultPrevented) {
|
|
62
|
-
handleClick(event);
|
|
63
|
-
}
|
|
64
|
-
},
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
return <Button onClick={handleClick}>{label as any}</Button>;
|
|
68
|
-
}, [
|
|
69
|
-
anchor,
|
|
70
|
-
handleClick,
|
|
71
|
-
isOpen,
|
|
72
|
-
label,
|
|
73
|
-
]);
|
|
74
|
-
|
|
75
|
-
const DropDownComponent = (component || Popover) as React.ComponentType<any>;
|
|
76
|
-
|
|
77
|
-
return (
|
|
78
|
-
<>
|
|
79
|
-
{anchorNode}
|
|
80
|
-
<DropDownComponent
|
|
81
|
-
anchorEl={anchorEl}
|
|
82
|
-
open={isOpen}
|
|
83
|
-
onClose={handleClose}
|
|
84
|
-
anchorOrigin={{
|
|
85
|
-
vertical: 'bottom',
|
|
86
|
-
horizontal: 'left',
|
|
87
|
-
}}
|
|
88
|
-
transformOrigin={{
|
|
89
|
-
vertical: 'top',
|
|
90
|
-
horizontal: 'left',
|
|
91
|
-
}}
|
|
92
|
-
{...props}
|
|
93
|
-
>
|
|
94
|
-
{typeof children === 'function' ?
|
|
95
|
-
children({
|
|
96
|
-
handleClose,
|
|
97
|
-
open: isOpen,
|
|
98
|
-
}) :
|
|
99
|
-
children}
|
|
100
|
-
</DropDownComponent>
|
|
101
|
-
</>
|
|
102
|
-
);
|
|
103
|
-
}
|