@ackplus/react-tanstack-data-table 1.0.19-beta-0.9 → 1.0.19-beta-0.12
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 +4 -4
- package/package.json +1 -1
- package/src/index.d.ts +1 -0
- package/src/index.js +3 -1
- package/src/lib/components/table/data-table.d.ts +2 -1
- package/src/lib/components/table/data-table.js +141 -121
- 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/components/toolbar/table-export-control.js +18 -6
- 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/index.d.ts +1 -0
- package/src/lib/examples/index.js +3 -1
- package/src/lib/examples/server-side-fetching-example.d.ts +1 -0
- package/src/lib/examples/server-side-fetching-example.js +250 -0
- package/src/lib/examples/server-side-test.d.ts +1 -0
- package/src/lib/examples/server-side-test.js +9 -0
- 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} +22 -10
- package/src/lib/hooks/use-data-table-api.d.ts +6 -6
- package/src/lib/hooks/use-data-table-api.js +20 -20
- 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 +47 -24
- package/src/lib/components/toolbar/column-custom-filter-control.d.ts +0 -1
package/src/lib/components/toolbar/{column-custom-filter-control.js → column-filter-control.js}
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.ColumnFilterControl = ColumnFilterControl;
|
|
4
4
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
5
|
const icons_material_1 = require("@mui/icons-material");
|
|
6
6
|
const material_1 = require("@mui/material");
|
|
@@ -12,51 +12,51 @@ const column_helpers_1 = require("../../utils/column-helpers");
|
|
|
12
12
|
const slot_helpers_1 = require("../../utils/slot-helpers");
|
|
13
13
|
const filters_1 = require("../filters");
|
|
14
14
|
const filter_value_input_1 = require("../filters/filter-value-input");
|
|
15
|
-
function
|
|
15
|
+
function ColumnFilterControl() {
|
|
16
16
|
var _a, _b, _c;
|
|
17
17
|
const { table, slots, slotProps } = (0, data_table_context_1.useDataTableContext)();
|
|
18
18
|
const FilterIconSlot = (0, slot_helpers_1.getSlotComponent)(slots, 'filterIcon', icons_material_1.FilterList);
|
|
19
|
-
const
|
|
19
|
+
const filterState = ((_a = table === null || table === void 0 ? void 0 : table.getColumnFilterState) === null || _a === void 0 ? void 0 : _a.call(table)) || {
|
|
20
20
|
filters: [],
|
|
21
21
|
logic: 'AND',
|
|
22
22
|
pendingFilters: [],
|
|
23
23
|
pendingLogic: 'AND'
|
|
24
24
|
};
|
|
25
|
-
const filters =
|
|
26
|
-
const filterLogic =
|
|
27
|
-
const activeFiltersCount = ((_c = (_b = table.getActiveColumnFilters) === null || _b === void 0 ? void 0 : _b.call(table)) === null || _c === void 0 ? void 0 : _c.length) || 0;
|
|
25
|
+
const filters = filterState.pendingFilters;
|
|
26
|
+
const filterLogic = filterState.pendingLogic;
|
|
27
|
+
const activeFiltersCount = ((_c = (_b = table === null || table === void 0 ? void 0 : table.getActiveColumnFilters) === null || _b === void 0 ? void 0 : _b.call(table)) === null || _c === void 0 ? void 0 : _c.length) || 0;
|
|
28
28
|
const filterableColumns = (0, react_1.useMemo)(() => {
|
|
29
|
-
return table.getAllLeafColumns()
|
|
30
|
-
.filter(column => (0, column_helpers_1.isColumnFilterable)(column));
|
|
29
|
+
return table === null || table === void 0 ? void 0 : table.getAllLeafColumns().filter(column => (0, column_helpers_1.isColumnFilterable)(column));
|
|
31
30
|
}, [table]);
|
|
32
31
|
const addFilter = (0, react_1.useCallback)((columnId, operator) => {
|
|
33
32
|
var _a, _b;
|
|
34
33
|
let defaultOperator = operator || '';
|
|
34
|
+
console.log('addFilter', columnId, operator, filterableColumns);
|
|
35
35
|
if (columnId && !operator) {
|
|
36
|
-
const column = filterableColumns.find(col => col.id === columnId);
|
|
36
|
+
const column = filterableColumns === null || filterableColumns === void 0 ? void 0 : filterableColumns.find(col => col.id === columnId);
|
|
37
37
|
const columnType = (0, column_helpers_1.getColumnType)(column);
|
|
38
38
|
const operators = filters_1.FILTER_OPERATORS[columnType] || filters_1.FILTER_OPERATORS.text;
|
|
39
39
|
defaultOperator = ((_a = operators[0]) === null || _a === void 0 ? void 0 : _a.value) || 'contains';
|
|
40
40
|
}
|
|
41
|
-
(_b = table.addPendingColumnFilter) === null || _b === void 0 ? void 0 : _b.call(table, columnId || '', defaultOperator, '');
|
|
41
|
+
(_b = table === null || table === void 0 ? void 0 : table.addPendingColumnFilter) === null || _b === void 0 ? void 0 : _b.call(table, columnId || '', defaultOperator, '');
|
|
42
42
|
}, [table, filterableColumns]);
|
|
43
43
|
const handleAddFilter = (0, react_1.useCallback)(() => {
|
|
44
44
|
addFilter();
|
|
45
45
|
}, [addFilter]);
|
|
46
46
|
const updateFilter = (0, react_1.useCallback)((filterId, updates) => {
|
|
47
47
|
var _a;
|
|
48
|
-
(_a = table.updatePendingColumnFilter) === null || _a === void 0 ? void 0 : _a.call(table, filterId, updates);
|
|
48
|
+
(_a = table === null || table === void 0 ? void 0 : table.updatePendingColumnFilter) === null || _a === void 0 ? void 0 : _a.call(table, filterId, updates);
|
|
49
49
|
}, [table]);
|
|
50
50
|
const removeFilter = (0, react_1.useCallback)((filterId) => {
|
|
51
51
|
var _a;
|
|
52
|
-
(_a = table.removePendingColumnFilter) === null || _a === void 0 ? void 0 : _a.call(table, filterId);
|
|
52
|
+
(_a = table === null || table === void 0 ? void 0 : table.removePendingColumnFilter) === null || _a === void 0 ? void 0 : _a.call(table, filterId);
|
|
53
53
|
}, [table]);
|
|
54
54
|
const clearAllFilters = (0, react_1.useCallback)((closeDialog) => {
|
|
55
55
|
var _a;
|
|
56
|
-
(_a = table.clearAllPendingColumnFilters) === null || _a === void 0 ? void 0 : _a.call(table);
|
|
56
|
+
(_a = table === null || table === void 0 ? void 0 : table.clearAllPendingColumnFilters) === null || _a === void 0 ? void 0 : _a.call(table);
|
|
57
57
|
setTimeout(() => {
|
|
58
58
|
var _a;
|
|
59
|
-
(_a = table.applyPendingColumnFilters) === null || _a === void 0 ? void 0 : _a.call(table);
|
|
59
|
+
(_a = table === null || table === void 0 ? void 0 : table.applyPendingColumnFilters) === null || _a === void 0 ? void 0 : _a.call(table);
|
|
60
60
|
if (closeDialog) {
|
|
61
61
|
closeDialog();
|
|
62
62
|
}
|
|
@@ -64,24 +64,24 @@ function ColumnCustomFilterControl() {
|
|
|
64
64
|
}, [table]);
|
|
65
65
|
const handleLogicChange = (0, react_1.useCallback)((newLogic) => {
|
|
66
66
|
var _a;
|
|
67
|
-
(_a = table.setPendingFilterLogic) === null || _a === void 0 ? void 0 : _a.call(table, newLogic);
|
|
67
|
+
(_a = table === null || table === void 0 ? void 0 : table.setPendingFilterLogic) === null || _a === void 0 ? void 0 : _a.call(table, newLogic);
|
|
68
68
|
}, [table]);
|
|
69
69
|
const applyFilters = (0, react_1.useCallback)(() => {
|
|
70
70
|
var _a;
|
|
71
|
-
(_a = table.applyPendingColumnFilters) === null || _a === void 0 ? void 0 : _a.call(table);
|
|
71
|
+
(_a = table === null || table === void 0 ? void 0 : table.applyPendingColumnFilters) === null || _a === void 0 ? void 0 : _a.call(table);
|
|
72
72
|
}, [table]);
|
|
73
73
|
const handleApplyFilters = (0, react_1.useCallback)((closeDialog) => {
|
|
74
74
|
applyFilters();
|
|
75
75
|
closeDialog();
|
|
76
76
|
}, [applyFilters]);
|
|
77
77
|
const getOperatorsForColumn = (0, react_1.useCallback)((columnId) => {
|
|
78
|
-
const column = filterableColumns.find(col => col.id === columnId);
|
|
78
|
+
const column = filterableColumns === null || filterableColumns === void 0 ? void 0 : filterableColumns.find(col => col.id === columnId);
|
|
79
79
|
const type = (0, column_helpers_1.getColumnType)(column);
|
|
80
80
|
return filters_1.FILTER_OPERATORS[type] || filters_1.FILTER_OPERATORS.text;
|
|
81
81
|
}, [filterableColumns]);
|
|
82
82
|
const handleColumnChange = (0, react_1.useCallback)((filterId, newColumnId, currentFilter) => {
|
|
83
83
|
var _a;
|
|
84
|
-
const newColumn = filterableColumns.find(col => col.id === newColumnId);
|
|
84
|
+
const newColumn = filterableColumns === null || filterableColumns === void 0 ? void 0 : filterableColumns.find(col => col.id === newColumnId);
|
|
85
85
|
const columnType = (0, column_helpers_1.getColumnType)(newColumn);
|
|
86
86
|
const operators = filters_1.FILTER_OPERATORS[columnType] || filters_1.FILTER_OPERATORS.text;
|
|
87
87
|
const currentOperatorValid = operators.some(op => op.value === currentFilter.operator);
|
|
@@ -115,12 +115,14 @@ function ColumnCustomFilterControl() {
|
|
|
115
115
|
const hasPendingChanges = pendingFiltersCount > 0 || (filters.length === 0 && hasAppliedFilters);
|
|
116
116
|
(0, react_1.useEffect)(() => {
|
|
117
117
|
var _a;
|
|
118
|
-
|
|
118
|
+
console.log('useEffect', filters.length, filterableColumns, { activeFiltersCount });
|
|
119
|
+
if (filters.length === 0 && filterableColumns && (filterableColumns === null || filterableColumns === void 0 ? void 0 : filterableColumns.length) > 0 && activeFiltersCount === 0) {
|
|
119
120
|
const firstColumn = filterableColumns[0];
|
|
120
121
|
const columnType = (0, column_helpers_1.getColumnType)(firstColumn);
|
|
121
122
|
const operators = filters_1.FILTER_OPERATORS[columnType] || filters_1.FILTER_OPERATORS.text;
|
|
122
123
|
const defaultOperator = ((_a = operators[0]) === null || _a === void 0 ? void 0 : _a.value) || 'contains';
|
|
123
|
-
|
|
124
|
+
console.log('useEffect', firstColumn, columnType, operators, defaultOperator);
|
|
125
|
+
addFilter(firstColumn === null || firstColumn === void 0 ? void 0 : firstColumn.id, defaultOperator);
|
|
124
126
|
}
|
|
125
127
|
}, [filters.length, filterableColumns, addFilter, activeFiltersCount]);
|
|
126
128
|
return ((0, jsx_runtime_1.jsx)(menu_dropdown_1.MenuDropdown, { anchor: ((0, jsx_runtime_1.jsx)(material_1.Badge, { variant: "dot", color: "primary", invisible: activeFiltersCount === 0, children: (0, jsx_runtime_1.jsx)(material_1.IconButton, { size: "small", color: activeFiltersCount > 0 ? 'primary' : 'default', sx: {
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.DataTableToolbar = DataTableToolbar;
|
|
4
4
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
5
|
const material_1 = require("@mui/material");
|
|
6
|
-
const
|
|
6
|
+
const column_filter_control_1 = require("./column-filter-control");
|
|
7
7
|
const column_pinning_control_1 = require("./column-pinning-control");
|
|
8
8
|
const column_reset_control_1 = require("./column-reset-control");
|
|
9
9
|
const column_visibility_control_1 = require("./column-visibility-control");
|
|
@@ -17,7 +17,7 @@ function DataTableToolbar({ extraFilter = null, enableGlobalFilter = true, title
|
|
|
17
17
|
const ToolbarSlot = (0, slot_helpers_1.getSlotComponent)(slots, 'toolbar', material_1.Toolbar);
|
|
18
18
|
const TableSearchControlSlot = (0, slot_helpers_1.getSlotComponent)(slots, 'searchInput', table_search_control_1.TableSearchControl);
|
|
19
19
|
const TableSizeControlSlot = (0, slot_helpers_1.getSlotComponent)(slots, 'tableSizeControl', table_size_control_1.TableSizeControl);
|
|
20
|
-
const ColumnCustomFilterControlSlot = (0, slot_helpers_1.getSlotComponent)(slots, 'columnCustomFilterControl',
|
|
20
|
+
const ColumnCustomFilterControlSlot = (0, slot_helpers_1.getSlotComponent)(slots, 'columnCustomFilterControl', column_filter_control_1.ColumnFilterControl);
|
|
21
21
|
const ColumnPinningControlSlot = (0, slot_helpers_1.getSlotComponent)(slots, 'columnPinningControl', column_pinning_control_1.ColumnPinningControl);
|
|
22
22
|
const ColumnVisibilityControlSlot = (0, slot_helpers_1.getSlotComponent)(slots, 'columnVisibilityControl', column_visibility_control_1.ColumnVisibilityControl);
|
|
23
23
|
const ColumnResetControlSlot = (0, slot_helpers_1.getSlotComponent)(slots, 'resetButton', column_reset_control_1.ColumnResetControl);
|
|
@@ -4,5 +4,6 @@ export { ColumnPinningControl } from './column-pinning-control';
|
|
|
4
4
|
export { ColumnResetControl } from './column-reset-control';
|
|
5
5
|
export { TableExportControl } from './table-export-control';
|
|
6
6
|
export { TableSizeControl } from './table-size-control';
|
|
7
|
+
export { ColumnFilterControl } from './column-filter-control';
|
|
7
8
|
export { BulkActionsToolbar } from './bulk-actions-toolbar';
|
|
8
9
|
export type { BulkActionsToolbarProps } from './bulk-actions-toolbar';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.BulkActionsToolbar = exports.TableSizeControl = exports.TableExportControl = exports.ColumnResetControl = exports.ColumnPinningControl = exports.ColumnVisibilityControl = exports.DataTableToolbar = void 0;
|
|
3
|
+
exports.BulkActionsToolbar = exports.ColumnFilterControl = exports.TableSizeControl = exports.TableExportControl = exports.ColumnResetControl = exports.ColumnPinningControl = exports.ColumnVisibilityControl = exports.DataTableToolbar = void 0;
|
|
4
4
|
var data_table_toolbar_1 = require("./data-table-toolbar");
|
|
5
5
|
Object.defineProperty(exports, "DataTableToolbar", { enumerable: true, get: function () { return data_table_toolbar_1.DataTableToolbar; } });
|
|
6
6
|
var column_visibility_control_1 = require("./column-visibility-control");
|
|
@@ -13,5 +13,7 @@ var table_export_control_1 = require("./table-export-control");
|
|
|
13
13
|
Object.defineProperty(exports, "TableExportControl", { enumerable: true, get: function () { return table_export_control_1.TableExportControl; } });
|
|
14
14
|
var table_size_control_1 = require("./table-size-control");
|
|
15
15
|
Object.defineProperty(exports, "TableSizeControl", { enumerable: true, get: function () { return table_size_control_1.TableSizeControl; } });
|
|
16
|
+
var column_filter_control_1 = require("./column-filter-control");
|
|
17
|
+
Object.defineProperty(exports, "ColumnFilterControl", { enumerable: true, get: function () { return column_filter_control_1.ColumnFilterControl; } });
|
|
16
18
|
var bulk_actions_toolbar_1 = require("./bulk-actions-toolbar");
|
|
17
19
|
Object.defineProperty(exports, "BulkActionsToolbar", { enumerable: true, get: function () { return bulk_actions_toolbar_1.BulkActionsToolbar; } });
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { TableFilters } from '../../types';
|
|
2
|
-
import { SelectionState } from '../../features
|
|
2
|
+
import { SelectionState } from '../../features';
|
|
3
3
|
interface TableExportControlProps {
|
|
4
4
|
exportFilename?: string;
|
|
5
5
|
onServerExport?: (filters?: Partial<TableFilters>, selection?: SelectionState) => Promise<{
|
|
@@ -7,9 +7,9 @@ interface TableExportControlProps {
|
|
|
7
7
|
total: number;
|
|
8
8
|
}>;
|
|
9
9
|
onExportProgress?: (progress: {
|
|
10
|
-
processedRows
|
|
11
|
-
totalRows
|
|
12
|
-
percentage
|
|
10
|
+
processedRows?: number;
|
|
11
|
+
totalRows?: number;
|
|
12
|
+
percentage?: number;
|
|
13
13
|
}) => void;
|
|
14
14
|
onExportComplete?: (result: {
|
|
15
15
|
success: boolean;
|
|
@@ -23,6 +23,7 @@ function TableExportControl({ exportFilename: propsExportFilename, onServerExpor
|
|
|
23
23
|
const handleExport = (format) => tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
24
24
|
var _a, _b;
|
|
25
25
|
try {
|
|
26
|
+
console.log('handleExport', dataMode, onServerExport);
|
|
26
27
|
if (dataMode === 'server' && onServerExport) {
|
|
27
28
|
const currentState = table.getState();
|
|
28
29
|
const currentFilters = {
|
|
@@ -60,12 +61,23 @@ function TableExportControl({ exportFilename: propsExportFilename, onServerExpor
|
|
|
60
61
|
});
|
|
61
62
|
}
|
|
62
63
|
});
|
|
63
|
-
const selectedRowCount =
|
|
64
|
+
const selectedRowCount = table.getSelectedCount ? table.getSelectedCount() : 0;
|
|
65
|
+
const hasSelection = table.getIsSomeRowsSelected ? table.getIsSomeRowsSelected() : false;
|
|
66
|
+
const visibleColumns = table.getVisibleLeafColumns().filter(col => col.getIsVisible());
|
|
67
|
+
const exportableColumns = visibleColumns.filter(col => {
|
|
68
|
+
const columnDef = col.columnDef;
|
|
69
|
+
return columnDef.hideInExport !== true;
|
|
70
|
+
});
|
|
71
|
+
const hiddenFromExportColumns = visibleColumns.filter(col => {
|
|
72
|
+
const columnDef = col.columnDef;
|
|
73
|
+
return columnDef.hideInExport === true;
|
|
74
|
+
});
|
|
64
75
|
const summary = {
|
|
65
76
|
filteredRows: table.getFilteredRowModel().rows.length,
|
|
66
|
-
totalColumns:
|
|
77
|
+
totalColumns: exportableColumns.length,
|
|
78
|
+
hiddenColumns: hiddenFromExportColumns.length,
|
|
67
79
|
selectedRows: selectedRowCount,
|
|
68
|
-
hasSelection:
|
|
80
|
+
hasSelection: hasSelection,
|
|
69
81
|
};
|
|
70
82
|
return ((0, jsx_runtime_1.jsx)(menu_dropdown_1.MenuDropdown, { anchor: ((0, jsx_runtime_1.jsx)(material_1.Tooltip, { title: "Export data", children: (0, jsx_runtime_1.jsx)(material_1.IconButton, { size: "small", disabled: isExporting, sx: {
|
|
71
83
|
flexShrink: 0,
|
|
@@ -78,9 +90,9 @@ function TableExportControl({ exportFilename: propsExportFilename, onServerExpor
|
|
|
78
90
|
p: 1,
|
|
79
91
|
bgcolor: 'grey.50',
|
|
80
92
|
borderRadius: 1,
|
|
81
|
-
}, children: [(0, jsx_runtime_1.jsx)(material_1.Typography, { variant: "subtitle2", gutterBottom: true, children: "Export Summary" }), (0, jsx_runtime_1.
|
|
82
|
-
|
|
83
|
-
|
|
93
|
+
}, children: [(0, jsx_runtime_1.jsx)(material_1.Typography, { variant: "subtitle2", gutterBottom: true, children: "Export Summary" }), (0, jsx_runtime_1.jsxs)(material_1.Typography, { variant: "body2", color: "text.secondary", children: [summary.hasSelection
|
|
94
|
+
? `${summary.selectedRows} selected • ${summary.totalColumns} exportable columns`
|
|
95
|
+
: `${summary.filteredRows} filtered • ${summary.totalColumns} exportable columns`, summary.hiddenColumns > 0 && ((0, jsx_runtime_1.jsxs)("span", { style: { color: 'orange' }, children: [' ', "\u2022 ", summary.hiddenColumns, " hidden from export"] }))] }), summary.hasSelection ? ((0, jsx_runtime_1.jsx)(material_1.Typography, { variant: "caption", color: "primary.main", sx: { fontWeight: 'medium' }, children: "Will export selected rows only" })) : null] }), isExporting ? ((0, jsx_runtime_1.jsxs)(material_1.MenuItem, { onClick: () => {
|
|
84
96
|
onCancelExport === null || onCancelExport === void 0 ? void 0 : onCancelExport();
|
|
85
97
|
handleClose();
|
|
86
98
|
}, children: [(0, jsx_runtime_1.jsx)(material_1.ListItemIcon, { children: (0, jsx_runtime_1.jsx)(ExportIconSlot, Object.assign({ fontSize: "small", color: "warning" }, slotProps === null || slotProps === void 0 ? void 0 : slotProps.exportIcon)) }), (0, jsx_runtime_1.jsx)(material_1.ListItemText, { primary: "Cancel Export", secondary: "Stop current export" })] })) : ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsxs)(material_1.MenuItem, { onClick: () => tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { Table } from '@tanstack/react-table';
|
|
2
2
|
import { ReactNode, RefObject } from 'react';
|
|
3
|
-
import {
|
|
3
|
+
import { ColumnFilterState, TableSize } from '../types';
|
|
4
4
|
import { DataTableApi } from '../types/data-table-api';
|
|
5
5
|
interface DataTableContextValue<T = any> {
|
|
6
6
|
table?: Table<T>;
|
|
7
|
-
apiRef?: RefObject<DataTableApi<T
|
|
7
|
+
apiRef?: RefObject<DataTableApi<T> | null>;
|
|
8
8
|
dataMode?: 'client' | 'server';
|
|
9
9
|
tableSize?: TableSize;
|
|
10
10
|
onTableSizeChange?: (size: TableSize) => void;
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
columnFilter?: ColumnFilterState;
|
|
12
|
+
onChangeColumnFilter?: (filter: ColumnFilterState) => void;
|
|
13
13
|
slots?: Record<string, any>;
|
|
14
14
|
slotProps?: Record<string, any>;
|
|
15
15
|
isExporting?: boolean;
|
|
@@ -17,9 +17,9 @@ interface DataTableContextValue<T = any> {
|
|
|
17
17
|
onCancelExport?: () => void;
|
|
18
18
|
exportFilename?: string;
|
|
19
19
|
onExportProgress?: (progress: {
|
|
20
|
-
processedRows
|
|
21
|
-
totalRows
|
|
22
|
-
percentage
|
|
20
|
+
processedRows?: number;
|
|
21
|
+
totalRows?: number;
|
|
22
|
+
percentage?: number;
|
|
23
23
|
}) => void;
|
|
24
24
|
onExportComplete?: (result: {
|
|
25
25
|
success: boolean;
|
|
@@ -38,6 +38,6 @@ interface DataTableContextValue<T = any> {
|
|
|
38
38
|
interface DataTableProviderProps<T = any> extends DataTableContextValue<T> {
|
|
39
39
|
children: ReactNode;
|
|
40
40
|
}
|
|
41
|
-
export declare function DataTableProvider<T = any>({ children, table, apiRef, dataMode, tableSize, onTableSizeChange,
|
|
41
|
+
export declare function DataTableProvider<T = any>({ children, table, apiRef, dataMode, tableSize, onTableSizeChange, columnFilter, onChangeColumnFilter, slots, slotProps, isExporting, exportController, onCancelExport, exportFilename, onExportProgress, onExportComplete, onExportError, onServerExport, }: DataTableProviderProps<T>): import("react/jsx-runtime").JSX.Element;
|
|
42
42
|
export declare function useDataTableContext<T = any>(): DataTableContextValue<T>;
|
|
43
43
|
export {};
|
|
@@ -5,15 +5,15 @@ exports.useDataTableContext = useDataTableContext;
|
|
|
5
5
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
6
6
|
const react_1 = require("react");
|
|
7
7
|
const DataTableContext = (0, react_1.createContext)(null);
|
|
8
|
-
function DataTableProvider({ children, table, apiRef, dataMode, tableSize, onTableSizeChange,
|
|
8
|
+
function DataTableProvider({ children, table, apiRef, dataMode, tableSize, onTableSizeChange, columnFilter, onChangeColumnFilter, slots = {}, slotProps = {}, isExporting, exportController, onCancelExport, exportFilename, onExportProgress, onExportComplete, onExportError, onServerExport, }) {
|
|
9
9
|
const value = (0, react_1.useMemo)(() => ({
|
|
10
10
|
table,
|
|
11
11
|
apiRef,
|
|
12
12
|
dataMode,
|
|
13
13
|
tableSize,
|
|
14
14
|
onTableSizeChange,
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
columnFilter,
|
|
16
|
+
onChangeColumnFilter,
|
|
17
17
|
slots,
|
|
18
18
|
slotProps,
|
|
19
19
|
isExporting,
|
|
@@ -30,8 +30,8 @@ function DataTableProvider({ children, table, apiRef, dataMode, tableSize, onTab
|
|
|
30
30
|
dataMode,
|
|
31
31
|
tableSize,
|
|
32
32
|
onTableSizeChange,
|
|
33
|
-
|
|
34
|
-
|
|
33
|
+
columnFilter,
|
|
34
|
+
onChangeColumnFilter,
|
|
35
35
|
slots,
|
|
36
36
|
slotProps,
|
|
37
37
|
isExporting,
|
|
@@ -3,3 +3,4 @@ export { SelectionTestExample } from './selection-test-example';
|
|
|
3
3
|
export { AdvancedFeaturesExample } from './advanced-features-example';
|
|
4
4
|
export { SimpleLocalExample } from './simple-local-example';
|
|
5
5
|
export { BulkActionsTest } from './bulk-actions-test';
|
|
6
|
+
export { ServerSideFetchingExample } from './server-side-fetching-example';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.BulkActionsTest = exports.SimpleLocalExample = exports.AdvancedFeaturesExample = exports.SelectionTestExample = exports.CustomColumnFilterExample = void 0;
|
|
3
|
+
exports.ServerSideFetchingExample = exports.BulkActionsTest = exports.SimpleLocalExample = exports.AdvancedFeaturesExample = exports.SelectionTestExample = exports.CustomColumnFilterExample = void 0;
|
|
4
4
|
var custom_column_filter_example_1 = require("./custom-column-filter-example");
|
|
5
5
|
Object.defineProperty(exports, "CustomColumnFilterExample", { enumerable: true, get: function () { return custom_column_filter_example_1.CustomColumnFilterExample; } });
|
|
6
6
|
var selection_test_example_1 = require("./selection-test-example");
|
|
@@ -11,3 +11,5 @@ var simple_local_example_1 = require("./simple-local-example");
|
|
|
11
11
|
Object.defineProperty(exports, "SimpleLocalExample", { enumerable: true, get: function () { return simple_local_example_1.SimpleLocalExample; } });
|
|
12
12
|
var bulk_actions_test_1 = require("./bulk-actions-test");
|
|
13
13
|
Object.defineProperty(exports, "BulkActionsTest", { enumerable: true, get: function () { return bulk_actions_test_1.BulkActionsTest; } });
|
|
14
|
+
var server_side_fetching_example_1 = require("./server-side-fetching-example");
|
|
15
|
+
Object.defineProperty(exports, "ServerSideFetchingExample", { enumerable: true, get: function () { return server_side_fetching_example_1.ServerSideFetchingExample; } });
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function ServerSideFetchingExample(): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ServerSideFetchingExample = ServerSideFetchingExample;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
6
|
+
const react_1 = require("react");
|
|
7
|
+
const material_1 = require("@mui/material");
|
|
8
|
+
const data_table_1 = require("../components/table/data-table");
|
|
9
|
+
const MOCK_EMPLOYEES = Array.from({ length: 1000 }, (_, index) => {
|
|
10
|
+
const departments = ['Engineering', 'Marketing', 'Sales', 'HR', 'Finance', 'Operations'];
|
|
11
|
+
const roles = ['Manager', 'Senior', 'Junior', 'Lead', 'Director', 'Specialist'];
|
|
12
|
+
const firstNames = ['John', 'Jane', 'Bob', 'Alice', 'Charlie', 'Diana', 'Eve', 'Frank', 'Grace', 'Henry'];
|
|
13
|
+
const lastNames = ['Smith', 'Johnson', 'Williams', 'Brown', 'Jones', 'Garcia', 'Miller', 'Davis', 'Rodriguez', 'Martinez'];
|
|
14
|
+
const firstName = firstNames[Math.floor(Math.random() * firstNames.length)];
|
|
15
|
+
const lastName = lastNames[Math.floor(Math.random() * lastNames.length)];
|
|
16
|
+
return {
|
|
17
|
+
id: index + 1,
|
|
18
|
+
name: `${firstName} ${lastName}`,
|
|
19
|
+
email: `${firstName.toLowerCase()}.${lastName.toLowerCase()}@company.com`,
|
|
20
|
+
department: departments[Math.floor(Math.random() * departments.length)],
|
|
21
|
+
role: roles[Math.floor(Math.random() * roles.length)],
|
|
22
|
+
salary: Math.floor(Math.random() * 80000) + 40000,
|
|
23
|
+
isActive: Math.random() > 0.15,
|
|
24
|
+
joinDate: new Date(2020 + Math.floor(Math.random() * 4), Math.floor(Math.random() * 12), Math.floor(Math.random() * 28) + 1).toISOString().split('T')[0],
|
|
25
|
+
};
|
|
26
|
+
});
|
|
27
|
+
function ServerSideFetchingExample() {
|
|
28
|
+
const [loading, setLoading] = (0, react_1.useState)(false);
|
|
29
|
+
const [error, setError] = (0, react_1.useState)(null);
|
|
30
|
+
const [selectionInfo, setSelectionInfo] = (0, react_1.useState)(null);
|
|
31
|
+
const [lastFetchParams, setLastFetchParams] = (0, react_1.useState)(null);
|
|
32
|
+
const [fetchCount, setFetchCount] = (0, react_1.useState)(0);
|
|
33
|
+
const [tab, setTab] = (0, react_1.useState)('all');
|
|
34
|
+
const apiRef = (0, react_1.useRef)(null);
|
|
35
|
+
const handleFetchData = (0, react_1.useCallback)((filters) => tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
36
|
+
var _a, _b, _c;
|
|
37
|
+
console.log('🔄 Fetching data with filters:', filters);
|
|
38
|
+
console.log('🔄 Tab:', { tab }, 'Current tab:');
|
|
39
|
+
setLoading(true);
|
|
40
|
+
setError(null);
|
|
41
|
+
setLastFetchParams(filters);
|
|
42
|
+
setFetchCount(prev => prev + 1);
|
|
43
|
+
try {
|
|
44
|
+
yield new Promise(resolve => setTimeout(resolve, 300 + Math.random() * 500));
|
|
45
|
+
let filteredData = [...MOCK_EMPLOYEES];
|
|
46
|
+
if (filters.globalFilter) {
|
|
47
|
+
const searchTerm = filters.globalFilter.toLowerCase();
|
|
48
|
+
filteredData = filteredData.filter(employee => employee.name.toLowerCase().includes(searchTerm) ||
|
|
49
|
+
employee.email.toLowerCase().includes(searchTerm) ||
|
|
50
|
+
employee.department.toLowerCase().includes(searchTerm) ||
|
|
51
|
+
employee.role.toLowerCase().includes(searchTerm));
|
|
52
|
+
}
|
|
53
|
+
if ((_b = (_a = filters.columnFilter) === null || _a === void 0 ? void 0 : _a.filters) === null || _b === void 0 ? void 0 : _b.length) {
|
|
54
|
+
filteredData = filteredData.filter(employee => {
|
|
55
|
+
return filters.columnFilter.filters.every((filter) => {
|
|
56
|
+
const value = employee[filter.columnId];
|
|
57
|
+
const filterValue = filter.value;
|
|
58
|
+
switch (filter.operator) {
|
|
59
|
+
case 'equals':
|
|
60
|
+
return value === filterValue;
|
|
61
|
+
case 'contains':
|
|
62
|
+
return String(value).toLowerCase().includes(String(filterValue).toLowerCase());
|
|
63
|
+
case 'startsWith':
|
|
64
|
+
return String(value).toLowerCase().startsWith(String(filterValue).toLowerCase());
|
|
65
|
+
case 'endsWith':
|
|
66
|
+
return String(value).toLowerCase().endsWith(String(filterValue).toLowerCase());
|
|
67
|
+
case 'greaterThan':
|
|
68
|
+
return Number(value) > Number(filterValue);
|
|
69
|
+
case 'lessThan':
|
|
70
|
+
return Number(value) < Number(filterValue);
|
|
71
|
+
default:
|
|
72
|
+
return true;
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
if ((_c = filters.sorting) === null || _c === void 0 ? void 0 : _c.length) {
|
|
78
|
+
filteredData.sort((a, b) => {
|
|
79
|
+
for (const sort of filters.sorting) {
|
|
80
|
+
const aValue = a[sort.id];
|
|
81
|
+
const bValue = b[sort.id];
|
|
82
|
+
let comparison = 0;
|
|
83
|
+
if (aValue < bValue)
|
|
84
|
+
comparison = -1;
|
|
85
|
+
else if (aValue > bValue)
|
|
86
|
+
comparison = 1;
|
|
87
|
+
if (comparison !== 0) {
|
|
88
|
+
return sort.desc ? -comparison : comparison;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return 0;
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
const total = filteredData.length;
|
|
95
|
+
let pageData = filteredData;
|
|
96
|
+
if (filters.pagination) {
|
|
97
|
+
const { pageIndex = 0, pageSize = 10 } = filters.pagination;
|
|
98
|
+
const start = pageIndex * pageSize;
|
|
99
|
+
const end = start + pageSize;
|
|
100
|
+
pageData = filteredData.slice(start, end);
|
|
101
|
+
}
|
|
102
|
+
console.log('✅ Data fetched successfully:', {
|
|
103
|
+
total,
|
|
104
|
+
pageSize: pageData.length,
|
|
105
|
+
filters: filters.pagination
|
|
106
|
+
});
|
|
107
|
+
return {
|
|
108
|
+
data: pageData,
|
|
109
|
+
total: total,
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
catch (err) {
|
|
113
|
+
console.error('❌ Error fetching data:', err);
|
|
114
|
+
setError('Failed to fetch data. Please try again.');
|
|
115
|
+
throw err;
|
|
116
|
+
}
|
|
117
|
+
finally {
|
|
118
|
+
setLoading(false);
|
|
119
|
+
}
|
|
120
|
+
}), []);
|
|
121
|
+
const handleSelectionChange = (0, react_1.useCallback)((selection) => {
|
|
122
|
+
console.log('🔄 Selection changed:', selection);
|
|
123
|
+
setSelectionInfo(selection);
|
|
124
|
+
}, []);
|
|
125
|
+
(0, react_1.useEffect)(() => {
|
|
126
|
+
var _a;
|
|
127
|
+
console.log('🔄 Tab changed:', tab);
|
|
128
|
+
if (tab && tab !== 'all') {
|
|
129
|
+
(_a = apiRef.current) === null || _a === void 0 ? void 0 : _a.data.refresh();
|
|
130
|
+
}
|
|
131
|
+
}, [tab]);
|
|
132
|
+
const handleServerExport = (0, react_1.useCallback)((filters, selection) => tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
133
|
+
console.log('📤 Exporting data with filters:', filters);
|
|
134
|
+
console.log('📤 Export selection:', selection);
|
|
135
|
+
yield new Promise(resolve => setTimeout(resolve, 1000));
|
|
136
|
+
let exportData = [...MOCK_EMPLOYEES];
|
|
137
|
+
if (filters === null || filters === void 0 ? void 0 : filters.globalFilter) {
|
|
138
|
+
const searchTerm = filters.globalFilter.toLowerCase();
|
|
139
|
+
exportData = exportData.filter(employee => employee.name.toLowerCase().includes(searchTerm) ||
|
|
140
|
+
employee.email.toLowerCase().includes(searchTerm) ||
|
|
141
|
+
employee.department.toLowerCase().includes(searchTerm) ||
|
|
142
|
+
employee.role.toLowerCase().includes(searchTerm));
|
|
143
|
+
}
|
|
144
|
+
if (selection.type === 'include' && selection.ids.length > 0) {
|
|
145
|
+
exportData = exportData.filter(employee => selection.ids.includes(employee.id.toString()));
|
|
146
|
+
}
|
|
147
|
+
else if (selection.type === 'exclude' && selection.ids.length > 0) {
|
|
148
|
+
exportData = exportData.filter(employee => !selection.ids.includes(employee.id.toString()));
|
|
149
|
+
}
|
|
150
|
+
return {
|
|
151
|
+
data: exportData,
|
|
152
|
+
total: exportData.length,
|
|
153
|
+
};
|
|
154
|
+
}), []);
|
|
155
|
+
const columns = [
|
|
156
|
+
{
|
|
157
|
+
id: 'name',
|
|
158
|
+
accessorKey: 'name',
|
|
159
|
+
header: 'Name',
|
|
160
|
+
size: 200,
|
|
161
|
+
enableGlobalFilter: true,
|
|
162
|
+
},
|
|
163
|
+
{
|
|
164
|
+
id: 'email',
|
|
165
|
+
accessorKey: 'email',
|
|
166
|
+
header: 'Email',
|
|
167
|
+
size: 250,
|
|
168
|
+
enableGlobalFilter: true,
|
|
169
|
+
},
|
|
170
|
+
{
|
|
171
|
+
id: 'department',
|
|
172
|
+
accessorKey: 'department',
|
|
173
|
+
header: 'Department',
|
|
174
|
+
size: 150,
|
|
175
|
+
enableGlobalFilter: true,
|
|
176
|
+
},
|
|
177
|
+
{
|
|
178
|
+
id: 'role',
|
|
179
|
+
accessorKey: 'role',
|
|
180
|
+
header: 'Role',
|
|
181
|
+
size: 120,
|
|
182
|
+
enableGlobalFilter: true,
|
|
183
|
+
},
|
|
184
|
+
{
|
|
185
|
+
id: 'salary',
|
|
186
|
+
accessorKey: 'salary',
|
|
187
|
+
header: 'Salary',
|
|
188
|
+
size: 120,
|
|
189
|
+
accessorFn: (row) => `$${row.salary.toLocaleString()}`,
|
|
190
|
+
hideInExport: true,
|
|
191
|
+
},
|
|
192
|
+
{
|
|
193
|
+
id: 'isActive',
|
|
194
|
+
accessorKey: 'isActive',
|
|
195
|
+
header: 'Status',
|
|
196
|
+
size: 100,
|
|
197
|
+
accessorFn: (row) => row.isActive ? 'Active' : 'Inactive',
|
|
198
|
+
cell: ({ getValue }) => ((0, jsx_runtime_1.jsx)(material_1.Chip, { label: getValue() ? 'Active' : 'Inactive', color: getValue() ? 'success' : 'default', size: "small" })),
|
|
199
|
+
},
|
|
200
|
+
{
|
|
201
|
+
id: 'joinDate',
|
|
202
|
+
accessorKey: 'joinDate',
|
|
203
|
+
header: 'Join Date',
|
|
204
|
+
size: 120,
|
|
205
|
+
accessorFn: (row) => new Date(row.joinDate).toLocaleDateString(),
|
|
206
|
+
},
|
|
207
|
+
];
|
|
208
|
+
return ((0, jsx_runtime_1.jsxs)(material_1.Box, { sx: { p: 3 }, children: [(0, jsx_runtime_1.jsx)(material_1.Typography, { variant: "h4", gutterBottom: true, children: "Server-Side Data Fetching Example" }), (0, jsx_runtime_1.jsx)(material_1.Typography, { variant: "body1", color: "text.secondary", paragraph: true, children: "Demonstrates server-side data fetching with proper API ref state management and page-based selection. The Salary column has `hideInExport: true` so it will be excluded from exports." }), (0, jsx_runtime_1.jsx)(material_1.Button, { onClick: () => setTab('all'), children: "All" }), (0, jsx_runtime_1.jsx)(material_1.Button, { onClick: () => setTab('active'), children: "Active" }), (0, jsx_runtime_1.jsx)(material_1.Button, { onClick: () => setTab('inactive'), children: "Inactive" }), (0, jsx_runtime_1.jsxs)(material_1.Stack, { direction: "row", spacing: 2, sx: { mb: 3 }, children: [(0, jsx_runtime_1.jsx)(material_1.Card, { variant: "outlined", children: (0, jsx_runtime_1.jsxs)(material_1.CardContent, { sx: { pb: 2 }, children: [(0, jsx_runtime_1.jsx)(material_1.Typography, { variant: "h6", color: "primary", children: fetchCount }), (0, jsx_runtime_1.jsx)(material_1.Typography, { variant: "body2", color: "text.secondary", children: "API Calls Made" })] }) }), (0, jsx_runtime_1.jsx)(material_1.Card, { variant: "outlined", children: (0, jsx_runtime_1.jsxs)(material_1.CardContent, { sx: { pb: 2 }, children: [(0, jsx_runtime_1.jsx)(material_1.Typography, { variant: "h6", color: "secondary", children: (selectionInfo === null || selectionInfo === void 0 ? void 0 : selectionInfo.ids.length) || 0 }), (0, jsx_runtime_1.jsx)(material_1.Typography, { variant: "body2", color: "text.secondary", children: "Selected Items" })] }) }), (0, jsx_runtime_1.jsx)(material_1.Card, { variant: "outlined", children: (0, jsx_runtime_1.jsxs)(material_1.CardContent, { sx: { pb: 2 }, children: [(0, jsx_runtime_1.jsxs)(material_1.Stack, { direction: "row", alignItems: "center", spacing: 1, children: [(0, jsx_runtime_1.jsx)(material_1.Typography, { variant: "h6", color: loading ? 'warning.main' : 'success.main', children: loading ? 'Loading...' : 'Ready' }), loading && (0, jsx_runtime_1.jsx)(material_1.CircularProgress, { size: 16 })] }), (0, jsx_runtime_1.jsx)(material_1.Typography, { variant: "body2", color: "text.secondary", children: "Server Status" })] }) })] }), error && ((0, jsx_runtime_1.jsx)(material_1.Alert, { severity: "error", sx: { mb: 3 }, children: error })), (0, jsx_runtime_1.jsx)(material_1.Card, { sx: { mb: 3 }, children: (0, jsx_runtime_1.jsxs)(material_1.CardContent, { children: [(0, jsx_runtime_1.jsx)(material_1.Typography, { variant: "h6", gutterBottom: true, children: "API Controls (via apiRef)" }), (0, jsx_runtime_1.jsxs)(material_1.Stack, { direction: "row", spacing: 2, flexWrap: "wrap", children: [(0, jsx_runtime_1.jsx)(material_1.Button, { variant: "outlined", size: "small", onClick: () => {
|
|
209
|
+
var _a;
|
|
210
|
+
const state = (_a = apiRef.current) === null || _a === void 0 ? void 0 : _a.selection.getSelectionState();
|
|
211
|
+
console.log('Current Selection State:', state);
|
|
212
|
+
alert(`Selection: ${JSON.stringify(state, null, 2)}`);
|
|
213
|
+
}, children: "Get Selection State" }), (0, jsx_runtime_1.jsx)(material_1.Button, { variant: "outlined", size: "small", onClick: () => {
|
|
214
|
+
var _a;
|
|
215
|
+
const count = (_a = apiRef.current) === null || _a === void 0 ? void 0 : _a.selection.getSelectedCount();
|
|
216
|
+
console.log('Selected Count:', count);
|
|
217
|
+
alert(`Selected Count: ${count}`);
|
|
218
|
+
}, children: "Get Selected Count" }), (0, jsx_runtime_1.jsx)(material_1.Button, { variant: "outlined", size: "small", onClick: () => {
|
|
219
|
+
var _a;
|
|
220
|
+
(_a = apiRef.current) === null || _a === void 0 ? void 0 : _a.selection.selectAll();
|
|
221
|
+
console.log('Selected all rows on current page');
|
|
222
|
+
}, children: "Select All (Page)" }), (0, jsx_runtime_1.jsx)(material_1.Button, { variant: "outlined", size: "small", onClick: () => {
|
|
223
|
+
var _a;
|
|
224
|
+
(_a = apiRef.current) === null || _a === void 0 ? void 0 : _a.selection.deselectAll();
|
|
225
|
+
console.log('Deselected all rows');
|
|
226
|
+
}, children: "Deselect All" }), (0, jsx_runtime_1.jsx)(material_1.Button, { variant: "outlined", size: "small", onClick: () => {
|
|
227
|
+
var _a;
|
|
228
|
+
(_a = apiRef.current) === null || _a === void 0 ? void 0 : _a.data.refresh();
|
|
229
|
+
console.log('Refreshed data');
|
|
230
|
+
}, children: "Refresh Data" })] })] }) }), selectionInfo && ((0, jsx_runtime_1.jsx)(material_1.Card, { sx: { mb: 3 }, children: (0, jsx_runtime_1.jsxs)(material_1.CardContent, { children: [(0, jsx_runtime_1.jsx)(material_1.Typography, { variant: "h6", gutterBottom: true, children: "Current Selection Info" }), (0, jsx_runtime_1.jsx)(material_1.Paper, { sx: { p: 2, bgcolor: 'grey.50' }, children: (0, jsx_runtime_1.jsxs)(material_1.Stack, { spacing: 1, children: [(0, jsx_runtime_1.jsxs)(material_1.Typography, { variant: "body2", children: [(0, jsx_runtime_1.jsx)("strong", { children: "Selection Type:" }), " ", selectionInfo.type] }), (0, jsx_runtime_1.jsxs)(material_1.Typography, { variant: "body2", children: [(0, jsx_runtime_1.jsx)("strong", { children: "Selected IDs:" }), " [", selectionInfo.ids.join(', '), "]"] }), (0, jsx_runtime_1.jsxs)(material_1.Typography, { variant: "body2", children: [(0, jsx_runtime_1.jsx)("strong", { children: "Count:" }), " ", selectionInfo.ids.length] })] }) })] }) })), (0, jsx_runtime_1.jsx)(material_1.Card, { sx: { mb: 3 }, children: (0, jsx_runtime_1.jsxs)(material_1.CardContent, { children: [(0, jsx_runtime_1.jsx)(material_1.Typography, { variant: "h6", gutterBottom: true, children: "Export & Column Configuration" }), (0, jsx_runtime_1.jsx)(material_1.Alert, { severity: "info", sx: { mb: 2 }, children: (0, jsx_runtime_1.jsxs)(material_1.Typography, { variant: "body2", children: [(0, jsx_runtime_1.jsx)("strong", { children: "hideInExport Demo:" }), " The Salary column has `hideInExport: true` so it will be excluded from CSV/Excel exports. Try exporting to see the difference!"] }) }), (0, jsx_runtime_1.jsxs)(material_1.Stack, { spacing: 1, children: [(0, jsx_runtime_1.jsxs)(material_1.Typography, { variant: "body2", children: [(0, jsx_runtime_1.jsx)("strong", { children: "Exportable columns:" }), " Name, Email, Department, Role, Status, Join Date"] }), (0, jsx_runtime_1.jsxs)(material_1.Typography, { variant: "body2", color: "warning.main", children: [(0, jsx_runtime_1.jsx)("strong", { children: "Hidden from export:" }), " Salary (contains sensitive data)"] })] })] }) }), lastFetchParams && ((0, jsx_runtime_1.jsx)(material_1.Card, { sx: { mb: 3 }, children: (0, jsx_runtime_1.jsxs)(material_1.CardContent, { children: [(0, jsx_runtime_1.jsx)(material_1.Typography, { variant: "h6", gutterBottom: true, children: "Last Fetch Parameters" }), (0, jsx_runtime_1.jsx)(material_1.Paper, { sx: { p: 2, bgcolor: 'grey.50' }, children: (0, jsx_runtime_1.jsx)("pre", { style: { fontSize: '12px', margin: 0, overflow: 'auto' }, children: JSON.stringify(lastFetchParams, null, 2) }) })] }) })), (0, jsx_runtime_1.jsx)(material_1.Divider, { sx: { mb: 3 } }), (0, jsx_runtime_1.jsx)(data_table_1.DataTable, { ref: apiRef, columns: columns, dataMode: "server", initialLoadData: true, onFetchData: handleFetchData, loading: loading, enableRowSelection: true, enableMultiRowSelection: true, selectMode: "page", onSelectionChange: handleSelectionChange, enableBulkActions: true, bulkActions: (selectionState) => ((0, jsx_runtime_1.jsxs)(material_1.Stack, { direction: "row", spacing: 1, children: [(0, jsx_runtime_1.jsxs)(material_1.Button, { variant: "contained", size: "small", color: "error", onClick: () => {
|
|
231
|
+
console.log('Bulk delete action triggered');
|
|
232
|
+
console.log('Selection state:', selectionState);
|
|
233
|
+
alert(`Would delete ${selectionState.ids.length} items`);
|
|
234
|
+
}, children: ["Delete Selected (", selectionState.ids.length, ")"] }), (0, jsx_runtime_1.jsx)(material_1.Button, { variant: "outlined", size: "small", onClick: () => {
|
|
235
|
+
console.log('Bulk update action triggered');
|
|
236
|
+
console.log('Selection state:', selectionState);
|
|
237
|
+
alert(`Would update ${selectionState.ids.length} items`);
|
|
238
|
+
}, children: "Update Selected" })] })), enableGlobalFilter: true, enableColumnFilter: true, enableSorting: true, enablePagination: true, initialState: {
|
|
239
|
+
pagination: {
|
|
240
|
+
pageIndex: 0,
|
|
241
|
+
pageSize: 10,
|
|
242
|
+
},
|
|
243
|
+
}, enableExport: true, exportFilename: "employees", onServerExport: handleServerExport, onExportProgress: (progress) => {
|
|
244
|
+
console.log('Export progress:', progress);
|
|
245
|
+
}, onExportComplete: (result) => {
|
|
246
|
+
console.log('Export completed:', result);
|
|
247
|
+
}, onExportError: (error) => {
|
|
248
|
+
console.error('Export error:', error);
|
|
249
|
+
}, enableHover: true, enableStripes: true, tableSize: "medium", enableColumnVisibility: true, enableTableSizeControl: true, enableReset: true, emptyMessage: "No employees found matching your criteria", skeletonRows: 10 })] }));
|
|
250
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function ServerSideTest(): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ServerSideTest = ServerSideTest;
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
const material_1 = require("@mui/material");
|
|
6
|
+
const server_side_fetching_example_1 = require("./server-side-fetching-example");
|
|
7
|
+
function ServerSideTest() {
|
|
8
|
+
return ((0, jsx_runtime_1.jsx)(material_1.Box, { sx: { p: 2 }, children: (0, jsx_runtime_1.jsxs)(material_1.Paper, { sx: { p: 3 }, children: [(0, jsx_runtime_1.jsx)(material_1.Typography, { variant: "h5", gutterBottom: true, children: "Server-Side Data Fetching Test" }), (0, jsx_runtime_1.jsx)(material_1.Typography, { variant: "body2", color: "text.secondary", paragraph: true, children: "This example demonstrates how to use the DataTable component with server-side data fetching. The onFetchData callback handles all server operations including filtering, sorting, and pagination." }), (0, jsx_runtime_1.jsx)(server_side_fetching_example_1.ServerSideFetchingExample, {})] }) }));
|
|
9
|
+
}
|