@ackplus/react-tanstack-data-table 1.1.17 → 1.1.19
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/components/toolbar/column-filter-control.d.ts +3 -2
- package/dist/lib/components/toolbar/column-filter-control.d.ts.map +1 -1
- package/dist/lib/components/toolbar/column-filter-control.js +91 -92
- package/dist/lib/components/toolbar/table-refresh-control.d.ts.map +1 -1
- package/dist/lib/components/toolbar/table-refresh-control.js +3 -1
- package/dist/lib/features/column-filter.feature.d.ts +2 -1
- package/dist/lib/features/column-filter.feature.d.ts.map +1 -1
- package/dist/lib/features/column-filter.feature.js +14 -0
- package/dist/lib/hooks/use-data-table-engine.d.ts.map +1 -1
- package/dist/lib/hooks/use-data-table-engine.js +278 -14
- package/package.json +1 -1
- package/src/lib/components/toolbar/column-filter-control.tsx +270 -212
- package/src/lib/components/toolbar/table-refresh-control.tsx +11 -7
- package/src/lib/features/column-filter.feature.ts +15 -1
- package/src/lib/hooks/use-data-table-engine.ts +248 -14
|
@@ -381,7 +381,10 @@ function useDataTableEngine(props) {
|
|
|
381
381
|
lastServerKeyRef.current = serverKey;
|
|
382
382
|
const delay = (_a = nextFetchDelayRef.current) !== null && _a !== void 0 ? _a : 0;
|
|
383
383
|
nextFetchDelayRef.current = 0; // reset after using
|
|
384
|
-
|
|
384
|
+
const timeoutId = setTimeout(() => {
|
|
385
|
+
void fetchData({}, { delay, meta: { reason: "stateChange" } });
|
|
386
|
+
}, 0);
|
|
387
|
+
return () => clearTimeout(timeoutId);
|
|
385
388
|
}, [serverKey, fetchData]);
|
|
386
389
|
// columnFilter apply handler stays explicit (button), but you can also auto-fetch on change if needed
|
|
387
390
|
const handleColumnFilterChangeHandler = (0, react_1.useCallback)((updater, isApply = false) => {
|
|
@@ -583,21 +586,175 @@ function useDataTableEngine(props) {
|
|
|
583
586
|
getGlobalFilter: () => tableRef.current.getState().globalFilter,
|
|
584
587
|
};
|
|
585
588
|
// --- data
|
|
589
|
+
const getBaseData = () => {
|
|
590
|
+
const sData = serverDataRef.current;
|
|
591
|
+
return sData !== null ? sData : dataRef.current;
|
|
592
|
+
};
|
|
593
|
+
const getRowIndexById = (arr, rowId) => arr.findIndex((row, i) => (0, utils_1.generateRowId)(row, i, idKey) === rowId);
|
|
586
594
|
api.data = {
|
|
587
595
|
refresh: (options) => void triggerRefresh(options, "refresh"),
|
|
588
596
|
reload: (options = {}) => { var _a; return void triggerRefresh({ ...options, reason: (_a = options.reason) !== null && _a !== void 0 ? _a : "reload" }, "reload"); },
|
|
589
597
|
resetAll: () => resetAllAndReload(),
|
|
590
|
-
getAllData: () =>
|
|
591
|
-
|
|
592
|
-
const
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
getDataCount: () => {
|
|
596
|
-
const sData = serverDataRef.current;
|
|
597
|
-
const base = sData !== null ? sData : dataRef.current;
|
|
598
|
-
return base.length;
|
|
598
|
+
getAllData: () => [...getBaseData()],
|
|
599
|
+
getRowData: (rowId) => {
|
|
600
|
+
const rows = tableRef.current.getRowModel().rows;
|
|
601
|
+
const row = rows.find((r) => r.id === rowId);
|
|
602
|
+
return row === null || row === void 0 ? void 0 : row.original;
|
|
599
603
|
},
|
|
604
|
+
getRowByIndex: (index) => { var _a; return (_a = tableRef.current.getRowModel().rows[index]) === null || _a === void 0 ? void 0 : _a.original; },
|
|
605
|
+
getDataCount: () => getBaseData().length,
|
|
600
606
|
getFilteredDataCount: () => tableRef.current.getFilteredRowModel().rows.length,
|
|
607
|
+
updateRow: (rowId, updates) => {
|
|
608
|
+
const base = getBaseData();
|
|
609
|
+
const idx = getRowIndexById(base, rowId);
|
|
610
|
+
if (idx === -1)
|
|
611
|
+
return;
|
|
612
|
+
const next = [...base];
|
|
613
|
+
next[idx] = { ...next[idx], ...updates };
|
|
614
|
+
setServerData(next);
|
|
615
|
+
setServerTotal(next.length);
|
|
616
|
+
},
|
|
617
|
+
updateRowByIndex: (index, updates) => {
|
|
618
|
+
const base = getBaseData();
|
|
619
|
+
if (index < 0 || index >= base.length)
|
|
620
|
+
return;
|
|
621
|
+
const next = [...base];
|
|
622
|
+
next[index] = { ...next[index], ...updates };
|
|
623
|
+
setServerData(next);
|
|
624
|
+
setServerTotal(next.length);
|
|
625
|
+
},
|
|
626
|
+
insertRow: (newRow, index) => {
|
|
627
|
+
const base = getBaseData();
|
|
628
|
+
const next = index == null ? [...base, newRow] : [...base.slice(0, index), newRow, ...base.slice(index)];
|
|
629
|
+
setServerData(next);
|
|
630
|
+
setServerTotal(next.length);
|
|
631
|
+
},
|
|
632
|
+
deleteRow: (rowId) => {
|
|
633
|
+
const base = getBaseData();
|
|
634
|
+
const idx = getRowIndexById(base, rowId);
|
|
635
|
+
if (idx === -1)
|
|
636
|
+
return;
|
|
637
|
+
const next = base.filter((_, i) => i !== idx);
|
|
638
|
+
setServerData(next);
|
|
639
|
+
setServerTotal(next.length);
|
|
640
|
+
},
|
|
641
|
+
deleteRowByIndex: (index) => {
|
|
642
|
+
const base = getBaseData();
|
|
643
|
+
if (index < 0 || index >= base.length)
|
|
644
|
+
return;
|
|
645
|
+
const next = base.filter((_, i) => i !== index);
|
|
646
|
+
setServerData(next);
|
|
647
|
+
setServerTotal(next.length);
|
|
648
|
+
},
|
|
649
|
+
deleteSelectedRows: () => {
|
|
650
|
+
var _a, _b, _c, _d;
|
|
651
|
+
const state = (_b = (_a = tableRef.current).getSelectionState) === null || _b === void 0 ? void 0 : _b.call(_a);
|
|
652
|
+
if (!state || state.type !== "include" || !state.ids.length)
|
|
653
|
+
return;
|
|
654
|
+
const base = getBaseData();
|
|
655
|
+
const ids = new Set(state.ids);
|
|
656
|
+
const next = base.filter((row, i) => !ids.has((0, utils_1.generateRowId)(row, i, idKey)));
|
|
657
|
+
setServerData(next);
|
|
658
|
+
setServerTotal(next.length);
|
|
659
|
+
(_d = (_c = tableRef.current).deselectAll) === null || _d === void 0 ? void 0 : _d.call(_c);
|
|
660
|
+
},
|
|
661
|
+
replaceAllData: (newData) => {
|
|
662
|
+
setServerData(newData);
|
|
663
|
+
setServerTotal(newData.length);
|
|
664
|
+
},
|
|
665
|
+
updateMultipleRows: (updates) => {
|
|
666
|
+
const base = getBaseData();
|
|
667
|
+
const next = [...base];
|
|
668
|
+
for (const { rowId, data: u } of updates) {
|
|
669
|
+
const idx = getRowIndexById(next, rowId);
|
|
670
|
+
if (idx !== -1)
|
|
671
|
+
next[idx] = { ...next[idx], ...u };
|
|
672
|
+
}
|
|
673
|
+
setServerData(next);
|
|
674
|
+
setServerTotal(next.length);
|
|
675
|
+
},
|
|
676
|
+
insertMultipleRows: (newRows, startIndex) => {
|
|
677
|
+
const base = getBaseData();
|
|
678
|
+
const idx = startIndex !== null && startIndex !== void 0 ? startIndex : base.length;
|
|
679
|
+
const next = [...base.slice(0, idx), ...newRows, ...base.slice(idx)];
|
|
680
|
+
setServerData(next);
|
|
681
|
+
setServerTotal(next.length);
|
|
682
|
+
},
|
|
683
|
+
deleteMultipleRows: (rowIds) => {
|
|
684
|
+
const ids = new Set(rowIds);
|
|
685
|
+
const base = getBaseData();
|
|
686
|
+
const next = base.filter((row, i) => !ids.has((0, utils_1.generateRowId)(row, i, idKey)));
|
|
687
|
+
setServerData(next);
|
|
688
|
+
setServerTotal(next.length);
|
|
689
|
+
},
|
|
690
|
+
updateField: (rowId, fieldName, value) => {
|
|
691
|
+
api.data.updateRow(rowId, { [fieldName]: value });
|
|
692
|
+
},
|
|
693
|
+
updateFieldByIndex: (index, fieldName, value) => {
|
|
694
|
+
api.data.updateRowByIndex(index, { [fieldName]: value });
|
|
695
|
+
},
|
|
696
|
+
findRows: (predicate) => getBaseData().filter(predicate),
|
|
697
|
+
findRowIndex: (predicate) => getBaseData().findIndex(predicate),
|
|
698
|
+
};
|
|
699
|
+
// --- layout (save/restore column visibility, order, sizing, pinning)
|
|
700
|
+
api.layout = {
|
|
701
|
+
saveLayout: () => {
|
|
702
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
703
|
+
const s = tableRef.current.getState();
|
|
704
|
+
return {
|
|
705
|
+
columnVisibility: (_a = s.columnVisibility) !== null && _a !== void 0 ? _a : {},
|
|
706
|
+
columnOrder: (_b = s.columnOrder) !== null && _b !== void 0 ? _b : [],
|
|
707
|
+
columnSizing: (_c = s.columnSizing) !== null && _c !== void 0 ? _c : {},
|
|
708
|
+
columnPinning: (_d = s.columnPinning) !== null && _d !== void 0 ? _d : { left: [], right: [] },
|
|
709
|
+
pagination: (_e = s.pagination) !== null && _e !== void 0 ? _e : { pageIndex: 0, pageSize: 10 },
|
|
710
|
+
globalFilter: (_f = s.globalFilter) !== null && _f !== void 0 ? _f : "",
|
|
711
|
+
columnFilter: (_g = s.columnFilter) !== null && _g !== void 0 ? _g : [],
|
|
712
|
+
};
|
|
713
|
+
},
|
|
714
|
+
restoreLayout: (layout) => {
|
|
715
|
+
var _a, _b, _c;
|
|
716
|
+
if (layout.columnVisibility)
|
|
717
|
+
dispatch({ type: "SET_COLUMN_VISIBILITY", payload: layout.columnVisibility });
|
|
718
|
+
if (layout.columnOrder) {
|
|
719
|
+
dispatch({ type: "SET_COLUMN_ORDER", payload: layout.columnOrder });
|
|
720
|
+
(_a = onColumnDragEndRef.current) === null || _a === void 0 ? void 0 : _a.call(onColumnDragEndRef, layout.columnOrder);
|
|
721
|
+
}
|
|
722
|
+
if (layout.columnSizing) {
|
|
723
|
+
dispatch({ type: "SET_COLUMN_SIZING", payload: layout.columnSizing });
|
|
724
|
+
(_b = onColumnSizingChangeRef.current) === null || _b === void 0 ? void 0 : _b.call(onColumnSizingChangeRef, layout.columnSizing);
|
|
725
|
+
}
|
|
726
|
+
if (layout.columnPinning) {
|
|
727
|
+
dispatch({ type: "SET_COLUMN_PINNING", payload: layout.columnPinning });
|
|
728
|
+
(_c = onColumnPinningChangeRef.current) === null || _c === void 0 ? void 0 : _c.call(onColumnPinningChangeRef, layout.columnPinning);
|
|
729
|
+
}
|
|
730
|
+
if (layout.pagination && enablePagination)
|
|
731
|
+
dispatch({ type: "SET_PAGINATION", payload: layout.pagination });
|
|
732
|
+
if (layout.globalFilter !== undefined)
|
|
733
|
+
dispatch({ type: "SET_GLOBAL_FILTER_RESET_PAGE", payload: layout.globalFilter });
|
|
734
|
+
if (layout.columnFilter)
|
|
735
|
+
dispatch({ type: "SET_COLUMN_FILTER", payload: layout.columnFilter });
|
|
736
|
+
},
|
|
737
|
+
resetLayout: () => {
|
|
738
|
+
var _a, _b, _c;
|
|
739
|
+
const vis = initialStateConfig.columnVisibility || {};
|
|
740
|
+
const order = initialStateConfig.columnOrder || [];
|
|
741
|
+
const sizing = initialStateConfig.columnSizing || {};
|
|
742
|
+
const pinning = initialStateConfig.columnPinning || { left: [], right: [] };
|
|
743
|
+
dispatch({ type: "SET_COLUMN_VISIBILITY", payload: vis });
|
|
744
|
+
dispatch({ type: "SET_COLUMN_ORDER", payload: order });
|
|
745
|
+
dispatch({ type: "SET_COLUMN_SIZING", payload: sizing });
|
|
746
|
+
dispatch({ type: "SET_COLUMN_PINNING", payload: pinning });
|
|
747
|
+
dispatch({ type: "SET_PAGINATION", payload: { pageIndex: 0, pageSize: 10 } });
|
|
748
|
+
dispatch({ type: "SET_GLOBAL_FILTER_RESET_PAGE", payload: "" });
|
|
749
|
+
dispatch({ type: "SET_COLUMN_FILTER", payload: [] });
|
|
750
|
+
(_a = onColumnDragEndRef.current) === null || _a === void 0 ? void 0 : _a.call(onColumnDragEndRef, order);
|
|
751
|
+
(_b = onColumnSizingChangeRef.current) === null || _b === void 0 ? void 0 : _b.call(onColumnSizingChangeRef, sizing);
|
|
752
|
+
(_c = onColumnPinningChangeRef.current) === null || _c === void 0 ? void 0 : _c.call(onColumnPinningChangeRef, pinning);
|
|
753
|
+
},
|
|
754
|
+
resetAll: () => {
|
|
755
|
+
api.layout.resetLayout();
|
|
756
|
+
resetAllAndReload();
|
|
757
|
+
},
|
|
601
758
|
};
|
|
602
759
|
// --- sorting/pagination/filtering - dispatch + callbacks + server fetch policies
|
|
603
760
|
api.sorting = {
|
|
@@ -608,6 +765,13 @@ function useDataTableEngine(props) {
|
|
|
608
765
|
nextFetchDelayRef.current = 0;
|
|
609
766
|
dispatch({ type: "SET_SORTING_RESET_PAGE", payload: cleaned });
|
|
610
767
|
},
|
|
768
|
+
sortColumn: (columnId, direction) => {
|
|
769
|
+
var _a;
|
|
770
|
+
const next = direction === false ? [] : [{ id: columnId, desc: direction === 'desc' }];
|
|
771
|
+
(_a = onSortingChangeRef.current) === null || _a === void 0 ? void 0 : _a.call(onSortingChangeRef, next);
|
|
772
|
+
nextFetchDelayRef.current = 0;
|
|
773
|
+
dispatch({ type: "SET_SORTING_RESET_PAGE", payload: next });
|
|
774
|
+
},
|
|
611
775
|
clearSorting: () => {
|
|
612
776
|
var _a;
|
|
613
777
|
(_a = onSortingChangeRef.current) === null || _a === void 0 ? void 0 : _a.call(onSortingChangeRef, []);
|
|
@@ -631,6 +795,14 @@ function useDataTableEngine(props) {
|
|
|
631
795
|
nextFetchDelayRef.current = 0;
|
|
632
796
|
dispatch({ type: "SET_PAGINATION", payload: next });
|
|
633
797
|
},
|
|
798
|
+
nextPage: () => {
|
|
799
|
+
const prev = uiRef.current.pagination;
|
|
800
|
+
api.pagination.goToPage(Math.min(prev.pageIndex + 1, Math.max(0, Math.ceil((tableTotalRow !== null && tableTotalRow !== void 0 ? tableTotalRow : 0) / prev.pageSize) - 1)));
|
|
801
|
+
},
|
|
802
|
+
previousPage: () => {
|
|
803
|
+
const prev = uiRef.current.pagination;
|
|
804
|
+
api.pagination.goToPage(Math.max(0, prev.pageIndex - 1));
|
|
805
|
+
},
|
|
634
806
|
setPageSize: (pageSize) => {
|
|
635
807
|
var _a;
|
|
636
808
|
const next = { pageIndex: 0, pageSize };
|
|
@@ -638,6 +810,11 @@ function useDataTableEngine(props) {
|
|
|
638
810
|
nextFetchDelayRef.current = 0;
|
|
639
811
|
dispatch({ type: "SET_PAGINATION", payload: next });
|
|
640
812
|
},
|
|
813
|
+
goToFirstPage: () => api.pagination.goToPage(0),
|
|
814
|
+
goToLastPage: () => {
|
|
815
|
+
const prev = uiRef.current.pagination;
|
|
816
|
+
api.pagination.goToPage(Math.max(0, Math.ceil((tableTotalRow !== null && tableTotalRow !== void 0 ? tableTotalRow : 0) / prev.pageSize) - 1));
|
|
817
|
+
},
|
|
641
818
|
resetPagination: () => {
|
|
642
819
|
var _a;
|
|
643
820
|
const next = (initialStateConfig.pagination || { pageIndex: 0, pageSize: 10 });
|
|
@@ -660,10 +837,24 @@ function useDataTableEngine(props) {
|
|
|
660
837
|
dispatch({ type: "SET_GLOBAL_FILTER_RESET_PAGE", payload: "" });
|
|
661
838
|
},
|
|
662
839
|
setColumnFilters: (filters, isApply = false) => handleColumnFilterChangeHandler(filters, isApply),
|
|
840
|
+
addColumnFilter: (columnId, operator, value) => { var _a, _b; return (_b = (_a = tableRef.current).addColumnFilter) === null || _b === void 0 ? void 0 : _b.call(_a, columnId, operator, value); },
|
|
841
|
+
removeColumnFilter: (filterId) => { var _a, _b; return (_b = (_a = tableRef.current).removeColumnFilter) === null || _b === void 0 ? void 0 : _b.call(_a, filterId); },
|
|
842
|
+
clearAllFilters: () => { var _a, _b; return (_b = (_a = tableRef.current).resetColumnFilter) === null || _b === void 0 ? void 0 : _b.call(_a); },
|
|
843
|
+
resetFilters: () => {
|
|
844
|
+
var _a;
|
|
845
|
+
const reset = ((_a = initialStateConfig.columnFilter) !== null && _a !== void 0 ? _a : DEFAULT_INITIAL_STATE.columnFilter);
|
|
846
|
+
handleColumnFilterChangeHandler(reset, true);
|
|
847
|
+
},
|
|
663
848
|
};
|
|
664
849
|
api.columnVisibility = {
|
|
665
850
|
showColumn: (id) => dispatch({ type: "SET_COLUMN_VISIBILITY", payload: { ...uiRef.current.columnVisibility, [id]: true } }),
|
|
666
851
|
hideColumn: (id) => dispatch({ type: "SET_COLUMN_VISIBILITY", payload: { ...uiRef.current.columnVisibility, [id]: false } }),
|
|
852
|
+
toggleColumn: (id) => dispatch({ type: "SET_COLUMN_VISIBILITY", payload: { ...uiRef.current.columnVisibility, [id]: !uiRef.current.columnVisibility[id] } }),
|
|
853
|
+
showAllColumns: () => dispatch({ type: "SET_COLUMN_VISIBILITY", payload: {} }),
|
|
854
|
+
hideAllColumns: () => {
|
|
855
|
+
const all = tableRef.current.getAllLeafColumns().reduce((acc, col) => ({ ...acc, [col.id]: false }), {});
|
|
856
|
+
dispatch({ type: "SET_COLUMN_VISIBILITY", payload: all });
|
|
857
|
+
},
|
|
667
858
|
resetColumnVisibility: () => dispatch({ type: "SET_COLUMN_VISIBILITY", payload: initialStateConfig.columnVisibility || {} }),
|
|
668
859
|
};
|
|
669
860
|
api.columnOrdering = {
|
|
@@ -672,9 +863,45 @@ function useDataTableEngine(props) {
|
|
|
672
863
|
dispatch({ type: "SET_COLUMN_ORDER", payload: next });
|
|
673
864
|
(_a = onColumnDragEndRef.current) === null || _a === void 0 ? void 0 : _a.call(onColumnDragEndRef, next);
|
|
674
865
|
},
|
|
866
|
+
moveColumn: (columnId, toIndex) => {
|
|
867
|
+
var _a;
|
|
868
|
+
const order = uiRef.current.columnOrder.length ? uiRef.current.columnOrder : tableRef.current.getAllLeafColumns().map((c) => c.id);
|
|
869
|
+
const from = order.indexOf(columnId);
|
|
870
|
+
if (from === -1 || toIndex < 0 || toIndex >= order.length)
|
|
871
|
+
return;
|
|
872
|
+
const next = [...order];
|
|
873
|
+
next.splice(from, 1);
|
|
874
|
+
next.splice(toIndex, 0, columnId);
|
|
875
|
+
dispatch({ type: "SET_COLUMN_ORDER", payload: next });
|
|
876
|
+
(_a = onColumnDragEndRef.current) === null || _a === void 0 ? void 0 : _a.call(onColumnDragEndRef, next);
|
|
877
|
+
},
|
|
675
878
|
resetColumnOrder: () => dispatch({ type: "SET_COLUMN_ORDER", payload: initialStateConfig.columnOrder || [] }),
|
|
676
879
|
};
|
|
677
880
|
api.columnPinning = {
|
|
881
|
+
pinColumnLeft: (columnId) => {
|
|
882
|
+
var _a;
|
|
883
|
+
const cur = uiRef.current.columnPinning;
|
|
884
|
+
const left = cur.left.includes(columnId) ? cur.left : [...cur.left.filter((id) => id !== columnId), columnId];
|
|
885
|
+
const right = cur.right.filter((id) => id !== columnId);
|
|
886
|
+
dispatch({ type: "SET_COLUMN_PINNING", payload: { left, right } });
|
|
887
|
+
(_a = onColumnPinningChangeRef.current) === null || _a === void 0 ? void 0 : _a.call(onColumnPinningChangeRef, { left, right });
|
|
888
|
+
},
|
|
889
|
+
pinColumnRight: (columnId) => {
|
|
890
|
+
var _a;
|
|
891
|
+
const cur = uiRef.current.columnPinning;
|
|
892
|
+
const left = cur.left.filter((id) => id !== columnId);
|
|
893
|
+
const right = cur.right.includes(columnId) ? cur.right : [...cur.right.filter((id) => id !== columnId), columnId];
|
|
894
|
+
dispatch({ type: "SET_COLUMN_PINNING", payload: { left, right } });
|
|
895
|
+
(_a = onColumnPinningChangeRef.current) === null || _a === void 0 ? void 0 : _a.call(onColumnPinningChangeRef, { left, right });
|
|
896
|
+
},
|
|
897
|
+
unpinColumn: (columnId) => {
|
|
898
|
+
var _a;
|
|
899
|
+
const cur = uiRef.current.columnPinning;
|
|
900
|
+
const left = cur.left.filter((id) => id !== columnId);
|
|
901
|
+
const right = cur.right.filter((id) => id !== columnId);
|
|
902
|
+
dispatch({ type: "SET_COLUMN_PINNING", payload: { left, right } });
|
|
903
|
+
(_a = onColumnPinningChangeRef.current) === null || _a === void 0 ? void 0 : _a.call(onColumnPinningChangeRef, { left, right });
|
|
904
|
+
},
|
|
678
905
|
setPinning: (next) => {
|
|
679
906
|
var _a;
|
|
680
907
|
dispatch({ type: "SET_COLUMN_PINNING", payload: next });
|
|
@@ -683,16 +910,27 @@ function useDataTableEngine(props) {
|
|
|
683
910
|
resetColumnPinning: () => dispatch({ type: "SET_COLUMN_PINNING", payload: initialStateConfig.columnPinning || { left: [], right: [] } }),
|
|
684
911
|
};
|
|
685
912
|
api.columnResizing = {
|
|
913
|
+
resizeColumn: (columnId, width) => {
|
|
914
|
+
var _a;
|
|
915
|
+
const cur = uiRef.current.columnSizing;
|
|
916
|
+
dispatch({ type: "SET_COLUMN_SIZING", payload: { ...cur, [columnId]: width } });
|
|
917
|
+
(_a = onColumnSizingChangeRef.current) === null || _a === void 0 ? void 0 : _a.call(onColumnSizingChangeRef, { ...cur, [columnId]: width });
|
|
918
|
+
},
|
|
919
|
+
autoSizeColumn: (columnId) => { void columnId; /* no-op: would require measure; use reset for default */ },
|
|
920
|
+
autoSizeAllColumns: () => { },
|
|
686
921
|
resetColumnSizing: () => dispatch({ type: "SET_COLUMN_SIZING", payload: initialStateConfig.columnSizing || {} }),
|
|
687
922
|
};
|
|
688
923
|
api.selection = {
|
|
924
|
+
selectRow: (rowId) => { var _a, _b; return (_b = (_a = tableRef.current).selectRow) === null || _b === void 0 ? void 0 : _b.call(_a, rowId); },
|
|
925
|
+
deselectRow: (rowId) => { var _a, _b; return (_b = (_a = tableRef.current).deselectRow) === null || _b === void 0 ? void 0 : _b.call(_a, rowId); },
|
|
926
|
+
toggleRowSelection: (rowId) => { var _a, _b; return (_b = (_a = tableRef.current).toggleRowSelected) === null || _b === void 0 ? void 0 : _b.call(_a, rowId); },
|
|
927
|
+
selectAll: () => { var _a, _b; return (_b = (_a = tableRef.current).selectAll) === null || _b === void 0 ? void 0 : _b.call(_a); },
|
|
928
|
+
deselectAll: () => { var _a, _b; return (_b = (_a = tableRef.current).deselectAll) === null || _b === void 0 ? void 0 : _b.call(_a); },
|
|
929
|
+
toggleSelectAll: () => { var _a, _b; return (_b = (_a = tableRef.current).toggleAllRowsSelected) === null || _b === void 0 ? void 0 : _b.call(_a); },
|
|
689
930
|
getSelectionState: () => { var _a, _b; return ((_b = (_a = tableRef.current).getSelectionState) === null || _b === void 0 ? void 0 : _b.call(_a)) || { ids: [], type: "include" }; },
|
|
690
931
|
getSelectedRows: () => tableRef.current.getSelectedRows(),
|
|
691
932
|
getSelectedCount: () => tableRef.current.getSelectedCount(),
|
|
692
933
|
isRowSelected: (rowId) => tableRef.current.getIsRowSelected(rowId) || false,
|
|
693
|
-
// keep using your table extension methods if you have them:
|
|
694
|
-
selectAll: () => { var _a, _b; return (_b = (_a = tableRef.current).selectAll) === null || _b === void 0 ? void 0 : _b.call(_a); },
|
|
695
|
-
deselectAll: () => { var _a, _b; return (_b = (_a = tableRef.current).deselectAll) === null || _b === void 0 ? void 0 : _b.call(_a); },
|
|
696
934
|
};
|
|
697
935
|
// --- export API (use your existing exportClientData/exportServerData)
|
|
698
936
|
api.export = {
|
|
@@ -796,10 +1034,36 @@ function useDataTableEngine(props) {
|
|
|
796
1034
|
},
|
|
797
1035
|
});
|
|
798
1036
|
},
|
|
1037
|
+
exportServerData: async (options) => {
|
|
1038
|
+
const { format, filename: fn = exportFilename, fetchData: customFetchData, chunkSize: cs = exportChunkSize, strictTotalCheck: st = exportStrictTotalCheck, sanitizeCSV: san = exportSanitizeCSV } = options;
|
|
1039
|
+
await runExportWithPolicy({
|
|
1040
|
+
format,
|
|
1041
|
+
filename: fn,
|
|
1042
|
+
mode: "server",
|
|
1043
|
+
execute: async (controller) => {
|
|
1044
|
+
var _a, _b;
|
|
1045
|
+
await (0, utils_1.exportServerData)(tableRef.current, {
|
|
1046
|
+
format,
|
|
1047
|
+
filename: fn,
|
|
1048
|
+
fetchData: customFetchData,
|
|
1049
|
+
currentFilters: { globalFilter: tableRef.current.getState().globalFilter, columnFilter: tableRef.current.getState().columnFilter, sorting: tableRef.current.getState().sorting, pagination: tableRef.current.getState().pagination },
|
|
1050
|
+
selection: (_b = (_a = tableRef.current).getSelectionState) === null || _b === void 0 ? void 0 : _b.call(_a),
|
|
1051
|
+
onProgress: handleExportProgressInternal,
|
|
1052
|
+
onComplete: onExportCompleteRef.current,
|
|
1053
|
+
onError: onExportErrorRef.current,
|
|
1054
|
+
onStateChange: (s) => handleExportStateChangeInternal({ ...s, mode: "server", format, filename: fn, queueLength: queuedExportCount }),
|
|
1055
|
+
signal: controller.signal,
|
|
1056
|
+
chunkSize: cs,
|
|
1057
|
+
strictTotalCheck: st,
|
|
1058
|
+
sanitizeCSV: san,
|
|
1059
|
+
});
|
|
1060
|
+
},
|
|
1061
|
+
});
|
|
1062
|
+
},
|
|
799
1063
|
isExporting: () => exportControllerRef.current != null,
|
|
800
1064
|
cancelExport: () => handleCancelExport(),
|
|
801
1065
|
};
|
|
802
|
-
}, [dataMode, exportChunkSize, exportFilename, exportSanitizeCSV, exportStrictTotalCheck, fetchData, handleCancelExport, handleColumnFilterChangeHandler, handleExportProgressInternal, handleExportStateChangeInternal, initialStateConfig, isServerMode, isServerPagination, isServerSorting, resetAllAndReload, resetPageToFirst, runExportWithPolicy, triggerRefresh, queuedExportCount, tableRef, uiRef, serverDataRef, dataRef, onSortingChangeRef, onPaginationChangeRef, onGlobalFilterChangeRef, onColumnDragEndRef, onColumnPinningChangeRef, onServerExportRef, onExportCompleteRef, onExportErrorRef]);
|
|
1066
|
+
}, [dataMode, exportChunkSize, exportFilename, exportSanitizeCSV, exportStrictTotalCheck, fetchData, handleCancelExport, handleColumnFilterChangeHandler, handleExportProgressInternal, handleExportStateChangeInternal, initialStateConfig, isServerMode, isServerPagination, isServerSorting, resetAllAndReload, resetPageToFirst, runExportWithPolicy, triggerRefresh, queuedExportCount, tableTotalRow, idKey, tableRef, uiRef, serverDataRef, dataRef, onSortingChangeRef, onPaginationChangeRef, onGlobalFilterChangeRef, onColumnDragEndRef, onColumnPinningChangeRef, onColumnSizingChangeRef, onServerExportRef, onExportCompleteRef, onExportErrorRef]);
|
|
803
1067
|
// --- imperative handlers (used by TanStack callbacks above or view)
|
|
804
1068
|
const handleSortingChange = (0, react_1.useCallback)((updaterOrValue) => {
|
|
805
1069
|
var _a;
|