@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,321 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { Button, Stack, Typography, Box, TextField, Dialog, DialogTitle, DialogContent, DialogActions, MenuItem, Select, FormControl, InputLabel, } from '@mui/material';
3
+ import { useRef, useCallback, useState } from 'react';
4
+ import { DataTable } from '../components/table/data-table';
5
+ // Simulate API data
6
+ const initialData = [
7
+ {
8
+ id: 1,
9
+ name: 'John Doe',
10
+ email: 'john@example.com',
11
+ status: 'active',
12
+ role: 'admin',
13
+ created: '2024-01-01',
14
+ lastLogin: '2024-01-15',
15
+ },
16
+ {
17
+ id: 2,
18
+ name: 'Jane Smith',
19
+ email: 'jane@example.com',
20
+ status: 'inactive',
21
+ role: 'user',
22
+ created: '2024-01-02',
23
+ lastLogin: '2024-01-10',
24
+ },
25
+ {
26
+ id: 3,
27
+ name: 'Bob Johnson',
28
+ email: 'bob@example.com',
29
+ status: 'active',
30
+ role: 'manager',
31
+ created: '2024-01-03',
32
+ lastLogin: '2024-01-14',
33
+ },
34
+ {
35
+ id: 4,
36
+ name: 'Alice Brown',
37
+ email: 'alice@example.com',
38
+ status: 'pending',
39
+ role: 'user',
40
+ created: '2024-01-04',
41
+ },
42
+ {
43
+ id: 5,
44
+ name: 'Charlie Wilson',
45
+ email: 'charlie@example.com',
46
+ status: 'active',
47
+ role: 'user',
48
+ created: '2024-01-05',
49
+ lastLogin: '2024-01-12',
50
+ },
51
+ ];
52
+ const columns = [
53
+ {
54
+ id: 'name',
55
+ accessorKey: 'name',
56
+ header: 'Name',
57
+ size: 150,
58
+ },
59
+ {
60
+ id: 'email',
61
+ accessorKey: 'email',
62
+ header: 'Email',
63
+ size: 200,
64
+ },
65
+ {
66
+ id: 'status',
67
+ accessorKey: 'status',
68
+ header: 'Status',
69
+ size: 100,
70
+ cell: ({ getValue }) => {
71
+ const status = getValue();
72
+ const colors = {
73
+ active: '#4caf50',
74
+ inactive: '#f44336',
75
+ pending: '#ff9800',
76
+ };
77
+ return (_jsx("span", { style: {
78
+ color: colors[status],
79
+ fontWeight: 'bold',
80
+ textTransform: 'capitalize',
81
+ }, children: status }));
82
+ },
83
+ },
84
+ {
85
+ id: 'role',
86
+ accessorKey: 'role',
87
+ header: 'Role',
88
+ size: 100,
89
+ },
90
+ {
91
+ id: 'created',
92
+ accessorKey: 'created',
93
+ header: 'Created',
94
+ size: 120,
95
+ },
96
+ {
97
+ id: 'lastLogin',
98
+ accessorKey: 'lastLogin',
99
+ header: 'Last Login',
100
+ size: 120,
101
+ cell: ({ getValue }) => getValue() || 'Never',
102
+ },
103
+ ];
104
+ export function CrudApiExample() {
105
+ const dataTableRef = useRef(null);
106
+ const [data, setData] = useState(initialData);
107
+ const [dialogOpen, setDialogOpen] = useState(false);
108
+ const [editUser, setEditUser] = useState({});
109
+ // Handle data changes from the table
110
+ const handleDataChange = useCallback((newData) => {
111
+ setData(newData);
112
+ console.log('Data changed:', newData);
113
+ // Here you would typically sync with your API
114
+ // await updateUsersAPI(newData);
115
+ }, []);
116
+ // CRUD Operations Examples
117
+ // Get Data Operations
118
+ const handleGetAllData = useCallback(() => {
119
+ const allData = dataTableRef.current?.data.getAllData();
120
+ console.log('All data:', allData);
121
+ alert(`Total users: ${allData?.length}. Check console for details.`);
122
+ }, []);
123
+ const handleGetUserById = useCallback(() => {
124
+ const userId = prompt('Enter user ID:');
125
+ if (userId) {
126
+ const user = dataTableRef.current?.data.getRowData(userId);
127
+ console.log('User found:', user);
128
+ alert(user ? `Found: ${user.name} (${user.email})` : 'User not found');
129
+ }
130
+ }, []);
131
+ const handleGetUserByIndex = useCallback(() => {
132
+ const index = prompt('Enter row index (0-based):');
133
+ if (index !== null) {
134
+ const user = dataTableRef.current?.data.getRowByIndex(parseInt(index));
135
+ console.log('User at index:', user);
136
+ alert(user ? `User at index ${index}: ${user.name}` : 'No user at that index');
137
+ }
138
+ }, []);
139
+ const handleFindActiveUsers = useCallback(() => {
140
+ const activeUsers = dataTableRef.current?.data.findRows(user => user.status === 'active');
141
+ console.log('Active users:', activeUsers);
142
+ alert(`Found ${activeUsers?.length} active users. Check console for details.`);
143
+ }, []);
144
+ // Update Operations
145
+ const handleUpdateUserStatus = useCallback(() => {
146
+ const userId = prompt('Enter user ID to update status:');
147
+ if (userId) {
148
+ const user = dataTableRef.current?.data.getRowData(userId);
149
+ if (user) {
150
+ const newStatus = prompt('Enter new status (active/inactive/pending):');
151
+ if (newStatus && [
152
+ 'active',
153
+ 'inactive',
154
+ 'pending',
155
+ ].includes(newStatus)) {
156
+ dataTableRef.current?.data.updateField(userId, 'status', newStatus);
157
+ // If activating user, update last login
158
+ if (newStatus === 'active') {
159
+ dataTableRef.current?.data.updateField(userId, 'lastLogin', new Date().toISOString().split('T')[0]);
160
+ }
161
+ }
162
+ }
163
+ else {
164
+ alert('User not found');
165
+ }
166
+ }
167
+ }, []);
168
+ const handleUpdateUserByIndex = useCallback(() => {
169
+ const index = prompt('Enter row index to update:');
170
+ if (index !== null) {
171
+ const user = dataTableRef.current?.data.getRowByIndex(parseInt(index));
172
+ if (user) {
173
+ setEditUser(user);
174
+ setDialogOpen(true);
175
+ }
176
+ else {
177
+ alert('No user at that index');
178
+ }
179
+ }
180
+ }, []);
181
+ const handleBulkUpdateStatus = useCallback(() => {
182
+ const selectionState = dataTableRef.current?.selection.getSelectionState();
183
+ if (selectionState?.ids.length) {
184
+ const newStatus = prompt('Enter new status for selected users (active/inactive/pending):');
185
+ if (newStatus && [
186
+ 'active',
187
+ 'inactive',
188
+ 'pending',
189
+ ].includes(newStatus)) {
190
+ // Get the selected user IDs and update them
191
+ const updates = selectionState.ids.map(id => ({
192
+ rowId: id,
193
+ data: { status: newStatus },
194
+ }));
195
+ dataTableRef.current?.data.updateMultipleRows(updates);
196
+ }
197
+ }
198
+ else {
199
+ alert('Please select users first');
200
+ }
201
+ }, []);
202
+ // Insert Operations
203
+ const handleAddNewUser = useCallback(() => {
204
+ const name = prompt('Enter user name:');
205
+ const email = prompt('Enter user email:');
206
+ if (name && email) {
207
+ const newUser = {
208
+ id: Math.max(...data.map(u => u.id)) + 1,
209
+ name,
210
+ email,
211
+ status: 'pending',
212
+ role: 'user',
213
+ created: new Date().toISOString().split('T')[0],
214
+ };
215
+ // Insert at the beginning
216
+ dataTableRef.current?.data.insertRow(newUser, 0);
217
+ }
218
+ }, [data]);
219
+ const handleInsertMultipleUsers = useCallback(() => {
220
+ const count = prompt('How many test users to add?');
221
+ if (count) {
222
+ const numUsers = parseInt(count);
223
+ const newUsers = [];
224
+ const maxId = Math.max(...data.map(u => u.id));
225
+ for (let i = 1; i <= numUsers; i++) {
226
+ newUsers.push({
227
+ id: maxId + i,
228
+ name: `Test User ${i}`,
229
+ email: `test${i}@example.com`,
230
+ status: 'pending',
231
+ role: 'user',
232
+ created: new Date().toISOString().split('T')[0],
233
+ });
234
+ }
235
+ dataTableRef.current?.data.insertMultipleRows(newUsers);
236
+ }
237
+ }, [data]);
238
+ // Delete Operations
239
+ const handleDeleteUser = useCallback(() => {
240
+ const userId = prompt('Enter user ID to delete:');
241
+ if (userId) {
242
+ const user = dataTableRef.current?.data.getRowData(userId);
243
+ if (user) {
244
+ const confirmed = window.confirm(`Delete user "${user.name}"?`);
245
+ if (confirmed) {
246
+ dataTableRef.current?.data.deleteRow(userId);
247
+ }
248
+ }
249
+ else {
250
+ alert('User not found');
251
+ }
252
+ }
253
+ }, []);
254
+ const handleDeleteSelected = useCallback(() => {
255
+ const selectionState = dataTableRef.current?.selection.getSelectionState();
256
+ if (selectionState?.ids.length) {
257
+ const confirmed = window.confirm(`Delete ${selectionState.ids.length} selected users?`);
258
+ if (confirmed) {
259
+ dataTableRef.current?.data.deleteSelectedRows();
260
+ }
261
+ }
262
+ else {
263
+ alert('Please select users first');
264
+ }
265
+ }, []);
266
+ const handleDeleteInactiveUsers = useCallback(() => {
267
+ const inactiveUsers = data.filter(user => user.status === 'inactive');
268
+ if (inactiveUsers.length > 0) {
269
+ const confirmed = window.confirm(`Delete ${inactiveUsers.length} inactive users?`);
270
+ if (confirmed) {
271
+ const inactiveIds = inactiveUsers.map(user => String(user.id));
272
+ dataTableRef.current?.data.deleteMultipleRows(inactiveIds);
273
+ }
274
+ }
275
+ else {
276
+ alert('No inactive users to delete');
277
+ }
278
+ }, [data]);
279
+ // Dialog handlers
280
+ const handleDialogSave = useCallback(() => {
281
+ if (editUser.id !== undefined) {
282
+ const index = data.findIndex(user => user.id === editUser.id);
283
+ if (index !== -1) {
284
+ dataTableRef.current?.data.updateRowByIndex(index, editUser);
285
+ }
286
+ }
287
+ setDialogOpen(false);
288
+ setEditUser({});
289
+ }, [editUser, data]);
290
+ // Simulate API operations
291
+ const handleSimulateApiRefresh = useCallback(async () => {
292
+ // Simulate API call
293
+ console.log('Simulating API refresh...');
294
+ // Add some random data changes
295
+ const updatedData = data.map(user => ({
296
+ ...user,
297
+ lastLogin: user.status === 'active' ? new Date().toISOString().split('T')[0] : user.lastLogin,
298
+ }));
299
+ // Update data through ref API
300
+ dataTableRef.current?.data.replaceAllData(updatedData);
301
+ alert('Data refreshed from "API"');
302
+ }, [data]);
303
+ return (_jsxs(Box, { sx: { p: 3 }, children: [_jsx(Typography, { variant: "h4", gutterBottom: true, children: "DataTable CRUD API Example" }), _jsx(Typography, { variant: "body1", sx: { mb: 3 }, children: "This example demonstrates comprehensive CRUD operations using the DataTable ref API. Perfect for real-world scenarios with API integration." }), _jsxs(Stack, { spacing: 2, sx: { mb: 3 }, children: [_jsx(Typography, { variant: "h6", children: "Data Retrieval" }), _jsxs(Stack, { direction: "row", spacing: 1, flexWrap: "wrap", children: [_jsx(Button, { variant: "outlined", onClick: handleGetAllData, children: "Get All Data" }), _jsx(Button, { variant: "outlined", onClick: handleGetUserById, children: "Get User by ID" }), _jsx(Button, { variant: "outlined", onClick: handleGetUserByIndex, children: "Get User by Index" }), _jsx(Button, { variant: "outlined", onClick: handleFindActiveUsers, children: "Find Active Users" })] }), _jsx(Typography, { variant: "h6", children: "Data Updates" }), _jsxs(Stack, { direction: "row", spacing: 1, flexWrap: "wrap", children: [_jsx(Button, { variant: "outlined", onClick: handleUpdateUserStatus, children: "Update User Status" }), _jsx(Button, { variant: "outlined", onClick: handleUpdateUserByIndex, children: "Edit User by Index" }), _jsx(Button, { variant: "outlined", onClick: handleBulkUpdateStatus, children: "Bulk Update Selected" })] }), _jsx(Typography, { variant: "h6", children: "Data Insertion" }), _jsxs(Stack, { direction: "row", spacing: 1, flexWrap: "wrap", children: [_jsx(Button, { variant: "outlined", onClick: handleAddNewUser, children: "Add New User" }), _jsx(Button, { variant: "outlined", onClick: handleInsertMultipleUsers, children: "Insert Multiple Users" })] }), _jsx(Typography, { variant: "h6", children: "Data Deletion" }), _jsxs(Stack, { direction: "row", spacing: 1, flexWrap: "wrap", children: [_jsx(Button, { variant: "outlined", color: "error", onClick: handleDeleteUser, children: "Delete User by ID" }), _jsx(Button, { variant: "outlined", color: "error", onClick: handleDeleteSelected, children: "Delete Selected" }), _jsx(Button, { variant: "outlined", color: "error", onClick: handleDeleteInactiveUsers, children: "Delete Inactive Users" })] }), _jsx(Typography, { variant: "h6", children: "API Simulation" }), _jsx(Stack, { direction: "row", spacing: 1, flexWrap: "wrap", children: _jsx(Button, { variant: "contained", onClick: handleSimulateApiRefresh, children: "Simulate API Refresh" }) })] }), _jsx(Box, { sx: {
304
+ mb: 2,
305
+ p: 2,
306
+ bgcolor: 'grey.100',
307
+ borderRadius: 1,
308
+ }, children: _jsxs(Typography, { variant: "body2", children: ["Total Users:", ' ', data.length, ' ', "| Active:", ' ', data.filter(u => u.status === 'active').length, ' ', "| Inactive:", ' ', data.filter(u => u.status === 'inactive').length, ' ', "| Pending:", ' ', data.filter(u => u.status === 'pending').length] }) }), _jsx(DataTable, { ref: dataTableRef, columns: columns, data: data, onDataChange: handleDataChange, enableRowSelection: true, enableColumnResizing: true, draggable: true, enableColumnPinning: true, enableSorting: true, enableGlobalFilter: true, enableColumnFilters: true, enablePagination: true }), _jsxs(Dialog, { open: dialogOpen, onClose: () => setDialogOpen(false), maxWidth: "sm", fullWidth: true, children: [_jsx(DialogTitle, { children: "Edit User" }), _jsx(DialogContent, { children: _jsxs(Stack, { spacing: 2, sx: { mt: 1 }, children: [_jsx(TextField, { label: "Name", value: editUser.name || '', onChange: (e) => setEditUser(prev => ({
309
+ ...prev,
310
+ name: e.target.value,
311
+ })), fullWidth: true }), _jsx(TextField, { label: "Email", value: editUser.email || '', onChange: (e) => setEditUser(prev => ({
312
+ ...prev,
313
+ email: e.target.value,
314
+ })), fullWidth: true }), _jsxs(FormControl, { fullWidth: true, children: [_jsx(InputLabel, { children: "Status" }), _jsxs(Select, { value: editUser.status || '', onChange: (e) => setEditUser(prev => ({
315
+ ...prev,
316
+ status: e.target.value,
317
+ })), children: [_jsx(MenuItem, { value: "active", children: "Active" }), _jsx(MenuItem, { value: "inactive", children: "Inactive" }), _jsx(MenuItem, { value: "pending", children: "Pending" })] })] }), _jsxs(FormControl, { fullWidth: true, children: [_jsx(InputLabel, { children: "Role" }), _jsxs(Select, { value: editUser.role || '', onChange: (e) => setEditUser(prev => ({
318
+ ...prev,
319
+ role: e.target.value,
320
+ })), children: [_jsx(MenuItem, { value: "admin", children: "Admin" }), _jsx(MenuItem, { value: "manager", children: "Manager" }), _jsx(MenuItem, { value: "user", children: "User" })] })] })] }) }), _jsxs(DialogActions, { children: [_jsx(Button, { onClick: () => setDialogOpen(false), children: "Cancel" }), _jsx(Button, { onClick: handleDialogSave, variant: "contained", children: "Save" })] })] })] }));
321
+ }
@@ -0,0 +1 @@
1
+ {"version":3,"file":"custom-column-filter-example.d.ts","sourceRoot":"","sources":["../../../src/lib/examples/custom-column-filter-example.tsx"],"names":[],"mappings":"AAmEA,wBAAgB,yBAAyB,4CA0BxC"}
@@ -0,0 +1,60 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ /**
3
+ * Example: Custom Column Filter Feature Usage
4
+ */
5
+ import { useState } from 'react';
6
+ import { Box, Typography } from '@mui/material';
7
+ import { DataTable } from '../components/table/data-table';
8
+ const sampleData = [
9
+ { id: 1, name: 'John Doe', age: 30, department: 'Engineering', salary: 75000, isActive: true },
10
+ { id: 2, name: 'Jane Smith', age: 25, department: 'Marketing', salary: 60000, isActive: true },
11
+ { id: 3, name: 'Bob Johnson', age: 35, department: 'Engineering', salary: 85000, isActive: false },
12
+ { id: 4, name: 'Alice Brown', age: 28, department: 'HR', salary: 55000, isActive: true },
13
+ { id: 5, name: 'Charlie Wilson', age: 42, department: 'Sales', salary: 70000, isActive: true },
14
+ ];
15
+ const columns = [
16
+ {
17
+ accessorKey: 'name',
18
+ header: 'Name',
19
+ type: 'text',
20
+ },
21
+ {
22
+ accessorKey: 'age',
23
+ header: 'Age',
24
+ type: 'number',
25
+ },
26
+ {
27
+ accessorKey: 'department',
28
+ header: 'Department',
29
+ type: 'select',
30
+ options: [
31
+ { label: 'Engineering', value: 'Engineering' },
32
+ { label: 'Marketing', value: 'Marketing' },
33
+ { label: 'HR', value: 'HR' },
34
+ { label: 'Sales', value: 'Sales' },
35
+ ],
36
+ },
37
+ {
38
+ accessorKey: 'salary',
39
+ header: 'Salary',
40
+ type: 'number',
41
+ cell: ({ getValue }) => {
42
+ const value = getValue();
43
+ return new Intl.NumberFormat('en-US', {
44
+ style: 'currency',
45
+ currency: 'USD',
46
+ }).format(value);
47
+ },
48
+ },
49
+ {
50
+ accessorKey: 'isActive',
51
+ header: 'Active',
52
+ type: 'boolean',
53
+ },
54
+ ];
55
+ export function CustomColumnFilterExample() {
56
+ const [data] = useState(sampleData);
57
+ return (_jsxs(Box, { sx: { p: 3 }, children: [_jsx(Typography, { variant: "h4", gutterBottom: true, children: "Custom Column Filter Feature Example" }), _jsx(Typography, { variant: "body1", sx: { mb: 3 }, children: "Click the filter icon in the toolbar to test the custom column filter feature." }), _jsx(DataTable, { data: data, columns: columns, enableColumnFilter: true, enableGlobalFilter: true, enablePagination: true, enableSorting: true, onColumnFiltersChange: (filterState) => {
58
+ console.log('Custom Column Filter State Changed:', filterState);
59
+ } })] }));
60
+ }
@@ -0,0 +1 @@
1
+ {"version":3,"file":"custom-selection-example.d.ts","sourceRoot":"","sources":["../../../src/lib/examples/custom-selection-example.tsx"],"names":[],"mappings":"AAgCA,wBAAgB,sBAAsB,4CA8SrC"}
@@ -0,0 +1,184 @@
1
+ import { jsxs as _jsxs, jsx as _jsx } from "react/jsx-runtime";
2
+ /**
3
+ * Example demonstrating the Custom Selection Feature with isRowSelectable
4
+ *
5
+ * This shows how to use the simple isRowSelectable prop to control which rows can be selected,
6
+ * similar to MUI DataGrid's approach.
7
+ */
8
+ import { useState, useCallback, useMemo, createElement } from 'react';
9
+ import { DataTable } from '../components/table/data-table';
10
+ import { CustomSelectionManager } from '../features';
11
+ import { Checkbox } from '@mui/material';
12
+ const mockUsers = [
13
+ { id: 1, name: 'John Doe', email: 'john@example.com', role: 'admin', usage: 75000 },
14
+ { id: 2, name: 'Jane Smith', email: 'jane@example.com', role: 'user', usage: 45000, isLocked: true },
15
+ { id: 3, name: 'Bob Johnson', email: 'bob@example.com', role: 'viewer', usage: 25000 },
16
+ { id: 4, name: 'Alice Brown', email: 'alice@example.com', role: 'user', usage: 85000 },
17
+ { id: 5, name: 'Charlie Wilson', email: 'charlie@example.com', role: 'admin', usage: 35000, isLocked: true },
18
+ { id: 6, name: 'Diana Prince', email: 'diana@example.com', role: 'user', usage: 95000 },
19
+ { id: 7, name: 'Bruce Wayne', email: 'bruce@example.com', role: 'admin', usage: 65000 },
20
+ { id: 8, name: 'Clark Kent', email: 'clark@example.com', role: 'viewer', usage: 15000 },
21
+ ];
22
+ export function CustomSelectionExample() {
23
+ const [users] = useState(mockUsers);
24
+ const [mode, setMode] = useState('page');
25
+ const [currentSelection, setCurrentSelection] = useState({
26
+ ids: [],
27
+ idsSet: new Set(),
28
+ type: 'include'
29
+ });
30
+ // Row disable modes demonstration
31
+ const [disableMode, setDisableMode] = useState('none');
32
+ // Create isRowSelectable function based on mode (like MUI DataGrid)
33
+ const isRowSelectable = useMemo(() => {
34
+ switch (disableMode) {
35
+ case 'locked-users':
36
+ return ({ row }) => !row.isLocked;
37
+ case 'viewers':
38
+ return ({ row }) => row.role !== 'viewer';
39
+ case 'low-usage':
40
+ return ({ row }) => row.usage > 50000;
41
+ default:
42
+ return undefined; // All rows selectable
43
+ }
44
+ }, [disableMode]);
45
+ // Initialize custom selection manager
46
+ const selectionManager = useMemo(() => {
47
+ const manager = new CustomSelectionManager({ ids: [], type: 'include' }, mode, undefined, // Table ref will be set automatically by special columns
48
+ isRowSelectable // Pass isRowSelectable to constructor
49
+ );
50
+ // Enhanced callback with Set for performance
51
+ manager.onChange((state, tableRef) => {
52
+ console.log('Selection changed (with Set):', {
53
+ selectedIds: state.ids,
54
+ selectedSet: state.idsSet,
55
+ type: state.type,
56
+ totalSelected: state.idsSet.size,
57
+ tableRef: !!tableRef
58
+ });
59
+ setCurrentSelection(state);
60
+ });
61
+ return manager;
62
+ }, [mode, isRowSelectable]);
63
+ // Update manager when mode or isRowSelectable changes
64
+ useMemo(() => {
65
+ selectionManager.setSelectionMode(mode);
66
+ selectionManager.setIsRowSelectable(isRowSelectable);
67
+ }, [selectionManager, mode, isRowSelectable]);
68
+ // Define columns with custom selection column
69
+ const columns = useMemo(() => [
70
+ // Custom selection column
71
+ {
72
+ id: 'selection',
73
+ header: () => {
74
+ const allSelected = selectionManager.isAllSelected();
75
+ const someSelected = selectionManager.isSomeSelected();
76
+ return createElement(Checkbox, {
77
+ checked: allSelected,
78
+ indeterminate: someSelected && !allSelected,
79
+ onChange: () => selectionManager.toggleSelectAll(),
80
+ size: 'small',
81
+ sx: { p: 0 },
82
+ title: 'Select/Deselect All'
83
+ });
84
+ },
85
+ cell: ({ row }) => {
86
+ const rowId = String(row.original.id);
87
+ const checked = selectionManager.isRowSelected(rowId);
88
+ const canSelect = isRowSelectable
89
+ ? isRowSelectable({ row: row.original, id: rowId })
90
+ : true;
91
+ return createElement(Checkbox, {
92
+ checked,
93
+ disabled: !canSelect,
94
+ onChange: () => {
95
+ if (canSelect) {
96
+ selectionManager.toggleRowSelection(rowId);
97
+ }
98
+ },
99
+ size: 'small',
100
+ sx: {
101
+ p: 0,
102
+ opacity: canSelect ? 1 : 0.5
103
+ },
104
+ title: canSelect ? 'Click to toggle selection' : 'This row cannot be selected'
105
+ });
106
+ },
107
+ size: 50,
108
+ },
109
+ {
110
+ accessorKey: 'id',
111
+ header: 'ID',
112
+ size: 80,
113
+ },
114
+ {
115
+ accessorKey: 'name',
116
+ header: 'Name',
117
+ size: 150,
118
+ cell: ({ getValue, row }) => {
119
+ const name = getValue();
120
+ const user = row.original;
121
+ return (_jsxs("span", { children: [name, " ", user.isLocked && '🔒'] }));
122
+ },
123
+ },
124
+ {
125
+ accessorKey: 'email',
126
+ header: 'Email',
127
+ size: 200,
128
+ },
129
+ {
130
+ accessorKey: 'role',
131
+ header: 'Role',
132
+ size: 100,
133
+ cell: ({ getValue }) => {
134
+ const role = getValue();
135
+ const colors = {
136
+ admin: '#9c27b0',
137
+ user: '#2196f3',
138
+ viewer: '#757575',
139
+ };
140
+ return (_jsx("span", { style: { color: colors[role], fontWeight: 'bold' }, children: role }));
141
+ },
142
+ },
143
+ {
144
+ accessorKey: 'usage',
145
+ header: 'Usage',
146
+ size: 120,
147
+ cell: ({ getValue }) => {
148
+ const usage = getValue();
149
+ const color = usage > 50000 ? '#4caf50' : '#ff9800';
150
+ return (_jsx("span", { style: { color, fontWeight: 'bold' }, children: usage.toLocaleString() }));
151
+ },
152
+ },
153
+ ], [selectionManager, isRowSelectable]);
154
+ const handleSelectionChange = useCallback((selection) => {
155
+ console.log('Selection state changed:', selection);
156
+ }, []);
157
+ return (_jsxs("div", { style: { padding: '20px', maxWidth: '1200px', margin: '0 auto' }, children: [_jsx("h2", { children: "Custom Selection Example with isRowSelectable" }), _jsxs("p", { children: ["This example demonstrates the simple ", _jsx("code", { children: "isRowSelectable" }), " prop that works like MUI DataGrid to control which rows can be selected."] }), _jsxs("div", { style: {
158
+ display: 'flex',
159
+ gap: '20px',
160
+ marginBottom: '20px',
161
+ padding: '15px',
162
+ backgroundColor: '#f5f5f5',
163
+ borderRadius: '8px'
164
+ }, children: [_jsx("div", { children: _jsxs("label", { children: [_jsx("strong", { children: "Selection Mode:" }), _jsxs("select", { value: mode, onChange: (e) => setMode(e.target.value), style: { marginLeft: '8px', padding: '4px' }, children: [_jsx("option", { value: "page", children: "Page Mode" }), _jsx("option", { value: "all", children: "All Mode" })] })] }) }), _jsx("div", { children: _jsxs("label", { children: [_jsx("strong", { children: "Row Selection Rules:" }), _jsxs("select", { value: disableMode, onChange: (e) => setDisableMode(e.target.value), style: { marginLeft: '8px', padding: '4px' }, children: [_jsx("option", { value: "none", children: "All Selectable \u2705" }), _jsx("option", { value: "locked-users", children: "Disable Locked Users \uD83D\uDD12" }), _jsx("option", { value: "viewers", children: "Disable Viewers \uD83D\uDC41\uFE0F" }), _jsx("option", { value: "low-usage", children: "Disable Low Usage (<50k) \uD83D\uDCC9" })] })] }) })] }), _jsxs("div", { style: {
165
+ display: 'flex',
166
+ gap: '15px',
167
+ marginBottom: '20px',
168
+ flexWrap: 'wrap'
169
+ }, children: [_jsx("button", { onClick: () => selectionManager.selectAll(), style: { padding: '8px 16px', backgroundColor: '#2196f3', color: 'white', border: 'none', borderRadius: '4px' }, children: "Select All" }), _jsx("button", { onClick: () => selectionManager.deselectAll(), style: { padding: '8px 16px', backgroundColor: '#f44336', color: 'white', border: 'none', borderRadius: '4px' }, children: "Deselect All" }), _jsx("button", { onClick: () => {
170
+ console.time('Bulk Select All (Set-based)');
171
+ selectionManager.selectAll();
172
+ console.timeEnd('Bulk Select All (Set-based)');
173
+ console.log('Selected all selectable rows automatically!');
174
+ }, style: { padding: '8px 16px', backgroundColor: '#ff9800', color: 'white', border: 'none', borderRadius: '4px' }, children: "\uD83D\uDE80 Select All Selectable (Performance Test)" })] }), _jsx("div", { style: { marginBottom: '20px', height: '400px' }, children: _jsx(DataTable, { ref: (tableRef) => {
175
+ if (tableRef) {
176
+ selectionManager.setTableRef(tableRef);
177
+ }
178
+ }, data: users, columns: columns, idKey: "id", loading: false, enableRowSelection: false, tableSize: "small", onSelectionChange: handleSelectionChange }) }), _jsxs("div", { style: {
179
+ padding: '15px',
180
+ backgroundColor: '#f9f9f9',
181
+ borderRadius: '8px',
182
+ border: '1px solid #ddd'
183
+ }, children: [_jsx("h3", { children: "Selection State (Real-time)" }), _jsxs("div", { style: { display: 'grid', gridTemplateColumns: '1fr 1fr', gap: '20px' }, children: [_jsxs("div", { children: [_jsx("h4", { children: "Current Selection:" }), _jsxs("p", { children: [_jsx("strong", { children: "Count:" }), " ", currentSelection.idsSet.size] }), _jsxs("p", { children: [_jsx("strong", { children: "Type:" }), " ", currentSelection.type] }), _jsxs("p", { children: [_jsx("strong", { children: "IDs:" }), " [", currentSelection.ids.join(', '), "]"] })] }), _jsxs("div", { children: [_jsx("strong", { children: "Selection Rules:" }), _jsxs("p", { children: [disableMode === 'none' && 'All rows are selectable ✅', disableMode === 'locked-users' && 'Locked users 🔒 cannot be selected', disableMode === 'viewers' && 'Viewer role 👁️ users cannot be selected', disableMode === 'low-usage' && 'Users with usage < 50k 📉 cannot be selected'] }), isRowSelectable && (_jsxs("small", { style: { color: '#666' }, children: ["Selectable rows: ", users.filter(user => isRowSelectable({ row: user, id: String(user.id) })).length, " / ", users.length] }))] })] }), _jsx("h4", { children: "Performance Features:" }), _jsxs("ul", { style: { margin: 0 }, children: [_jsx("li", { children: "\u2705 Set-based operations for O(1) lookups" }), _jsxs("li", { children: ["\u2705 Bulk operations with ", _jsx("code", { children: "selectRows()" })] }), _jsxs("li", { children: ["\u2705 Simple row disable with ", _jsx("code", { children: "isRowSelectable" })] }), _jsx("li", { children: "\u2705 Compatible with both 'page' and 'all' selection modes" }), _jsx("li", { children: "\u2705 Clean API similar to MUI DataGrid" })] })] })] }));
184
+ }
@@ -0,0 +1 @@
1
+ {"version":3,"file":"export-callbacks-example.d.ts","sourceRoot":"","sources":["../../../src/lib/examples/export-callbacks-example.tsx"],"names":[],"mappings":"AA4DA,wBAAgB,sBAAsB,4CAqTrC"}