@ackplus/react-tanstack-data-table 1.0.19-beta-0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +599 -0
- package/index.d.ts.map +1 -0
- package/index.js +42 -0
- package/lib/components/droupdown/menu-dropdown.d.ts.map +1 -0
- package/lib/components/droupdown/menu-dropdown.js +47 -0
- package/lib/components/export-progress-dialog.d.ts.map +1 -0
- package/lib/components/export-progress-dialog.js +30 -0
- package/lib/components/filters/filter-value-input.d.ts.map +1 -0
- package/lib/components/filters/filter-value-input.js +64 -0
- package/lib/components/filters/index.d.ts.map +1 -0
- package/lib/components/filters/index.js +125 -0
- package/lib/components/headers/draggable-header.d.ts.map +1 -0
- package/lib/components/headers/draggable-header.js +226 -0
- package/lib/components/headers/index.d.ts.map +1 -0
- package/lib/components/headers/index.js +5 -0
- package/lib/components/headers/table-header.d.ts.map +1 -0
- package/lib/components/headers/table-header.js +59 -0
- package/lib/components/index.d.ts.map +1 -0
- package/lib/components/index.js +18 -0
- package/lib/components/pagination/data-table-pagination.d.ts.map +1 -0
- package/lib/components/pagination/data-table-pagination.js +24 -0
- package/lib/components/pagination/index.d.ts.map +1 -0
- package/lib/components/pagination/index.js +4 -0
- package/lib/components/rows/data-table-row.d.ts.map +1 -0
- package/lib/components/rows/data-table-row.js +42 -0
- package/lib/components/rows/empty-data-row.d.ts.map +1 -0
- package/lib/components/rows/empty-data-row.js +8 -0
- package/lib/components/rows/index.d.ts.map +1 -0
- package/lib/components/rows/index.js +6 -0
- package/lib/components/rows/loading-rows.d.ts.map +1 -0
- package/lib/components/rows/loading-rows.js +46 -0
- package/lib/components/table/data-table.d.ts.map +1 -0
- package/lib/components/table/data-table.js +663 -0
- package/lib/components/table/data-table.types.d.ts.map +1 -0
- package/lib/components/table/data-table.types.js +6 -0
- package/lib/components/table/index.d.ts.map +1 -0
- package/lib/components/table/index.js +5 -0
- package/lib/components/toolbar/bulk-actions-toolbar.d.ts.map +1 -0
- package/lib/components/toolbar/bulk-actions-toolbar.js +31 -0
- package/lib/components/toolbar/column-custom-filter-control.d.ts.map +1 -0
- package/lib/components/toolbar/column-custom-filter-control.js +149 -0
- package/lib/components/toolbar/column-custum-filter-control.d.ts.map +1 -0
- package/lib/components/toolbar/column-custum-filter-control.js +150 -0
- package/lib/components/toolbar/column-pinning-control.d.ts.map +1 -0
- package/lib/components/toolbar/column-pinning-control.js +103 -0
- package/lib/components/toolbar/column-reset-control.d.ts.map +1 -0
- package/lib/components/toolbar/column-reset-control.js +13 -0
- package/lib/components/toolbar/column-visibility-control.d.ts.map +1 -0
- package/lib/components/toolbar/column-visibility-control.js +27 -0
- package/lib/components/toolbar/data-table-toolbar.d.ts.map +1 -0
- package/lib/components/toolbar/data-table-toolbar.js +23 -0
- package/lib/components/toolbar/index.d.ts.map +1 -0
- package/lib/components/toolbar/index.js +13 -0
- package/lib/components/toolbar/table-export-control.d.ts.map +1 -0
- package/lib/components/toolbar/table-export-control.js +94 -0
- package/lib/components/toolbar/table-search-control.d.ts.map +1 -0
- package/lib/components/toolbar/table-search-control.js +61 -0
- package/lib/components/toolbar/table-size-control.d.ts.map +1 -0
- package/lib/components/toolbar/table-size-control.js +33 -0
- package/lib/contexts/data-table-context.d.ts.map +1 -0
- package/lib/contexts/data-table-context.js +50 -0
- package/lib/examples/advanced-features-example.d.ts.map +1 -0
- package/lib/examples/advanced-features-example.js +282 -0
- package/lib/examples/basic-example.d.ts.map +1 -0
- package/lib/examples/basic-example.js +323 -0
- package/lib/examples/bulk-actions-test.d.ts.map +1 -0
- package/lib/examples/bulk-actions-test.js +47 -0
- package/lib/examples/crud-api-example.d.ts.map +1 -0
- package/lib/examples/crud-api-example.js +321 -0
- package/lib/examples/custom-column-filter-example.d.ts.map +1 -0
- package/lib/examples/custom-column-filter-example.js +60 -0
- package/lib/examples/custom-selection-example.d.ts.map +1 -0
- package/lib/examples/custom-selection-example.js +184 -0
- package/lib/examples/export-callbacks-example.d.ts.map +1 -0
- package/lib/examples/export-callbacks-example.js +155 -0
- package/lib/examples/improved-export-example.d.ts.map +1 -0
- package/lib/examples/improved-export-example.js +153 -0
- package/lib/examples/improved-server-selection-example.d.ts.map +1 -0
- package/lib/examples/improved-server-selection-example.js +118 -0
- package/lib/examples/index.d.ts.map +1 -0
- package/lib/examples/index.js +5 -0
- package/lib/examples/selection-test-example.d.ts.map +1 -0
- package/lib/examples/selection-test-example.js +111 -0
- package/lib/examples/simple-local-example.d.ts.map +1 -0
- package/lib/examples/simple-local-example.js +101 -0
- package/lib/examples/simple-server-selection-example.d.ts.map +1 -0
- package/lib/examples/simple-server-selection-example.js +178 -0
- package/lib/examples/virtualized-example.d.ts.map +1 -0
- package/lib/examples/virtualized-example.js +119 -0
- package/lib/features/custom-column-filter.feature.d.ts.map +1 -0
- package/lib/features/custom-column-filter.feature.js +306 -0
- package/lib/features/custom-selection.feature.d.ts.map +1 -0
- package/lib/features/custom-selection.feature.js +224 -0
- package/lib/features/index.d.ts.map +1 -0
- package/lib/features/index.js +9 -0
- package/lib/hooks/index.d.ts.map +1 -0
- package/lib/hooks/index.js +6 -0
- package/lib/hooks/use-data-table-api.d.ts.map +1 -0
- package/lib/hooks/use-data-table-api.js +673 -0
- package/lib/hooks/use-table-state.d.ts.map +1 -0
- package/lib/hooks/use-table-state.js +74 -0
- package/lib/icons/add-icon.d.ts.map +1 -0
- package/lib/icons/add-icon.js +5 -0
- package/lib/icons/csv-icon.d.ts.map +1 -0
- package/lib/icons/csv-icon.js +5 -0
- package/lib/icons/delete-icon.d.ts.map +1 -0
- package/lib/icons/delete-icon.js +5 -0
- package/lib/icons/excel-icon.d.ts.map +1 -0
- package/lib/icons/excel-icon.js +5 -0
- package/lib/icons/index.d.ts.map +1 -0
- package/lib/icons/index.js +7 -0
- package/lib/icons/unpin-icon.d.ts.map +1 -0
- package/lib/icons/unpin-icon.js +5 -0
- package/lib/icons/view-comfortable-icon.d.ts.map +1 -0
- package/lib/icons/view-comfortable-icon.js +5 -0
- package/lib/icons/view-compact-icon.d.ts.map +1 -0
- package/lib/icons/view-compact-icon.js +5 -0
- package/lib/types/column.types.d.ts.map +1 -0
- package/lib/types/column.types.js +2 -0
- package/lib/types/data-table-api.d.ts.map +1 -0
- package/lib/types/data-table-api.js +1 -0
- package/lib/types/export.types.d.ts.map +1 -0
- package/lib/types/export.types.js +5 -0
- package/lib/types/hooks.types.d.ts.map +1 -0
- package/lib/types/hooks.types.js +1 -0
- package/lib/types/index.d.ts.map +1 -0
- package/lib/types/index.js +14 -0
- package/lib/types/slots.types.d.ts.map +1 -0
- package/lib/types/slots.types.js +1 -0
- package/lib/types/table.types.d.ts.map +1 -0
- package/lib/types/table.types.js +1 -0
- package/lib/utils/column-helpers.d.ts.map +1 -0
- package/lib/utils/column-helpers.js +46 -0
- package/lib/utils/debounced-fetch.utils.d.ts.map +1 -0
- package/lib/utils/debounced-fetch.utils.js +51 -0
- package/lib/utils/export-utils.d.ts.map +1 -0
- package/lib/utils/export-utils.js +181 -0
- package/lib/utils/index.d.ts.map +1 -0
- package/lib/utils/index.js +17 -0
- package/lib/utils/selection-helpers.d.ts.map +1 -0
- package/lib/utils/selection-helpers.js +162 -0
- package/lib/utils/slot-helpers.d.ts.map +1 -0
- package/lib/utils/slot-helpers.js +27 -0
- package/lib/utils/special-columns.utils.d.ts.map +1 -0
- package/lib/utils/special-columns.utils.js +77 -0
- package/lib/utils/styling-helpers.d.ts.map +1 -0
- package/lib/utils/styling-helpers.js +97 -0
- package/lib/utils/table-helpers.d.ts.map +1 -0
- package/lib/utils/table-helpers.js +72 -0
- package/lib/utils/value-helpers.d.ts.map +1 -0
- package/lib/utils/value-helpers.js +48 -0
- package/package.json +57 -0
- package/tsconfig.lib.tsbuildinfo +1 -0
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Selection Helper Utilities
|
|
3
|
+
*
|
|
4
|
+
* Common selection logic that can be shared between the API hook and selection column
|
|
5
|
+
* to avoid dependency on API reference in selection column
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Toggle select all logic
|
|
9
|
+
*/
|
|
10
|
+
export function toggleSelectAll(table, config) {
|
|
11
|
+
const { selectMode, selectionState, onSelectionStateChange } = config;
|
|
12
|
+
const isSomeSelect = isSomeSelected(config);
|
|
13
|
+
const isAllSelect = isAllSelected(table, config);
|
|
14
|
+
if (selectMode === 'all') {
|
|
15
|
+
let type;
|
|
16
|
+
if (!isAllSelect && isSomeSelect) {
|
|
17
|
+
type = 'include';
|
|
18
|
+
}
|
|
19
|
+
else if (selectionState?.type === 'include') {
|
|
20
|
+
type = 'exclude';
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
type = 'include';
|
|
24
|
+
}
|
|
25
|
+
onSelectionStateChange({
|
|
26
|
+
ids: [],
|
|
27
|
+
type,
|
|
28
|
+
});
|
|
29
|
+
// Clear TanStack Table selections
|
|
30
|
+
table.toggleAllRowsSelected(false);
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
// For 'page' mode: toggle current page selection
|
|
34
|
+
const currentPageRows = table.getPaginationRowModel().rows;
|
|
35
|
+
const isCurrentPageAllSelected = currentPageRows.every(row => selectionState?.ids.includes(row.id));
|
|
36
|
+
onSelectionStateChange({
|
|
37
|
+
ids: isCurrentPageAllSelected ? [] : currentPageRows.map(row => row.id),
|
|
38
|
+
type: 'include',
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Select all logic
|
|
44
|
+
*/
|
|
45
|
+
export function selectAll(table, config) {
|
|
46
|
+
const { selectMode, onSelectionStateChange } = config;
|
|
47
|
+
if (selectMode === 'all') {
|
|
48
|
+
// For 'all' mode: exclude nothing (select all)
|
|
49
|
+
onSelectionStateChange({
|
|
50
|
+
ids: [],
|
|
51
|
+
type: 'include',
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
// For 'page' mode: include current page rows
|
|
56
|
+
const currentPageRows = table.getPaginationRowModel().rows;
|
|
57
|
+
onSelectionStateChange({
|
|
58
|
+
ids: currentPageRows.map(row => row.id),
|
|
59
|
+
type: 'include',
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Deselect all logic
|
|
65
|
+
*/
|
|
66
|
+
export function deselectAll(table, config) {
|
|
67
|
+
const { onSelectionStateChange } = config;
|
|
68
|
+
onSelectionStateChange({
|
|
69
|
+
ids: [],
|
|
70
|
+
type: 'include',
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Toggle individual row selection
|
|
75
|
+
*/
|
|
76
|
+
export function toggleRowSelection(rowId, config, isSelect) {
|
|
77
|
+
const { selectionState, onSelectionStateChange } = config;
|
|
78
|
+
let ids = selectionState?.ids || [];
|
|
79
|
+
const hasRowId = ids.includes(rowId);
|
|
80
|
+
if (isSelect === undefined) {
|
|
81
|
+
ids = hasRowId ? ids.filter(id => id !== rowId) : [...ids, rowId];
|
|
82
|
+
}
|
|
83
|
+
else if (isSelect === true && !hasRowId) {
|
|
84
|
+
ids = [...ids, rowId];
|
|
85
|
+
}
|
|
86
|
+
else if (isSelect === false && hasRowId) {
|
|
87
|
+
ids = ids.filter(id => id !== rowId);
|
|
88
|
+
}
|
|
89
|
+
onSelectionStateChange({
|
|
90
|
+
ids,
|
|
91
|
+
type: selectionState?.type || 'include',
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Check if all rows are selected
|
|
96
|
+
*/
|
|
97
|
+
export function isAllSelected(table, config) {
|
|
98
|
+
const { selectMode, selectionState } = config;
|
|
99
|
+
if (!selectionState) {
|
|
100
|
+
return false;
|
|
101
|
+
}
|
|
102
|
+
if (selectMode === 'all') {
|
|
103
|
+
if (selectionState.type === 'exclude') {
|
|
104
|
+
return selectionState.ids.length === 0;
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
107
|
+
return selectionState.ids.length === table.getRowCount();
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
else {
|
|
111
|
+
const currentPageRows = table.getPaginationRowModel().rows;
|
|
112
|
+
return currentPageRows.every(row => selectionState?.ids.includes(row.id));
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Check if some rows are selected (indeterminate state)
|
|
117
|
+
*/
|
|
118
|
+
export function isSomeSelected(config) {
|
|
119
|
+
const { selectMode, selectionState } = config;
|
|
120
|
+
if (selectMode === 'all') {
|
|
121
|
+
if (!selectionState) {
|
|
122
|
+
return false;
|
|
123
|
+
}
|
|
124
|
+
return (selectionState.type === 'exclude' && selectionState.ids?.length > 0) ||
|
|
125
|
+
(selectionState.type === 'include' && selectionState.ids?.length > 0);
|
|
126
|
+
}
|
|
127
|
+
else {
|
|
128
|
+
return selectionState?.ids?.length > 0;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Check if a specific row is selected
|
|
133
|
+
*/
|
|
134
|
+
export function isRowSelected(rowId, config) {
|
|
135
|
+
const { selectMode, selectionState } = config;
|
|
136
|
+
if (!selectionState) {
|
|
137
|
+
return false;
|
|
138
|
+
}
|
|
139
|
+
if (selectMode === 'all' && selectionState?.type === 'exclude') {
|
|
140
|
+
// all selection mode
|
|
141
|
+
return !selectionState.ids.includes(rowId);
|
|
142
|
+
}
|
|
143
|
+
else {
|
|
144
|
+
// In individual mode, selected only if included
|
|
145
|
+
return selectionState.ids.includes(rowId);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Get selected row count
|
|
150
|
+
*/
|
|
151
|
+
export function getSelectedCount(config) {
|
|
152
|
+
const { selectMode, selectionState, totalRow } = config;
|
|
153
|
+
if (!selectionState) {
|
|
154
|
+
return 0;
|
|
155
|
+
}
|
|
156
|
+
if (selectMode === 'all' && selectionState.type === 'exclude') {
|
|
157
|
+
return (totalRow || 0) - selectionState.ids.length;
|
|
158
|
+
}
|
|
159
|
+
else {
|
|
160
|
+
return selectionState.ids.length;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"slot-helpers.d.ts","sourceRoot":"","sources":["../../../src/lib/utils/slot-helpers.tsx"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAEtC,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAGtD;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,CAAC,SAAS,MAAM,cAAc,CAAC,CAAC,CAAC,EACjE,KAAK,EAAE,OAAO,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,GAAG,SAAS,EAC7C,QAAQ,EAAE,CAAC,EACX,QAAQ,EAAE,aAAa,CAAC,GAAG,CAAC,GAC7B,aAAa,CAAC,GAAG,CAAC,CAEpB;AAED;;GAEG;AACH,wBAAgB,UAAU,CACtB,aAAa,EAAE,aAAa,CAAC,GAAG,CAAC,EACjC,YAAY,EAAE,GAAG,EACjB,SAAS,CAAC,EAAE,GAAG,2CASlB;AAED;;GAEG;AACH,wBAAgB,wBAAwB,CAAC,CAAC,EAAE,CAAC,SAAS,MAAM,cAAc,CAAC,CAAC,CAAC,EACzE,QAAQ,EAAE,CAAC,EACX,gBAAgB,EAAE,aAAa,CAAC,GAAG,CAAC,IAED,OAAO;IACtC,KAAK,CAAC,EAAE,OAAO,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,CAAC;IACnC,SAAS,CAAC,EAAE,GAAG,CAAC;IAChB,cAAc,EAAE,GAAG,CAAC;CACvB,6CAaJ"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* Get slot component or fallback to default
|
|
4
|
+
*/
|
|
5
|
+
export function getSlotComponent(slots, slotName, fallback) {
|
|
6
|
+
return slots?.[slotName] || fallback;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Render a slot component with merged props
|
|
10
|
+
*/
|
|
11
|
+
export function renderSlot(slotComponent, defaultProps, slotProps) {
|
|
12
|
+
const mergedProps = {
|
|
13
|
+
...defaultProps,
|
|
14
|
+
...slotProps,
|
|
15
|
+
};
|
|
16
|
+
const Component = slotComponent;
|
|
17
|
+
return _jsx(Component, { ...mergedProps });
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Higher-order component factory for creating slottable components
|
|
21
|
+
*/
|
|
22
|
+
export function createSlottableComponent(slotName, defaultComponent) {
|
|
23
|
+
return function SlottableComponent(props) {
|
|
24
|
+
const SlotComponent = getSlotComponent(props.slots, slotName, defaultComponent);
|
|
25
|
+
return renderSlot(SlotComponent, props.componentProps, props.slotProps?.[slotName]);
|
|
26
|
+
};
|
|
27
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"special-columns.utils.d.ts","sourceRoot":"","sources":["../../../src/lib/utils/special-columns.utils.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,eAAe,EAAgE,MAAM,UAAU,CAAC;AAEzG;;GAEG;AACH,MAAM,WAAW,qBAAqB,CAAC,CAAC;IACpC,WAAW,CAAC,EAAE,OAAO,CAAC;CAEzB;AAED;;GAEG;AACH,eAAO,MAAM,qBAAqB,GAAI,CAAC,EAAE,QAAQ,OAAO,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,GAAG,qBAAqB,CAAC,CAAC,CAAC,KAAG,eAAe,CAAC,CAAC,CAoDzH,CAAC;AAEH;;GAEG;AACH,eAAO,MAAM,qBAAqB,GAAI,CAAC,EAAE,QAAQ,OAAO,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,KAAG,eAAe,CAAC,CAAC,CAiB9F,CAAC"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { KeyboardArrowDownOutlined, KeyboardArrowUpOutlined } from '@mui/icons-material';
|
|
2
|
+
import { Checkbox, IconButton } from '@mui/material';
|
|
3
|
+
import { createElement } from 'react';
|
|
4
|
+
import { DEFAULT_EXPANDING_COLUMN_NAME, DEFAULT_SELECTION_COLUMN_NAME } from '../types';
|
|
5
|
+
/**
|
|
6
|
+
* Creates a default selection column using TanStack Table custom feature methods
|
|
7
|
+
*/
|
|
8
|
+
export const createSelectionColumn = (config) => ({
|
|
9
|
+
id: DEFAULT_SELECTION_COLUMN_NAME,
|
|
10
|
+
size: 60,
|
|
11
|
+
align: 'center',
|
|
12
|
+
filterable: false,
|
|
13
|
+
enableResizing: false,
|
|
14
|
+
enableSorting: false,
|
|
15
|
+
enableHiding: false,
|
|
16
|
+
enablePinning: false,
|
|
17
|
+
hideInExport: true,
|
|
18
|
+
header: ({ table }) => {
|
|
19
|
+
if (!config.multiSelect)
|
|
20
|
+
return null;
|
|
21
|
+
// Use TanStack Table custom feature methods (same pattern as TanStack documentation)
|
|
22
|
+
const allSelected = table.getIsAllRowsSelected?.() || false;
|
|
23
|
+
const someSelected = table.getIsSomeRowsSelected?.() || false;
|
|
24
|
+
return createElement(Checkbox, {
|
|
25
|
+
checked: allSelected,
|
|
26
|
+
indeterminate: someSelected && !allSelected,
|
|
27
|
+
disabled: false,
|
|
28
|
+
onChange: () => {
|
|
29
|
+
table.toggleAllRowsSelected?.();
|
|
30
|
+
},
|
|
31
|
+
size: 'small',
|
|
32
|
+
sx: { p: 0 },
|
|
33
|
+
});
|
|
34
|
+
},
|
|
35
|
+
cell: ({ row, table }) => {
|
|
36
|
+
const rowId = row.id;
|
|
37
|
+
// Use TanStack Table custom feature methods (same pattern as TanStack documentation)
|
|
38
|
+
const checked = table.getIsRowSelected?.(rowId) || false;
|
|
39
|
+
const canSelect = table.canSelectRow?.(rowId) ?? true;
|
|
40
|
+
return createElement(Checkbox, {
|
|
41
|
+
checked,
|
|
42
|
+
disabled: !canSelect,
|
|
43
|
+
onChange: () => {
|
|
44
|
+
if (canSelect) {
|
|
45
|
+
table.toggleRowSelected?.(rowId);
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
size: 'small',
|
|
49
|
+
sx: {
|
|
50
|
+
p: 0,
|
|
51
|
+
opacity: canSelect ? 1 : 0.5
|
|
52
|
+
},
|
|
53
|
+
});
|
|
54
|
+
},
|
|
55
|
+
...config,
|
|
56
|
+
});
|
|
57
|
+
/**
|
|
58
|
+
* Creates a default expanding column
|
|
59
|
+
*/
|
|
60
|
+
export const createExpandingColumn = (config) => ({
|
|
61
|
+
id: DEFAULT_EXPANDING_COLUMN_NAME,
|
|
62
|
+
size: 60,
|
|
63
|
+
align: 'center',
|
|
64
|
+
filterable: false,
|
|
65
|
+
enableResizing: false,
|
|
66
|
+
enableSorting: false,
|
|
67
|
+
enableHiding: false,
|
|
68
|
+
enablePinning: false,
|
|
69
|
+
hideInExport: true,
|
|
70
|
+
header: '',
|
|
71
|
+
cell: ({ row }) => createElement(IconButton, {
|
|
72
|
+
onClick: row.getToggleExpandedHandler(),
|
|
73
|
+
size: 'small',
|
|
74
|
+
sx: { p: 0 },
|
|
75
|
+
}, row.getIsExpanded() ? createElement(KeyboardArrowUpOutlined) : createElement(KeyboardArrowDownOutlined)),
|
|
76
|
+
...config,
|
|
77
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"styling-helpers.d.ts","sourceRoot":"","sources":["../../../src/lib/utils/styling-helpers.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,KAAK,EAAE,eAAe,EAAE,wBAAwB,EAAE,MAAM,UAAU,CAAC;AAqB1E;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,wBAAwB;;;;;;;;;;EAmDrE;AAED;;GAEG;AACH,eAAO,MAAM,eAAe;;;;;;;;;;CAUlB,CAAC;AAEX;;GAEG;AACH,eAAO,MAAM,cAAc;;;;;;;;;;;CAWjB,CAAC;AAEX;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,CAAC,EAAE,eAAe,CAAC,GAAG,CAAC,GAAG,MAAM,GAAG,QAAQ,GAAG,OAAO,CAG7F"}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Styling utilities for DataTable components
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Generate box shadow for pinned columns using subtle theme-compatible shadows
|
|
6
|
+
* Only shows shadow on the trailing edge of pinned columns
|
|
7
|
+
*/
|
|
8
|
+
const getBoxShadow = (isPinned, isLastLeftPinnedColumn, isFirstRightPinnedColumn) => {
|
|
9
|
+
if (isPinned === 'left' && isLastLeftPinnedColumn) {
|
|
10
|
+
// Subtle shadow on right side of left-pinned column
|
|
11
|
+
return '1px 0 3px rgba(0, 0, 0, 0.12)';
|
|
12
|
+
}
|
|
13
|
+
if (isPinned === 'right' && isFirstRightPinnedColumn) {
|
|
14
|
+
// Subtle shadow on left side of right-pinned column
|
|
15
|
+
return '-1px 0 3px rgba(0, 0, 0, 0.12)';
|
|
16
|
+
}
|
|
17
|
+
return 'none';
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Generate consistent styling for pinned columns
|
|
21
|
+
*/
|
|
22
|
+
export function getPinnedColumnStyle(options) {
|
|
23
|
+
const { width = 'auto', isPinned, pinnedPosition, pinnedRightPosition, isLastLeftPinnedColumn, isFirstRightPinnedColumn, zIndex = 1, disableStickyHeader = false, } = options;
|
|
24
|
+
// Pinned columns should ALWAYS be sticky, regardless of enableStickyHeader setting
|
|
25
|
+
const needsPinnedPositioning = isPinned;
|
|
26
|
+
const shouldBeSticky = isPinned; // Pinned columns are always sticky
|
|
27
|
+
// Position logic
|
|
28
|
+
let positionStyle = {};
|
|
29
|
+
if (shouldBeSticky) {
|
|
30
|
+
// Pinned columns must always be sticky
|
|
31
|
+
positionStyle = { position: 'sticky' };
|
|
32
|
+
}
|
|
33
|
+
else if (!disableStickyHeader) {
|
|
34
|
+
// Non-pinned columns: only sticky when enableStickyHeader is false
|
|
35
|
+
positionStyle = { position: 'relative' };
|
|
36
|
+
}
|
|
37
|
+
// When disableStickyHeader is true and column is not pinned, let Table handle stickiness
|
|
38
|
+
return {
|
|
39
|
+
// Width constraints - more strict for narrow columns
|
|
40
|
+
width,
|
|
41
|
+
maxWidth: width,
|
|
42
|
+
overflow: 'hidden',
|
|
43
|
+
whiteSpace: 'nowrap',
|
|
44
|
+
// Position handling
|
|
45
|
+
...positionStyle,
|
|
46
|
+
// Pinned positioning (works with both sticky modes)
|
|
47
|
+
...(needsPinnedPositioning ? {
|
|
48
|
+
left: isPinned === 'left' ? pinnedPosition : undefined,
|
|
49
|
+
right: isPinned === 'right' ? pinnedRightPosition : undefined,
|
|
50
|
+
zIndex,
|
|
51
|
+
} : {}),
|
|
52
|
+
// Background handling for pinned columns - simpler approach
|
|
53
|
+
...(isPinned && {
|
|
54
|
+
// Use theme background as fallback, but allow inheritance from parent
|
|
55
|
+
backgroundColor: 'background.paper',
|
|
56
|
+
}),
|
|
57
|
+
// Box shadow only on trailing edge with subtle shadows
|
|
58
|
+
boxShadow: getBoxShadow(isPinned, !!isLastLeftPinnedColumn, !!isFirstRightPinnedColumn),
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Common table cell styling
|
|
63
|
+
*/
|
|
64
|
+
export const tableCellStyles = {
|
|
65
|
+
sticky: {
|
|
66
|
+
position: 'sticky',
|
|
67
|
+
zIndex: 10,
|
|
68
|
+
backgroundColor: 'background.paper',
|
|
69
|
+
},
|
|
70
|
+
pinned: {
|
|
71
|
+
borderRight: '1px solid',
|
|
72
|
+
borderColor: 'divider',
|
|
73
|
+
},
|
|
74
|
+
};
|
|
75
|
+
/**
|
|
76
|
+
* Common table row styling
|
|
77
|
+
*/
|
|
78
|
+
export const tableRowStyles = {
|
|
79
|
+
hover: {
|
|
80
|
+
'&:hover': {
|
|
81
|
+
backgroundColor: 'action.hover',
|
|
82
|
+
},
|
|
83
|
+
},
|
|
84
|
+
striped: {
|
|
85
|
+
'&:nth-of-type(odd)': {
|
|
86
|
+
backgroundColor: 'action.selected',
|
|
87
|
+
},
|
|
88
|
+
},
|
|
89
|
+
};
|
|
90
|
+
/**
|
|
91
|
+
* Get text alignment style from column metadata
|
|
92
|
+
*/
|
|
93
|
+
export function getColumnAlignment(column) {
|
|
94
|
+
if (!column)
|
|
95
|
+
return 'left';
|
|
96
|
+
return column.align || 'left';
|
|
97
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"table-helpers.d.ts","sourceRoot":"","sources":["../../../src/lib/utils/table-helpers.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAG7C,MAAM,MAAM,aAAa,GAAG,OAAO,GAAG,QAAQ,CAAC;AAE/C;;GAEG;AACH,wBAAgB,qBAAqB,CACjC,eAAe,EAAE,MAAM,EACvB,SAAS,EAAE,MAAM,EACjB,OAAO,SAAK,GACb,MAAM,CAGR;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,CAAC,GAAG,MAAM,CAK/E;AAED;;GAEG;AACH,wBAAgB,2BAA2B,CACvC,OAAO,EAAE,GAAG,EAAE,EACd,IAAI,EAAE,MAAM,GAAG,OAAO,GACvB,MAAM,CAIR;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAChC,WAAW,EAAE,OAAO,EACpB,oBAAoB,EAAE,OAAO,EAC7B,YAAY,EAAE,MAAM,GACrB,OAAO,CAET;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAehE;AAED;;GAEG;AACH,wBAAgB,QAAQ,CAAC,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,EACtD,IAAI,EAAE,CAAC,EACP,IAAI,EAAE,MAAM,GACb,CAAC,GAAG,IAAI,EAAE,UAAU,CAAC,CAAC,CAAC,KAAK,IAAI,CAMlC;AAED;;GAEG;AAEH,wBAAgB,qBAAqB,CACjC,SAAS,EAAE,MAAM,EACjB,WAAW,EAAE,MAAM,EACnB,OAAO,EAAE,GAAG,EAAE,EACd,eAAe,EAAE,MAAM,GACxB,YAAY,CAOd"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* General table utilities for DataTable components
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Calculate skeleton rows count based on viewport and row height
|
|
6
|
+
*/
|
|
7
|
+
export function calculateSkeletonRows(containerHeight, rowHeight, maxRows = 10) {
|
|
8
|
+
const estimatedRows = Math.ceil(containerHeight / rowHeight);
|
|
9
|
+
return Math.min(estimatedRows, maxRows);
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Generate unique row ID for virtualization
|
|
13
|
+
*/
|
|
14
|
+
export function generateRowId(row, index, idKey) {
|
|
15
|
+
if (idKey && row[idKey]) {
|
|
16
|
+
return String(row[idKey]);
|
|
17
|
+
}
|
|
18
|
+
return `row-${index}`;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Calculate total width of pinned columns
|
|
22
|
+
*/
|
|
23
|
+
export function calculatePinnedColumnsWidth(columns, side) {
|
|
24
|
+
return columns
|
|
25
|
+
.filter(col => col.getIsPinned() === side)
|
|
26
|
+
.reduce((total, col) => total + (col.getSize() || 0), 0);
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Check if table should use fixed layout
|
|
30
|
+
*/
|
|
31
|
+
export function shouldUseFixedLayout(fitToScreen, enableColumnResizing, totalColumns) {
|
|
32
|
+
return fitToScreen || (enableColumnResizing && totalColumns > 5);
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Format cell value based on column type
|
|
36
|
+
*/
|
|
37
|
+
export function formatCellValue(value, type) {
|
|
38
|
+
if (value === null || value === undefined) {
|
|
39
|
+
return '-';
|
|
40
|
+
}
|
|
41
|
+
switch (type) {
|
|
42
|
+
case 'date':
|
|
43
|
+
return value instanceof Date ? value.toLocaleDateString() : String(value);
|
|
44
|
+
case 'number':
|
|
45
|
+
return typeof value === 'number' ? value.toLocaleString() : String(value);
|
|
46
|
+
case 'boolean':
|
|
47
|
+
return value ? 'Yes' : 'No';
|
|
48
|
+
default:
|
|
49
|
+
return String(value);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Debounce function for search and filters
|
|
54
|
+
*/
|
|
55
|
+
export function debounce(func, wait) {
|
|
56
|
+
let timeout;
|
|
57
|
+
return (...args) => {
|
|
58
|
+
clearTimeout(timeout);
|
|
59
|
+
timeout = setTimeout(() => func(...args), wait);
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Get table performance metrics
|
|
64
|
+
*/
|
|
65
|
+
export function calculateTableMetrics(totalRows, visibleRows, columns, renderStartTime) {
|
|
66
|
+
return {
|
|
67
|
+
totalRows,
|
|
68
|
+
visibleRows,
|
|
69
|
+
pinnedColumns: columns.filter(col => col.getIsPinned()).length,
|
|
70
|
+
renderTime: performance.now() - renderStartTime,
|
|
71
|
+
};
|
|
72
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"value-helpers.d.ts","sourceRoot":"","sources":["../../../src/lib/utils/value-helpers.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAC;AAErD;;;GAGG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,oBAAoB,GAAG,GAAG,CAqB9D;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,oBAAoB,GAAG,GAAG,CAGnE;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,KAEtB,2BAA2B,GAAG,SAOzC"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Common value processing utilities for cell display and export
|
|
3
|
+
* Uses TanStack Table's built-in functionality instead of custom valueGetter/valueFormatter
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Get the raw value from a cell using TanStack Table's built-in methods
|
|
7
|
+
* This is the single source of truth for value processing
|
|
8
|
+
*/
|
|
9
|
+
export function getCellValue(params) {
|
|
10
|
+
const { row, getValue, column } = params;
|
|
11
|
+
const colDef = column.columnDef || column;
|
|
12
|
+
const rowData = row.original || row;
|
|
13
|
+
// Use TanStack Table's getValue for cell display (preferred)
|
|
14
|
+
if (getValue) {
|
|
15
|
+
return getValue();
|
|
16
|
+
}
|
|
17
|
+
// Use accessor function if available
|
|
18
|
+
if (colDef?.accessorFn) {
|
|
19
|
+
return colDef.accessorFn(rowData);
|
|
20
|
+
}
|
|
21
|
+
// Fallback to direct property access
|
|
22
|
+
if (colDef?.accessorKey) {
|
|
23
|
+
return rowData[colDef.accessorKey];
|
|
24
|
+
}
|
|
25
|
+
return undefined;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* @deprecated Use TanStack Table's built-in cell rendering instead
|
|
29
|
+
* This function is kept for backward compatibility but should not be used in new code
|
|
30
|
+
*/
|
|
31
|
+
export function getFormattedValue(params) {
|
|
32
|
+
console.warn('getFormattedValue is deprecated. Use TanStack Table\'s built-in cell rendering with accessorFn instead.');
|
|
33
|
+
return getCellValue(params);
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* @deprecated Use TanStack Table's built-in cell rendering instead
|
|
37
|
+
* This function is kept for backward compatibility but should not be used in new code
|
|
38
|
+
*/
|
|
39
|
+
export function createEnhancedCell() {
|
|
40
|
+
console.warn('createEnhancedCell is deprecated. Use TanStack Table\'s built-in cell rendering instead.');
|
|
41
|
+
return ({ row, getValue, column }) => {
|
|
42
|
+
return getCellValue({
|
|
43
|
+
row,
|
|
44
|
+
getValue,
|
|
45
|
+
column,
|
|
46
|
+
});
|
|
47
|
+
};
|
|
48
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@ackplus/react-tanstack-data-table",
|
|
3
|
+
"version": "1.0.19-beta-0.6",
|
|
4
|
+
"description": "A powerful React data table component built with MUI and TanStack Table",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"react",
|
|
7
|
+
"table",
|
|
8
|
+
"data-table",
|
|
9
|
+
"tanstack",
|
|
10
|
+
"mui",
|
|
11
|
+
"material-ui",
|
|
12
|
+
"typescript",
|
|
13
|
+
"component"
|
|
14
|
+
],
|
|
15
|
+
"author": {
|
|
16
|
+
"name": "ACK Plus",
|
|
17
|
+
"email": "your-email@example.com"
|
|
18
|
+
},
|
|
19
|
+
"license": "MIT",
|
|
20
|
+
"homepage": "https://github.com/ack-solutions/react-tanstack-data-table/packages/#readme",
|
|
21
|
+
"repository": {
|
|
22
|
+
"type": "git",
|
|
23
|
+
"url": "git+https://github.com/ack-solutions/react-tanstack-data-table.git"
|
|
24
|
+
},
|
|
25
|
+
"bugs": {
|
|
26
|
+
"url": "https://github.com/ack-solutions/react-tanstack-data-table/issues"
|
|
27
|
+
},
|
|
28
|
+
"main": "./index.js",
|
|
29
|
+
"types": "./index.d.ts",
|
|
30
|
+
"peerDependencies": {
|
|
31
|
+
"@emotion/react": ">=11.0.0",
|
|
32
|
+
"@emotion/styled": ">=11.0.0",
|
|
33
|
+
"@mui/icons-material": ">=5.0.0 || ^6.0.0 || ^7.0.0",
|
|
34
|
+
"@mui/material": ">=5.0.0 || ^6.0.0 || ^7.0.0",
|
|
35
|
+
"@tanstack/react-table": ">=8.10.0",
|
|
36
|
+
"@tanstack/react-virtual": ">=3.0.0",
|
|
37
|
+
"react": ">=18.0.0 || ^19.0.0",
|
|
38
|
+
"react-dom": ">=18.0.0 || ^19.0.0",
|
|
39
|
+
"xlsx": ">=0.18.0",
|
|
40
|
+
"moment": ">=2.29.0",
|
|
41
|
+
"@mui/x-date-pickers": ">=5.0.0 || ^6.0.0 || ^7.0.0 || ^8.0.0"
|
|
42
|
+
},
|
|
43
|
+
"devDependencies": {
|
|
44
|
+
"@types/react": "^19.0.0",
|
|
45
|
+
"@types/react-dom": "^19.0.0",
|
|
46
|
+
"typescript": "^5.8.2"
|
|
47
|
+
},
|
|
48
|
+
"exports": {
|
|
49
|
+
"./package.json": "./package.json",
|
|
50
|
+
".": {
|
|
51
|
+
"development": "./src/index.ts",
|
|
52
|
+
"types": "./dist/index.d.ts",
|
|
53
|
+
"import": "./dist/index.js",
|
|
54
|
+
"default": "./dist/index.js"
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|