@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.
Files changed (154) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +599 -0
  3. package/index.d.ts.map +1 -0
  4. package/index.js +42 -0
  5. package/lib/components/droupdown/menu-dropdown.d.ts.map +1 -0
  6. package/lib/components/droupdown/menu-dropdown.js +47 -0
  7. package/lib/components/export-progress-dialog.d.ts.map +1 -0
  8. package/lib/components/export-progress-dialog.js +30 -0
  9. package/lib/components/filters/filter-value-input.d.ts.map +1 -0
  10. package/lib/components/filters/filter-value-input.js +64 -0
  11. package/lib/components/filters/index.d.ts.map +1 -0
  12. package/lib/components/filters/index.js +125 -0
  13. package/lib/components/headers/draggable-header.d.ts.map +1 -0
  14. package/lib/components/headers/draggable-header.js +226 -0
  15. package/lib/components/headers/index.d.ts.map +1 -0
  16. package/lib/components/headers/index.js +5 -0
  17. package/lib/components/headers/table-header.d.ts.map +1 -0
  18. package/lib/components/headers/table-header.js +59 -0
  19. package/lib/components/index.d.ts.map +1 -0
  20. package/lib/components/index.js +18 -0
  21. package/lib/components/pagination/data-table-pagination.d.ts.map +1 -0
  22. package/lib/components/pagination/data-table-pagination.js +24 -0
  23. package/lib/components/pagination/index.d.ts.map +1 -0
  24. package/lib/components/pagination/index.js +4 -0
  25. package/lib/components/rows/data-table-row.d.ts.map +1 -0
  26. package/lib/components/rows/data-table-row.js +42 -0
  27. package/lib/components/rows/empty-data-row.d.ts.map +1 -0
  28. package/lib/components/rows/empty-data-row.js +8 -0
  29. package/lib/components/rows/index.d.ts.map +1 -0
  30. package/lib/components/rows/index.js +6 -0
  31. package/lib/components/rows/loading-rows.d.ts.map +1 -0
  32. package/lib/components/rows/loading-rows.js +46 -0
  33. package/lib/components/table/data-table.d.ts.map +1 -0
  34. package/lib/components/table/data-table.js +663 -0
  35. package/lib/components/table/data-table.types.d.ts.map +1 -0
  36. package/lib/components/table/data-table.types.js +6 -0
  37. package/lib/components/table/index.d.ts.map +1 -0
  38. package/lib/components/table/index.js +5 -0
  39. package/lib/components/toolbar/bulk-actions-toolbar.d.ts.map +1 -0
  40. package/lib/components/toolbar/bulk-actions-toolbar.js +31 -0
  41. package/lib/components/toolbar/column-custom-filter-control.d.ts.map +1 -0
  42. package/lib/components/toolbar/column-custom-filter-control.js +149 -0
  43. package/lib/components/toolbar/column-custum-filter-control.d.ts.map +1 -0
  44. package/lib/components/toolbar/column-custum-filter-control.js +150 -0
  45. package/lib/components/toolbar/column-pinning-control.d.ts.map +1 -0
  46. package/lib/components/toolbar/column-pinning-control.js +103 -0
  47. package/lib/components/toolbar/column-reset-control.d.ts.map +1 -0
  48. package/lib/components/toolbar/column-reset-control.js +13 -0
  49. package/lib/components/toolbar/column-visibility-control.d.ts.map +1 -0
  50. package/lib/components/toolbar/column-visibility-control.js +27 -0
  51. package/lib/components/toolbar/data-table-toolbar.d.ts.map +1 -0
  52. package/lib/components/toolbar/data-table-toolbar.js +23 -0
  53. package/lib/components/toolbar/index.d.ts.map +1 -0
  54. package/lib/components/toolbar/index.js +13 -0
  55. package/lib/components/toolbar/table-export-control.d.ts.map +1 -0
  56. package/lib/components/toolbar/table-export-control.js +94 -0
  57. package/lib/components/toolbar/table-search-control.d.ts.map +1 -0
  58. package/lib/components/toolbar/table-search-control.js +61 -0
  59. package/lib/components/toolbar/table-size-control.d.ts.map +1 -0
  60. package/lib/components/toolbar/table-size-control.js +33 -0
  61. package/lib/contexts/data-table-context.d.ts.map +1 -0
  62. package/lib/contexts/data-table-context.js +50 -0
  63. package/lib/examples/advanced-features-example.d.ts.map +1 -0
  64. package/lib/examples/advanced-features-example.js +282 -0
  65. package/lib/examples/basic-example.d.ts.map +1 -0
  66. package/lib/examples/basic-example.js +323 -0
  67. package/lib/examples/bulk-actions-test.d.ts.map +1 -0
  68. package/lib/examples/bulk-actions-test.js +47 -0
  69. package/lib/examples/crud-api-example.d.ts.map +1 -0
  70. package/lib/examples/crud-api-example.js +321 -0
  71. package/lib/examples/custom-column-filter-example.d.ts.map +1 -0
  72. package/lib/examples/custom-column-filter-example.js +60 -0
  73. package/lib/examples/custom-selection-example.d.ts.map +1 -0
  74. package/lib/examples/custom-selection-example.js +184 -0
  75. package/lib/examples/export-callbacks-example.d.ts.map +1 -0
  76. package/lib/examples/export-callbacks-example.js +155 -0
  77. package/lib/examples/improved-export-example.d.ts.map +1 -0
  78. package/lib/examples/improved-export-example.js +153 -0
  79. package/lib/examples/improved-server-selection-example.d.ts.map +1 -0
  80. package/lib/examples/improved-server-selection-example.js +118 -0
  81. package/lib/examples/index.d.ts.map +1 -0
  82. package/lib/examples/index.js +5 -0
  83. package/lib/examples/selection-test-example.d.ts.map +1 -0
  84. package/lib/examples/selection-test-example.js +111 -0
  85. package/lib/examples/simple-local-example.d.ts.map +1 -0
  86. package/lib/examples/simple-local-example.js +101 -0
  87. package/lib/examples/simple-server-selection-example.d.ts.map +1 -0
  88. package/lib/examples/simple-server-selection-example.js +178 -0
  89. package/lib/examples/virtualized-example.d.ts.map +1 -0
  90. package/lib/examples/virtualized-example.js +119 -0
  91. package/lib/features/custom-column-filter.feature.d.ts.map +1 -0
  92. package/lib/features/custom-column-filter.feature.js +306 -0
  93. package/lib/features/custom-selection.feature.d.ts.map +1 -0
  94. package/lib/features/custom-selection.feature.js +224 -0
  95. package/lib/features/index.d.ts.map +1 -0
  96. package/lib/features/index.js +9 -0
  97. package/lib/hooks/index.d.ts.map +1 -0
  98. package/lib/hooks/index.js +6 -0
  99. package/lib/hooks/use-data-table-api.d.ts.map +1 -0
  100. package/lib/hooks/use-data-table-api.js +673 -0
  101. package/lib/hooks/use-table-state.d.ts.map +1 -0
  102. package/lib/hooks/use-table-state.js +74 -0
  103. package/lib/icons/add-icon.d.ts.map +1 -0
  104. package/lib/icons/add-icon.js +5 -0
  105. package/lib/icons/csv-icon.d.ts.map +1 -0
  106. package/lib/icons/csv-icon.js +5 -0
  107. package/lib/icons/delete-icon.d.ts.map +1 -0
  108. package/lib/icons/delete-icon.js +5 -0
  109. package/lib/icons/excel-icon.d.ts.map +1 -0
  110. package/lib/icons/excel-icon.js +5 -0
  111. package/lib/icons/index.d.ts.map +1 -0
  112. package/lib/icons/index.js +7 -0
  113. package/lib/icons/unpin-icon.d.ts.map +1 -0
  114. package/lib/icons/unpin-icon.js +5 -0
  115. package/lib/icons/view-comfortable-icon.d.ts.map +1 -0
  116. package/lib/icons/view-comfortable-icon.js +5 -0
  117. package/lib/icons/view-compact-icon.d.ts.map +1 -0
  118. package/lib/icons/view-compact-icon.js +5 -0
  119. package/lib/types/column.types.d.ts.map +1 -0
  120. package/lib/types/column.types.js +2 -0
  121. package/lib/types/data-table-api.d.ts.map +1 -0
  122. package/lib/types/data-table-api.js +1 -0
  123. package/lib/types/export.types.d.ts.map +1 -0
  124. package/lib/types/export.types.js +5 -0
  125. package/lib/types/hooks.types.d.ts.map +1 -0
  126. package/lib/types/hooks.types.js +1 -0
  127. package/lib/types/index.d.ts.map +1 -0
  128. package/lib/types/index.js +14 -0
  129. package/lib/types/slots.types.d.ts.map +1 -0
  130. package/lib/types/slots.types.js +1 -0
  131. package/lib/types/table.types.d.ts.map +1 -0
  132. package/lib/types/table.types.js +1 -0
  133. package/lib/utils/column-helpers.d.ts.map +1 -0
  134. package/lib/utils/column-helpers.js +46 -0
  135. package/lib/utils/debounced-fetch.utils.d.ts.map +1 -0
  136. package/lib/utils/debounced-fetch.utils.js +51 -0
  137. package/lib/utils/export-utils.d.ts.map +1 -0
  138. package/lib/utils/export-utils.js +181 -0
  139. package/lib/utils/index.d.ts.map +1 -0
  140. package/lib/utils/index.js +17 -0
  141. package/lib/utils/selection-helpers.d.ts.map +1 -0
  142. package/lib/utils/selection-helpers.js +162 -0
  143. package/lib/utils/slot-helpers.d.ts.map +1 -0
  144. package/lib/utils/slot-helpers.js +27 -0
  145. package/lib/utils/special-columns.utils.d.ts.map +1 -0
  146. package/lib/utils/special-columns.utils.js +77 -0
  147. package/lib/utils/styling-helpers.d.ts.map +1 -0
  148. package/lib/utils/styling-helpers.js +97 -0
  149. package/lib/utils/table-helpers.d.ts.map +1 -0
  150. package/lib/utils/table-helpers.js +72 -0
  151. package/lib/utils/value-helpers.d.ts.map +1 -0
  152. package/lib/utils/value-helpers.js +48 -0
  153. package/package.json +57 -0
  154. package/tsconfig.lib.tsbuildinfo +1 -0
@@ -0,0 +1,155 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { Box, Button, Alert, LinearProgress, Typography, Card, CardContent } from '@mui/material';
3
+ import { useState, useRef } from 'react';
4
+ import { DataTable } from '../components/table/data-table';
5
+ // Sample data
6
+ const sampleData = Array.from({ length: 1000 }, (_, i) => ({
7
+ id: i + 1,
8
+ name: `User ${i + 1}`,
9
+ email: `user${i + 1}@example.com`,
10
+ age: Math.floor(Math.random() * 50) + 20,
11
+ city: [
12
+ 'New York',
13
+ 'London',
14
+ 'Tokyo',
15
+ 'Paris',
16
+ 'Berlin',
17
+ ][Math.floor(Math.random() * 5)],
18
+ status: [
19
+ 'Active',
20
+ 'Inactive',
21
+ 'Pending',
22
+ ][Math.floor(Math.random() * 3)],
23
+ }));
24
+ const columns = [
25
+ {
26
+ accessorKey: 'id',
27
+ header: 'ID',
28
+ size: 80,
29
+ },
30
+ {
31
+ accessorKey: 'name',
32
+ header: 'Name',
33
+ size: 150,
34
+ },
35
+ {
36
+ accessorKey: 'email',
37
+ header: 'Email',
38
+ size: 200,
39
+ },
40
+ {
41
+ accessorKey: 'age',
42
+ header: 'Age',
43
+ size: 80,
44
+ },
45
+ {
46
+ accessorKey: 'city',
47
+ header: 'City',
48
+ size: 120,
49
+ },
50
+ {
51
+ accessorKey: 'status',
52
+ header: 'Status',
53
+ size: 100,
54
+ },
55
+ ];
56
+ export function ExportCallbacksExample() {
57
+ const [exportProgress, setExportProgress] = useState(null);
58
+ const [exportStatus, setExportStatus] = useState('');
59
+ const [isExporting, setIsExporting] = useState(false);
60
+ const [exportResult, setExportResult] = useState(null);
61
+ const tableRef = useRef(null);
62
+ const handleExportProgress = (progress) => {
63
+ setExportProgress(progress);
64
+ setExportStatus(`Exporting... ${progress.percentage.toFixed(1)}%`);
65
+ };
66
+ const handleExportComplete = (result) => {
67
+ setExportProgress(null);
68
+ setExportResult(result);
69
+ setIsExporting(false);
70
+ setExportStatus(result.success
71
+ ? `✅ Export completed! ${result.totalRows} rows exported to ${result.filename}`
72
+ : '❌ Export failed');
73
+ };
74
+ const handleExportError = (error) => {
75
+ setExportProgress(null);
76
+ setIsExporting(false);
77
+ setExportStatus(`❌ Export error: ${error.message} (${error.code})`);
78
+ };
79
+ const handleExportCancel = () => {
80
+ setExportProgress(null);
81
+ setIsExporting(false);
82
+ setExportStatus('🚫 Export cancelled by user');
83
+ };
84
+ // Server export simulation
85
+ const handleServerExport = async (filters) => {
86
+ // Simulate server delay and chunked processing
87
+ await new Promise(resolve => setTimeout(resolve, 1000));
88
+ // Return filtered data based on current filters
89
+ let filteredData = [...sampleData];
90
+ // Apply global filter if exists
91
+ if (filters?.globalFilter) {
92
+ const search = filters.globalFilter.toLowerCase();
93
+ filteredData = filteredData.filter(item => Object.values(item).some(value => String(value).toLowerCase().includes(search)));
94
+ }
95
+ // Apply sorting if exists
96
+ if (filters?.sorting?.length > 0) {
97
+ const sort = filters.sorting[0];
98
+ filteredData.sort((a, b) => {
99
+ const aVal = a[sort.id];
100
+ const bVal = b[sort.id];
101
+ if (aVal < bVal)
102
+ return sort.desc ? 1 : -1;
103
+ if (aVal > bVal)
104
+ return sort.desc ? -1 : 1;
105
+ return 0;
106
+ });
107
+ }
108
+ return {
109
+ data: filteredData,
110
+ total: filteredData.length,
111
+ };
112
+ };
113
+ const programmaticExport = async (format) => {
114
+ if (!tableRef.current)
115
+ return;
116
+ try {
117
+ setIsExporting(true);
118
+ setExportStatus(`Starting ${format.toUpperCase()} export...`);
119
+ if (format === 'csv') {
120
+ await tableRef.current.export.exportCSV({
121
+ filename: 'programmatic-export',
122
+ onlyVisibleColumns: true,
123
+ });
124
+ }
125
+ else {
126
+ await tableRef.current.export.exportExcel({
127
+ filename: 'programmatic-export',
128
+ onlyVisibleColumns: true,
129
+ });
130
+ }
131
+ }
132
+ catch (error) {
133
+ console.error('Programmatic export failed:', error);
134
+ }
135
+ };
136
+ return (_jsxs(Box, { sx: { p: 3 }, children: [_jsx(Typography, { variant: "h4", gutterBottom: true, children: "Export with Callbacks Example" }), _jsx(Typography, { variant: "body1", paragraph: true, children: "This example demonstrates:" }), _jsxs("ul", { children: [_jsx("li", { children: "Export progress callbacks" }), _jsx("li", { children: "Export completion/error handling" }), _jsx("li", { children: "Export cancellation" }), _jsx("li", { children: "Programmatic exports via ref API" }), _jsx("li", { children: "Background export processing (doesn't block UI)" }), _jsx("li", { children: "Server-side export with filters" })] }), _jsx(Card, { sx: { mb: 3 }, children: _jsxs(CardContent, { children: [_jsx(Typography, { variant: "h6", gutterBottom: true, children: "Export Status" }), exportProgress ? (_jsxs(Box, { sx: { mb: 2 }, children: [_jsxs(Typography, { variant: "body2", gutterBottom: true, children: ["Progress:", ' ', exportProgress.processedRows, ' ', "/", ' ', exportProgress.totalRows, ' ', "rows"] }), _jsx(LinearProgress, { variant: "determinate", value: exportProgress.percentage, sx: {
137
+ height: 8,
138
+ borderRadius: 4,
139
+ } })] })) : null, exportStatus ? (_jsx(Alert, { severity: exportStatus.includes('❌') ? 'error' :
140
+ exportStatus.includes('🚫') ? 'warning' :
141
+ exportStatus.includes('✅') ? 'success' : 'info', sx: { mb: 2 }, children: exportStatus })) : null, exportResult ? (_jsxs(Typography, { variant: "body2", color: "text.secondary", children: ["Last export:", ' ', exportResult.filename, ' ', "(", exportResult.totalRows, ' ', "rows)"] })) : null] }) }), _jsx(Card, { sx: { mb: 3 }, children: _jsxs(CardContent, { children: [_jsx(Typography, { variant: "h6", gutterBottom: true, children: "Programmatic Export (via Ref API)" }), _jsxs(Box, { sx: {
142
+ display: 'flex',
143
+ gap: 2,
144
+ }, children: [_jsx(Button, { variant: "contained", onClick: () => programmaticExport('csv'), disabled: isExporting, children: "Export CSV (Ref API)" }), _jsx(Button, { variant: "contained", onClick: () => programmaticExport('excel'), disabled: isExporting, children: "Export Excel (Ref API)" }), _jsx(Button, { variant: "outlined", color: "warning", onClick: () => tableRef.current?.export.cancelExport(), disabled: !isExporting, children: "Cancel Export" })] })] }) }), _jsx(Card, { sx: { mb: 3 }, children: _jsxs(CardContent, { children: [_jsx(Typography, { variant: "h6", gutterBottom: true, children: "Client Mode Export (1000 rows in memory)" }), _jsx(DataTable, { ref: tableRef, data: sampleData, columns: columns, dataMode: "client", enableGlobalFilter: true, enableSorting: true, exportFilename: "client-export", onExportProgress: handleExportProgress, onExportComplete: handleExportComplete, onExportError: handleExportError, onExportCancel: handleExportCancel, enablePagination: true, initialState: {
145
+ pagination: {
146
+ pageIndex: 0,
147
+ pageSize: 10,
148
+ },
149
+ } })] }) }), _jsx(Card, { children: _jsxs(CardContent, { children: [_jsx(Typography, { variant: "h6", gutterBottom: true, children: "Server Mode Export (simulated server data)" }), _jsx(DataTable, { data: sampleData.slice(0, 10), totalRow: sampleData.length, columns: columns, dataMode: "server", enableGlobalFilter: true, enableSorting: true, exportFilename: "server-export", onExportProgress: handleExportProgress, onExportComplete: handleExportComplete, onExportError: handleExportError, onExportCancel: handleExportCancel, onServerExport: handleServerExport, enablePagination: true, initialState: {
150
+ pagination: {
151
+ pageIndex: 0,
152
+ pageSize: 10,
153
+ },
154
+ } })] }) }), _jsx(Alert, { severity: "info", sx: { mt: 3 }, children: _jsxs(Typography, { variant: "body2", children: [_jsx("strong", { children: "Note:" }), ' ', "Export functionality works in the background. You can continue using the table, changing filters, or navigating pages during export. The export captures the current state when started and won't be affected by subsequent changes."] }) })] }));
155
+ }
@@ -0,0 +1 @@
1
+ {"version":3,"file":"improved-export-example.d.ts","sourceRoot":"","sources":["../../../src/lib/examples/improved-export-example.tsx"],"names":[],"mappings":"AAuHA,wBAAgB,qBAAqB,4CAgMpC"}
@@ -0,0 +1,153 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { Box, Alert, Typography, Card, CardContent, Button, Chip } from '@mui/material';
3
+ import { useState, useRef } from 'react';
4
+ import { DataTable } from '../components/table/data-table';
5
+ // Sample data with complex values
6
+ const sampleData = Array.from({ length: 100 }, (_, i) => ({
7
+ id: i + 1,
8
+ name: `User ${i + 1}`,
9
+ email: `user${i + 1}@example.com`,
10
+ age: Math.floor(Math.random() * 50) + 20,
11
+ salary: Math.floor(Math.random() * 100000) + 30000,
12
+ joinDate: new Date(2020 + Math.floor(Math.random() * 4), Math.floor(Math.random() * 12), Math.floor(Math.random() * 28)),
13
+ status: [
14
+ 'Active',
15
+ 'Inactive',
16
+ 'Pending',
17
+ ][Math.floor(Math.random() * 3)],
18
+ metadata: {
19
+ department: [
20
+ 'Engineering',
21
+ 'Sales',
22
+ 'Marketing',
23
+ 'HR',
24
+ ][Math.floor(Math.random() * 4)],
25
+ skills: Math.floor(Math.random() * 10) + 1,
26
+ },
27
+ }));
28
+ // Columns using TanStack Table's built-in methods
29
+ const columns = [
30
+ {
31
+ accessorKey: 'id',
32
+ header: 'ID',
33
+ size: 80,
34
+ exportHeader: 'User ID', // Custom export header
35
+ },
36
+ {
37
+ accessorKey: 'name',
38
+ header: 'Name',
39
+ size: 150,
40
+ },
41
+ {
42
+ accessorKey: 'email',
43
+ header: 'Email',
44
+ size: 200,
45
+ },
46
+ {
47
+ accessorKey: 'age',
48
+ header: 'Age',
49
+ size: 80,
50
+ // Use cell for custom display formatting
51
+ cell: ({ getValue }) => `${getValue()} years`,
52
+ },
53
+ {
54
+ accessorKey: 'salary',
55
+ header: 'Salary',
56
+ size: 120,
57
+ accessorFn: (row) => new Intl.NumberFormat('en-US', {
58
+ style: 'currency',
59
+ currency: 'USD',
60
+ }).format(row.salary),
61
+ exportHeader: 'Annual Salary', // Different header for export
62
+ },
63
+ {
64
+ accessorKey: 'joinDate',
65
+ header: 'Join Date',
66
+ size: 120,
67
+ // Use cell for custom display formatting
68
+ cell: ({ getValue }) => {
69
+ return new Date(getValue()).toLocaleDateString('en-US', {
70
+ year: 'numeric',
71
+ month: 'short',
72
+ day: 'numeric',
73
+ });
74
+ },
75
+ },
76
+ {
77
+ accessorKey: 'status',
78
+ header: 'Status',
79
+ size: 100,
80
+ cell: ({ getValue }) => {
81
+ const status = getValue();
82
+ return (_jsx(Chip, { label: status, color: status === 'Active' ? 'success' : status === 'Inactive' ? 'error' : 'warning', size: "small" }));
83
+ },
84
+ // Export will show the raw status value, not the Chip component
85
+ },
86
+ {
87
+ id: 'department',
88
+ header: 'Department',
89
+ size: 120,
90
+ // Use accessorFn for custom data extraction
91
+ accessorFn: (row) => row.metadata?.department || 'N/A',
92
+ exportHeader: 'Employee Department',
93
+ },
94
+ {
95
+ id: 'skillLevel',
96
+ header: 'Skill Level',
97
+ size: 100,
98
+ // Use accessorFn for custom data extraction and cell for display formatting
99
+ cell: ({ getValue }) => {
100
+ const value = getValue();
101
+ if (value >= 8)
102
+ return 'Expert';
103
+ if (value >= 6)
104
+ return 'Advanced';
105
+ if (value >= 4)
106
+ return 'Intermediate';
107
+ return 'Beginner';
108
+ },
109
+ exportHeader: 'Skill Level Rating',
110
+ },
111
+ ];
112
+ export function ImprovedExportExample() {
113
+ const [exportStatus, setExportStatus] = useState('');
114
+ const tableRef = useRef(null);
115
+ const handleExportComplete = (result) => {
116
+ setExportStatus(result.success
117
+ ? `✅ Export completed! ${result.totalRows} rows exported to ${result.filename}`
118
+ : '❌ Export failed');
119
+ };
120
+ const handleExportError = (error) => {
121
+ setExportStatus(`❌ Export error: ${error.message} (${error.code})`);
122
+ };
123
+ const programmaticExport = async (format) => {
124
+ if (!tableRef.current)
125
+ return;
126
+ try {
127
+ setExportStatus(`Starting ${format.toUpperCase()} export...`);
128
+ if (format === 'csv') {
129
+ await tableRef.current.export.exportCSV({
130
+ filename: 'programmatic-export',
131
+ });
132
+ }
133
+ else {
134
+ await tableRef.current.export.exportExcel({
135
+ filename: 'programmatic-export',
136
+ });
137
+ }
138
+ }
139
+ catch (error) {
140
+ console.error('Programmatic export failed:', error);
141
+ }
142
+ };
143
+ return (_jsxs(Box, { sx: { p: 3 }, children: [_jsx(Typography, { variant: "h4", gutterBottom: true, children: "Improved Export Example" }), _jsx(Typography, { variant: "body1", paragraph: true, children: "This example demonstrates the corrected export functionality that:" }), _jsxs("ul", { children: [_jsxs("li", { children: [_jsx("strong", { children: "Uses TanStack Table Logic:" }), ' ', "Uses accessorFn and cell rendering for data processing"] }), _jsxs("li", { children: [_jsx("strong", { children: "Only Visible Columns:" }), ' ', "Exports only visible columns"] }), _jsxs("li", { children: [_jsx("strong", { children: "Auto-Selected Rows:" }), ' ', "If rows are selected, exports only selected rows"] }), _jsxs("li", { children: [_jsx("strong", { children: "Custom Export Headers:" }), ' ', "Uses exportHeader property if defined"] }), _jsxs("li", { children: [_jsx("strong", { children: "Raw Data Export:" }), ' ', "Exports raw data values, not formatted display values"] })] }), _jsx(Alert, { severity: "info", sx: { mb: 3 }, children: _jsxs(Typography, { variant: "body2", children: [_jsx("strong", { children: "Try this:" }), ' ', "Select some rows and then export. The export will automatically include only the selected rows. If no rows are selected, it exports all filtered rows."] }) }), exportStatus ? (_jsx(Alert, { severity: exportStatus.includes('❌') ? 'error' :
144
+ exportStatus.includes('✅') ? 'success' : 'info', sx: { mb: 3 }, children: exportStatus })) : null, _jsx(Card, { sx: { mb: 3 }, children: _jsxs(CardContent, { children: [_jsx(Typography, { variant: "h6", gutterBottom: true, children: "Programmatic Export (via Ref API)" }), _jsxs(Box, { sx: {
145
+ display: 'flex',
146
+ gap: 2,
147
+ }, children: [_jsx(Button, { variant: "contained", onClick: () => programmaticExport('csv'), children: "Export CSV (Ref API)" }), _jsx(Button, { variant: "contained", onClick: () => programmaticExport('excel'), children: "Export Excel (Ref API)" })] })] }) }), _jsx(Card, { children: _jsxs(CardContent, { children: [_jsx(Typography, { variant: "h6", gutterBottom: true, children: "DataTable with Column-Based Export" }), _jsx(DataTable, { ref: tableRef, data: sampleData, totalRow: sampleData.length, columns: columns, dataMode: "client", enableGlobalFilter: true, enableSorting: true, enableRowSelection: true, enableMultiRowSelection: true, enableExport: true, exportFilename: "improved-export", onExportComplete: handleExportComplete, onExportError: handleExportError, enablePagination: true, initialState: {
148
+ pagination: {
149
+ pageIndex: 0,
150
+ pageSize: 10,
151
+ },
152
+ } })] }) }), _jsx(Alert, { severity: "success", sx: { mt: 3 }, children: _jsxs(Typography, { variant: "body2", children: [_jsx("strong", { children: "Export Features:" }), _jsx("br", {}), "\u2022 Salary exports as formatted currency (e.g., \"$65,000.00\")", _jsx("br", {}), "\u2022 Age exports with \"years\" suffix (e.g., \"25 years\")", _jsx("br", {}), "\u2022 Join Date exports as formatted date (e.g., \"Jan 15, 2022\")", _jsx("br", {}), "\u2022 Department extracts from nested metadata object", _jsx("br", {}), "\u2022 Skill Level converts numbers to text levels", _jsx("br", {}), "\u2022 Custom export headers replace display headers", _jsx("br", {}), "\u2022 Status shows raw value (not Chip component)"] }) })] }));
153
+ }
@@ -0,0 +1 @@
1
+ {"version":3,"file":"improved-server-selection-example.d.ts","sourceRoot":"","sources":["../../../src/lib/examples/improved-server-selection-example.tsx"],"names":[],"mappings":"AAqBA,eAAO,MAAM,8BAA8B,+CAgM1C,CAAC"}
@@ -0,0 +1,118 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useState, useRef, useCallback } from 'react';
3
+ import { DataTable } from '../components/table/data-table';
4
+ const MOCK_USERS = Array.from({ length: 500 }, (_, i) => ({
5
+ id: String(i + 1),
6
+ name: `User ${i + 1}`,
7
+ email: `user${i + 1}@example.com`,
8
+ role: i % 3 === 0 ? 'Admin' : i % 3 === 1 ? 'Editor' : 'Viewer',
9
+ status: i % 4 === 0 ? 'inactive' : 'active',
10
+ }));
11
+ export const ImprovedServerSelectionExample = () => {
12
+ const [data, setData] = useState([]);
13
+ const [total, setTotal] = useState(500);
14
+ const [loading, setLoading] = useState(false);
15
+ const [selectionInfo, setSelectionInfo] = useState(null);
16
+ const apiRef = useRef(null);
17
+ const columns = [
18
+ {
19
+ id: 'name',
20
+ header: 'Name',
21
+ accessorKey: 'name',
22
+ enableGlobalFilter: true,
23
+ },
24
+ {
25
+ id: 'email',
26
+ header: 'Email',
27
+ accessorKey: 'email',
28
+ enableGlobalFilter: true,
29
+ },
30
+ {
31
+ id: 'role',
32
+ header: 'Role',
33
+ accessorKey: 'role',
34
+ enableGlobalFilter: true,
35
+ },
36
+ {
37
+ id: 'status',
38
+ header: 'Status',
39
+ accessorKey: 'status',
40
+ enableGlobalFilter: true,
41
+ },
42
+ ];
43
+ const fetchData = useCallback(async (filters) => {
44
+ console.log('Fetching data with filters:', filters);
45
+ setLoading(true);
46
+ // Simulate API call delay
47
+ await new Promise(resolve => setTimeout(resolve, 500));
48
+ const { pagination } = filters;
49
+ const pageIndex = pagination?.pageIndex || 0;
50
+ const pageSize = pagination?.pageSize || 50;
51
+ const startIndex = pageIndex * pageSize;
52
+ const endIndex = startIndex + pageSize;
53
+ const pageData = MOCK_USERS.slice(startIndex, endIndex);
54
+ setData(pageData);
55
+ setTotal(MOCK_USERS.length);
56
+ setLoading(false);
57
+ return {
58
+ data: pageData,
59
+ total: MOCK_USERS.length,
60
+ };
61
+ }, []);
62
+ // Server export function that handles selection
63
+ const fetchExportData = useCallback(async (filters, selection) => {
64
+ console.log('Exporting data with filters:', filters);
65
+ console.log('Export selection data:', selection);
66
+ // Simulate API call delay
67
+ await new Promise(resolve => setTimeout(resolve, 1000));
68
+ let dataToExport = [...MOCK_USERS];
69
+ // Apply selection filtering
70
+ if (selection?.hasSelection) {
71
+ if (selection.selectAllMatching) {
72
+ // Export all except excluded
73
+ dataToExport = MOCK_USERS.filter(user => !selection.excludedIds.includes(user.id));
74
+ }
75
+ else {
76
+ // Export only selected
77
+ dataToExport = MOCK_USERS.filter(user => selection.selectedIds.includes(user.id));
78
+ }
79
+ }
80
+ return {
81
+ data: dataToExport,
82
+ total: dataToExport.length,
83
+ };
84
+ }, []);
85
+ const handleServerSelectionChange = useCallback((selection) => {
86
+ console.log('Server selection changed:', selection);
87
+ // Convert new selection state to old format for display compatibility
88
+ const legacyFormat = {
89
+ selectAllMatching: selection.type === 'exclude' && selection.ids.length === 0,
90
+ excludedIds: selection.type === 'exclude' ? selection.ids : [],
91
+ selectedIds: selection.type === 'include' ? selection.ids : [],
92
+ totalSelected: selection.type === 'exclude' ? (total - selection.ids.length) : selection.ids.length,
93
+ };
94
+ setSelectionInfo(legacyFormat);
95
+ }, [total]);
96
+ const handleRowSelectionChange = useCallback((selectedRows) => {
97
+ console.log('Row selection changed:', selectedRows.length, 'rows selected');
98
+ console.log('Selected row IDs:', selectedRows.map(row => row.id));
99
+ }, []);
100
+ const handleExportProgress = (progress) => {
101
+ };
102
+ const handleExportComplete = (result) => {
103
+ console.log('Export completed:', result);
104
+ };
105
+ const handleExportError = (error) => {
106
+ console.error('Export error:', error);
107
+ };
108
+ return (_jsxs("div", { className: "p-6", children: [_jsx("h2", { className: "text-2xl font-bold mb-4", children: "Improved Server Selection Example" }), selectionInfo && (_jsxs("div", { className: "mb-4 p-4 bg-blue-50 rounded-lg", children: [_jsx("h3", { className: "font-semibold mb-2", children: "Selection Info:" }), _jsxs("div", { className: "grid grid-cols-2 gap-2 text-sm", children: [_jsxs("div", { children: ["Select All Matching: ", selectionInfo.selectAllMatching ? 'Yes' : 'No'] }), _jsxs("div", { children: ["Total Selected: ", selectionInfo.totalSelected] }), _jsxs("div", { children: ["Selected IDs: ", selectionInfo.selectedIds.length] }), _jsxs("div", { children: ["Excluded IDs: ", selectionInfo.excludedIds.length] })] })] })), _jsxs("div", { className: "mb-4 space-x-2", children: [_jsx("button", { onClick: () => {
109
+ const payload = apiRef.current?.selection.getSelectionState();
110
+ console.log('Selection State:', payload);
111
+ }, className: "px-4 py-2 bg-blue-500 text-white rounded hover:bg-blue-600", children: "Get Selection Payload" }), _jsx("button", { onClick: () => {
112
+ const selectionState = apiRef.current?.selection.getSelectionState();
113
+ console.log('Selection State:', selectionState);
114
+ }, className: "px-4 py-2 bg-green-500 text-white rounded hover:bg-green-600", children: "Get Selection State" }), _jsx("button", { onClick: () => {
115
+ const selectedCount = apiRef.current?.selection.getSelectedCount();
116
+ console.log('Selected Count:', selectedCount);
117
+ }, className: "px-4 py-2 bg-purple-500 text-white rounded hover:bg-purple-600", children: "Get Selected Count" })] }), _jsx(DataTable, { ref: apiRef, columns: columns, data: data, totalRow: total, loading: loading, dataMode: "server", selectMode: "all", enableGlobalFilter: true, enableRowSelection: true, enableMultiRowSelection: true, onFetchData: fetchData, onRowSelectionChange: handleRowSelectionChange, onSelectionChange: handleServerSelectionChange, onServerExport: fetchExportData, exportFilename: "selected-users", onExportProgress: handleExportProgress, onExportComplete: handleExportComplete, onExportError: handleExportError, enableExport: true, enableBulkActions: true })] }));
118
+ };
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/lib/examples/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,gCAAgC,CAAC;AAC3E,OAAO,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AAChE,OAAO,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAC;AACtE,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAC5D,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC"}
@@ -0,0 +1,5 @@
1
+ export { CustomColumnFilterExample } from './custom-column-filter-example';
2
+ export { SelectionTestExample } from './selection-test-example';
3
+ export { AdvancedFeaturesExample } from './advanced-features-example';
4
+ export { SimpleLocalExample } from './simple-local-example';
5
+ export { BulkActionsTest } from './bulk-actions-test';
@@ -0,0 +1 @@
1
+ {"version":3,"file":"selection-test-example.d.ts","sourceRoot":"","sources":["../../../src/lib/examples/selection-test-example.tsx"],"names":[],"mappings":"AAmFA,wBAAgB,oBAAoB,4CA+LnC"}
@@ -0,0 +1,111 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useState, useRef, useCallback } from 'react';
3
+ import { Box, Typography, Button, FormControl, InputLabel, Select, MenuItem, Chip, Paper, Divider, } from '@mui/material';
4
+ import { DataTable } from '../components';
5
+ // Generate sample data (25+ users for pagination testing)
6
+ const generateSampleData = () => {
7
+ const departments = ['Engineering', 'Marketing', 'Sales', 'HR', 'Finance'];
8
+ const firstNames = ['John', 'Jane', 'Bob', 'Alice', 'Charlie', 'Diana', 'Eva', 'Frank', 'Grace', 'Henry'];
9
+ const lastNames = ['Smith', 'Johnson', 'Williams', 'Brown', 'Jones', 'Garcia', 'Miller', 'Davis', 'Rodriguez', 'Martinez'];
10
+ return Array.from({ length: 25 }, (_, index) => ({
11
+ id: index + 1,
12
+ name: `${firstNames[index % firstNames.length]} ${lastNames[index % lastNames.length]}`,
13
+ email: `user${index + 1}@example.com`,
14
+ department: departments[index % departments.length],
15
+ salary: 50000 + (index * 5000),
16
+ isActive: Math.random() > 0.3, // 70% active
17
+ }));
18
+ };
19
+ const sampleData = generateSampleData();
20
+ // Column definitions
21
+ const columns = [
22
+ {
23
+ accessorKey: 'name',
24
+ header: 'Name',
25
+ size: 150,
26
+ },
27
+ {
28
+ accessorKey: 'email',
29
+ header: 'Email',
30
+ size: 200,
31
+ },
32
+ {
33
+ accessorKey: 'department',
34
+ header: 'Department',
35
+ size: 120,
36
+ },
37
+ {
38
+ accessorKey: 'salary',
39
+ header: 'Salary',
40
+ size: 100,
41
+ cell: ({ getValue }) => `$${getValue().toLocaleString()}`,
42
+ },
43
+ {
44
+ accessorKey: 'isActive',
45
+ header: 'Status',
46
+ size: 100,
47
+ cell: ({ getValue }) => (_jsx(Chip, { label: getValue() ? 'Active' : 'Inactive', color: getValue() ? 'success' : 'default', size: "small" })),
48
+ },
49
+ ];
50
+ export function SelectionTestExample() {
51
+ const [selectMode, setSelectMode] = useState('page');
52
+ const [selectionState, setSelectionState] = useState({
53
+ ids: [],
54
+ type: 'include',
55
+ });
56
+ const tableRef = useRef(null);
57
+ // Handle selection state changes
58
+ const handleSelectionChange = useCallback((newSelectionState) => {
59
+ setSelectionState(newSelectionState);
60
+ }, []);
61
+ // Test selection operations
62
+ const handleSelectAll = useCallback(() => {
63
+ tableRef.current?.selection.selectAll();
64
+ }, []);
65
+ const handleDeselectAll = useCallback(() => {
66
+ tableRef.current?.selection.deselectAll();
67
+ }, []);
68
+ const handleSelectFirst5 = useCallback(() => {
69
+ // Select first 5 users manually
70
+ const firstFiveIds = sampleData.slice(0, 5).map(user => user.id.toString());
71
+ firstFiveIds.forEach(id => {
72
+ tableRef.current?.selection.selectRow(id);
73
+ });
74
+ }, []);
75
+ const handleToggleRow = useCallback(() => {
76
+ // Toggle selection of user with id 3
77
+ tableRef.current?.selection.toggleRowSelection('3');
78
+ }, []);
79
+ // Row selectability function - disable users with salary > 100000
80
+ // ⚠️ IMPORTANT: This must be memoized to prevent infinite re-renders
81
+ const isRowSelectable = useCallback(({ row }) => {
82
+ return row.salary <= 100000;
83
+ }, []);
84
+ // Get selection info for display
85
+ const selectedCount = selectionState.ids.length;
86
+ const selectedType = selectionState.type;
87
+ return (_jsxs(Box, { sx: { p: 3 }, children: [_jsx(Typography, { variant: "h4", gutterBottom: true, children: "Selection Test Example" }), _jsx(Typography, { variant: "body1", color: "text.secondary", sx: { mb: 3 }, children: "Test the custom selection feature with different modes and operations. Users with salary > $100,000 are disabled for selection." }), _jsx(Paper, { sx: { p: 2, mb: 3 }, children: _jsxs(Box, { sx: { display: 'flex', gap: 2, flexWrap: 'wrap', alignItems: 'center' }, children: [_jsxs(FormControl, { size: "small", sx: { minWidth: 120 }, children: [_jsx(InputLabel, { children: "Selection Mode" }), _jsxs(Select, { value: selectMode, label: "Selection Mode", onChange: (e) => setSelectMode(e.target.value), children: [_jsx(MenuItem, { value: "page", children: "Page Mode" }), _jsx(MenuItem, { value: "all", children: "All Mode" })] })] }), _jsx(Button, { variant: "outlined", onClick: handleSelectAll, children: "Select All" }), _jsx(Button, { variant: "outlined", onClick: handleDeselectAll, children: "Deselect All" }), _jsx(Button, { variant: "outlined", onClick: handleSelectFirst5, children: "Select First 5" }), _jsx(Button, { variant: "outlined", onClick: handleToggleRow, children: "Toggle User #3" })] }) }), _jsxs(Paper, { sx: { p: 2, mb: 3 }, children: [_jsx(Typography, { variant: "h6", gutterBottom: true, children: "Current Selection State" }), _jsxs(Box, { sx: { display: 'grid', gridTemplateColumns: 'repeat(auto-fit, minmax(200px, 1fr))', gap: 2 }, children: [_jsxs(Typography, { variant: "body2", children: [_jsx("strong", { children: "Mode:" }), " ", selectMode] }), _jsxs(Typography, { variant: "body2", children: [_jsx("strong", { children: "Type:" }), " ", selectedType] }), _jsxs(Typography, { variant: "body2", children: [_jsx("strong", { children: "Count:" }), " ", selectedCount] }), _jsxs(Typography, { variant: "body2", sx: { gridColumn: '1 / -1' }, children: [_jsx("strong", { children: "IDs:" }), " ", selectionState.ids.join(', ') || 'None'] })] })] }), _jsx(Divider, { sx: { my: 2 } }), _jsx(DataTable, { ref: tableRef, data: sampleData, totalRow: sampleData.length, columns: columns,
88
+ // Enable selection
89
+ enableRowSelection: true, enableMultiRowSelection: true, selectMode: selectMode, isRowSelectable: isRowSelectable, onSelectionChange: handleSelectionChange,
90
+ // Enable pagination to test page vs all modes
91
+ enablePagination: true, initialState: {
92
+ pagination: {
93
+ pageIndex: 0,
94
+ pageSize: 10, // Show 10 rows per page
95
+ },
96
+ },
97
+ // Enable bulk actions to test selection
98
+ enableBulkActions: true, bulkActions: (selectionState) => (_jsxs(Box, { sx: { display: 'flex', gap: 1 }, children: [_jsx(Button, { variant: "outlined", size: "small", onClick: () => {
99
+ const count = selectionState.type === 'include'
100
+ ? selectionState.ids.length
101
+ : sampleData.length - selectionState.ids.length;
102
+ alert(`Exporting ${count} selected users (${selectionState.type} mode)`);
103
+ }, children: "\uD83D\uDCE4 Export Selected" }), _jsx(Button, { variant: "outlined", size: "small", color: "error", onClick: () => {
104
+ const count = selectionState.type === 'include'
105
+ ? selectionState.ids.length
106
+ : sampleData.length - selectionState.ids.length;
107
+ alert(`Would delete ${count} selected users (${selectionState.type} mode)`);
108
+ }, children: "\uD83D\uDDD1\uFE0F Delete Selected" })] })),
109
+ // Table settings
110
+ enableSorting: true, enableGlobalFilter: true, fitToScreen: true }), _jsx(Box, { sx: { mt: 2 }, children: _jsxs(Typography, { variant: "body2", color: "text.secondary", children: ["\uD83D\uDCA1 ", _jsx("strong", { children: "Test Instructions:" }), _jsx("br", {}), "1. Try selecting rows in \"Page\" mode, then switch pages - selections should be page-specific", _jsx("br", {}), "2. Try \"All\" mode and select rows - this works across all pages", _jsx("br", {}), "3. Note that users with salary > $100k are disabled (grayed out checkboxes)", _jsx("br", {}), "4. Use the control buttons to test programmatic selection", _jsx("br", {}), "5. Watch the \"Current Selection State\" panel to see how the selection data changes"] }) })] }));
111
+ }
@@ -0,0 +1 @@
1
+ {"version":3,"file":"simple-local-example.d.ts","sourceRoot":"","sources":["../../../src/lib/examples/simple-local-example.tsx"],"names":[],"mappings":"AAmFA,wBAAgB,kBAAkB,4CAqGjC"}