@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,101 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useCallback } from 'react';
|
|
3
|
+
import { Box, Typography, Chip } from '@mui/material';
|
|
4
|
+
import { DataTable } from '../components';
|
|
5
|
+
// Simple static data
|
|
6
|
+
const products = [
|
|
7
|
+
{ id: 1, name: 'Laptop Pro', category: 'Electronics', price: 1299, inStock: true, rating: 4.5 },
|
|
8
|
+
{ id: 2, name: 'Wireless Mouse', category: 'Electronics', price: 29, inStock: true, rating: 4.2 },
|
|
9
|
+
{ id: 3, name: 'Coffee Mug', category: 'Kitchen', price: 12, inStock: false, rating: 4.8 },
|
|
10
|
+
{ id: 4, name: 'Desk Chair', category: 'Furniture', price: 189, inStock: true, rating: 4.0 },
|
|
11
|
+
{ id: 5, name: 'Notebook Set', category: 'Office', price: 15, inStock: true, rating: 4.3 },
|
|
12
|
+
{ id: 6, name: 'Water Bottle', category: 'Kitchen', price: 22, inStock: true, rating: 4.7 },
|
|
13
|
+
{ id: 7, name: 'Monitor Stand', category: 'Electronics', price: 45, inStock: false, rating: 4.1 },
|
|
14
|
+
{ id: 8, name: 'Pen Set', category: 'Office', price: 8, inStock: true, rating: 3.9 },
|
|
15
|
+
{ id: 9, name: 'Table Lamp', category: 'Furniture', price: 67, inStock: true, rating: 4.4 },
|
|
16
|
+
{ id: 10, name: 'Phone Case', category: 'Electronics', price: 25, inStock: true, rating: 4.6 },
|
|
17
|
+
{ id: 11, name: 'Phone Case', category: 'Electronics', price: 25, inStock: true, rating: 4.6 },
|
|
18
|
+
{ id: 12, name: 'Phone Case', category: 'Electronics', price: 25, inStock: true, rating: 4.6 },
|
|
19
|
+
{ id: 13, name: 'Phone Case', category: 'Electronics', price: 25, inStock: true, rating: 4.6 },
|
|
20
|
+
{ id: 14, name: 'Phone Case', category: 'Electronics', price: 25, inStock: true, rating: 4.6 },
|
|
21
|
+
{ id: 15, name: 'Phone Case', category: 'Electronics', price: 25, inStock: true, rating: 4.6 },
|
|
22
|
+
{ id: 16, name: 'Phone Case', category: 'Electronics', price: 25, inStock: true, rating: 4.6 },
|
|
23
|
+
{ id: 17, name: 'Phone Case', category: 'Electronics', price: 25, inStock: true, rating: 4.6 },
|
|
24
|
+
];
|
|
25
|
+
// Simple column definitions
|
|
26
|
+
const columns = [
|
|
27
|
+
{
|
|
28
|
+
accessorKey: 'name',
|
|
29
|
+
header: 'Product Name',
|
|
30
|
+
size: 180,
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
accessorKey: 'category',
|
|
34
|
+
header: 'Category',
|
|
35
|
+
size: 120,
|
|
36
|
+
cell: ({ getValue }) => (_jsx(Chip, { label: getValue(), size: "small", variant: "outlined", color: "primary" })),
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
accessorKey: 'price',
|
|
40
|
+
header: 'Price',
|
|
41
|
+
size: 100,
|
|
42
|
+
cell: ({ getValue }) => `$${getValue().toFixed(2)}`,
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
accessorKey: 'inStock',
|
|
46
|
+
header: 'In Stock',
|
|
47
|
+
size: 100,
|
|
48
|
+
cell: ({ getValue }) => (_jsx(Chip, { label: getValue() ? 'Yes' : 'No', color: getValue() ? 'success' : 'error', size: "small" })),
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
accessorKey: 'rating',
|
|
52
|
+
header: 'Rating',
|
|
53
|
+
size: 100,
|
|
54
|
+
cell: ({ getValue }) => `⭐ ${getValue().toFixed(1)}`,
|
|
55
|
+
},
|
|
56
|
+
];
|
|
57
|
+
export function SimpleLocalExample() {
|
|
58
|
+
// Memoize bulkActions function to prevent infinite re-renders
|
|
59
|
+
const bulkActions = useCallback((selectionState) => (_jsxs(Box, { sx: { display: 'flex', gap: 1 }, children: [_jsx("button", { onClick: () => {
|
|
60
|
+
const count = selectionState.type === 'include'
|
|
61
|
+
? selectionState.ids.length
|
|
62
|
+
: products.length - selectionState.ids.length;
|
|
63
|
+
alert(`Selected ${count} products (${selectionState.type} mode)`);
|
|
64
|
+
}, style: {
|
|
65
|
+
padding: '8px 16px',
|
|
66
|
+
borderRadius: '4px',
|
|
67
|
+
border: '1px solid #ccc',
|
|
68
|
+
background: '#f5f5f5',
|
|
69
|
+
cursor: 'pointer'
|
|
70
|
+
}, children: "\uD83D\uDCCA Show Count" }), _jsx("button", { onClick: () => {
|
|
71
|
+
let selectedProducts;
|
|
72
|
+
if (selectionState.type === 'include') {
|
|
73
|
+
selectedProducts = products.filter(p => selectionState.ids.includes(p.id.toString()));
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
selectedProducts = products.filter(p => !selectionState.ids.includes(p.id.toString()));
|
|
77
|
+
}
|
|
78
|
+
const total = selectedProducts.reduce((sum, product) => sum + product.price, 0);
|
|
79
|
+
alert(`Total value: $${total.toFixed(2)}`);
|
|
80
|
+
}, style: {
|
|
81
|
+
padding: '8px 16px',
|
|
82
|
+
borderRadius: '4px',
|
|
83
|
+
border: '1px solid #ccc',
|
|
84
|
+
background: '#f5f5f5',
|
|
85
|
+
cursor: 'pointer'
|
|
86
|
+
}, children: "\uD83D\uDCB0 Calculate Total" })] })), []);
|
|
87
|
+
return (_jsxs(Box, { sx: { p: 3 }, children: [_jsx(Typography, { variant: "h4", gutterBottom: true, children: "Simple Local Data Example" }), _jsx(Typography, { variant: "body1", color: "text.secondary", sx: { mb: 3 }, children: "A basic example using static local data with no API calls. Demonstrates essential DataTable features with minimal setup." }), _jsx(DataTable, { data: products, totalRow: products.length, columns: columns,
|
|
88
|
+
//Enable basic features
|
|
89
|
+
enableSorting: true, enableGlobalFilter: true, enableColumnFilter: true,
|
|
90
|
+
// enablePagination={false}
|
|
91
|
+
enableColumnResizing: true, enableRowSelection: true, enableBulkActions: true, bulkActions: bulkActions, fitToScreen: true, initialState: {
|
|
92
|
+
pagination: {
|
|
93
|
+
pageIndex: 0,
|
|
94
|
+
pageSize: 5,
|
|
95
|
+
},
|
|
96
|
+
}, slotProps: {
|
|
97
|
+
pagination: {
|
|
98
|
+
rowsPerPageOptions: [5, 10, 20, 30, 40, 50],
|
|
99
|
+
},
|
|
100
|
+
} }), _jsx(Box, { sx: { mt: 2, p: 2, backgroundColor: 'grey.50', borderRadius: 1 }, children: _jsxs(Typography, { variant: "body2", color: "text.secondary", children: ["\uD83D\uDCA1 ", _jsx("strong", { children: "This example demonstrates:" }), _jsx("br", {}), "\u2022 Basic table with static local data", _jsx("br", {}), "\u2022 Simple column definitions with custom cell renderers", _jsx("br", {}), "\u2022 Sorting, filtering, and pagination", _jsx("br", {}), "\u2022 Row selection with bulk actions", _jsx("br", {}), "\u2022 Minimal setup - perfect for getting started"] }) })] }));
|
|
101
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"simple-server-selection-example.d.ts","sourceRoot":"","sources":["../../../src/lib/examples/simple-server-selection-example.tsx"],"names":[],"mappings":"AAsCA,wBAAgB,4BAA4B,4CA+Q3C"}
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* Simple Server Selection Example
|
|
4
|
+
* Demonstrates the clean, straightforward approach to server-side selection using selectMode
|
|
5
|
+
*/
|
|
6
|
+
import { useState, useMemo, useRef } from 'react';
|
|
7
|
+
import { Box, Typography, Card, CardContent, Button, Alert, Chip, Stack } from '@mui/material';
|
|
8
|
+
import { DataTable } from '../components/table/data-table';
|
|
9
|
+
// Generate sample data
|
|
10
|
+
const generateEmployees = (count) => {
|
|
11
|
+
const departments = ['Engineering', 'Marketing', 'Sales', 'HR', 'Finance'];
|
|
12
|
+
const roles = ['Manager', 'Senior', 'Junior', 'Lead', 'Director'];
|
|
13
|
+
const names = ['John Smith', 'Jane Doe', 'Bob Johnson', 'Alice Brown', 'Charlie Wilson'];
|
|
14
|
+
return Array.from({ length: count }, (_, index) => ({
|
|
15
|
+
id: index + 1,
|
|
16
|
+
name: names[Math.floor(Math.random() * names.length)] + ` ${index + 1}`,
|
|
17
|
+
email: `employee${index + 1}@company.com`,
|
|
18
|
+
department: departments[Math.floor(Math.random() * departments.length)],
|
|
19
|
+
role: roles[Math.floor(Math.random() * roles.length)],
|
|
20
|
+
salary: Math.floor(Math.random() * 80000) + 40000,
|
|
21
|
+
isActive: Math.random() > 0.2,
|
|
22
|
+
}));
|
|
23
|
+
};
|
|
24
|
+
export function SimpleServerSelectionExample() {
|
|
25
|
+
// Sample data (in real app, this would come from server)
|
|
26
|
+
const employees = useMemo(() => generateEmployees(500), []);
|
|
27
|
+
const totalFilteredCount = employees.length; // In real app, this comes from server
|
|
28
|
+
// Selection mode state
|
|
29
|
+
const [selectMode, setSelectMode] = useState('page');
|
|
30
|
+
// API ref for debugging
|
|
31
|
+
const apiRef = useRef(null);
|
|
32
|
+
const handleFetchData = (filters) => {
|
|
33
|
+
if (filters?.pagination?.pageSize) {
|
|
34
|
+
const data = employees.slice(filters.pagination.pageIndex * filters?.pagination?.pageSize, (filters.pagination.pageIndex + 1) * filters?.pagination?.pageSize);
|
|
35
|
+
console.log('data', data?.length);
|
|
36
|
+
return Promise.resolve({
|
|
37
|
+
data,
|
|
38
|
+
total: employees.length,
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
return Promise.resolve({
|
|
42
|
+
data: employees,
|
|
43
|
+
total: employees.length,
|
|
44
|
+
});
|
|
45
|
+
};
|
|
46
|
+
// Define columns
|
|
47
|
+
const columns = [
|
|
48
|
+
{
|
|
49
|
+
id: 'name',
|
|
50
|
+
accessorKey: 'name',
|
|
51
|
+
header: 'Name',
|
|
52
|
+
size: 200,
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
id: 'email',
|
|
56
|
+
accessorKey: 'email',
|
|
57
|
+
header: 'Email',
|
|
58
|
+
size: 250,
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
id: 'department',
|
|
62
|
+
accessorKey: 'department',
|
|
63
|
+
header: 'Department',
|
|
64
|
+
size: 150,
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
id: 'role',
|
|
68
|
+
accessorKey: 'role',
|
|
69
|
+
header: 'Role',
|
|
70
|
+
size: 120,
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
id: 'salary',
|
|
74
|
+
accessorKey: 'salary',
|
|
75
|
+
header: 'Salary',
|
|
76
|
+
size: 120,
|
|
77
|
+
cell: ({ getValue }) => `$${getValue().toLocaleString()}`,
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
id: 'isActive',
|
|
81
|
+
accessorKey: 'isActive',
|
|
82
|
+
header: 'Status',
|
|
83
|
+
size: 100,
|
|
84
|
+
cell: ({ getValue }) => getValue() ? 'Active' : 'Inactive',
|
|
85
|
+
},
|
|
86
|
+
];
|
|
87
|
+
return (_jsxs(Box, { sx: { p: 3 }, children: [_jsx(Typography, { variant: "h4", gutterBottom: true, children: "Simple Server Selection Example" }), _jsx(Typography, { variant: "body1", color: "text.secondary", paragraph: true, children: "Clean implementation of server-side selection with page-level and \"select all matching\" features." }), _jsx(Card, { sx: { mb: 3 }, children: _jsxs(CardContent, { children: [_jsx(Typography, { variant: "h6", gutterBottom: true, children: "Selection Mode" }), _jsxs(Stack, { direction: "row", spacing: 2, alignItems: "center", children: [_jsx(Button, { variant: selectMode === 'page' ? 'contained' : 'outlined', onClick: () => setSelectMode('page'), size: "small", children: "Page Selection" }), _jsx(Button, { variant: selectMode === 'all' ? 'contained' : 'outlined', onClick: () => setSelectMode('all'), size: "small", children: "All Pages Selection" }), _jsx(Chip, { label: selectMode === 'page' ? 'Select rows on current page only' : 'Select all matching rows across pages', size: "small", color: "info" })] })] }) }), _jsx(Alert, { severity: "info", sx: { mb: 3 }, children: _jsxs(Typography, { variant: "body2", children: [_jsx("strong", { children: "How to use:" }), _jsx("br", {}), "\u2022 ", _jsx("strong", { children: "Page Selection:" }), " Header checkbox selects/deselects all rows on current page", _jsx("br", {}), "\u2022 ", _jsx("strong", { children: "All Pages Selection:" }), " Header checkbox toggles \"select all matching\" mode", _jsx("br", {}), "\u2022 When \"select all matching\" is active, individual checkboxes exclude/include specific rows", _jsx("br", {}), "\u2022 Bulk actions receive different payload based on selection mode"] }) }), _jsx(DataTable, { ref: (api) => {
|
|
88
|
+
apiRef.current = api;
|
|
89
|
+
// You can access the selection API here
|
|
90
|
+
if (api) {
|
|
91
|
+
// Example: api.selection.getSelectionState()
|
|
92
|
+
// Example: api.selection.selectAll()
|
|
93
|
+
// Example: api.selection.setSelectionMode('all')
|
|
94
|
+
}
|
|
95
|
+
}, initialLoadData: true, columns: columns, onFetchData: handleFetchData, dataMode: "server" // Server mode to demonstrate server selection
|
|
96
|
+
, selectMode: selectMode, enableRowSelection: true, enableMultiRowSelection: true, enableBulkActions: true, enablePagination: true, bulkActions: (selectionState) => (_jsxs(Button, { variant: "contained", size: "small", onClick: () => {
|
|
97
|
+
// The bulk action payload is automatically logged in console
|
|
98
|
+
// You can also access it via the API ref
|
|
99
|
+
console.log('Bulk action triggered with selection mode:', selectMode);
|
|
100
|
+
console.log('Selected rows:', selectionState?.ids);
|
|
101
|
+
}, children: ["Delete Selected (", selectionState?.ids.length, ")"] })) }), _jsx(Card, { sx: { mt: 3 }, children: _jsxs(CardContent, { children: [_jsx(Typography, { variant: "h6", gutterBottom: true, children: "Debug Controls" }), _jsxs(Stack, { direction: "row", spacing: 2, children: [_jsx(Button, { variant: "outlined", onClick: () => {
|
|
102
|
+
if (apiRef.current) {
|
|
103
|
+
console.log('Manual selectAll trigger');
|
|
104
|
+
apiRef.current.selection.selectAll();
|
|
105
|
+
}
|
|
106
|
+
}, children: "Manual Select All" }), _jsx(Button, { variant: "outlined", onClick: () => {
|
|
107
|
+
if (apiRef.current) {
|
|
108
|
+
console.log('Manual toggleSelectAll trigger');
|
|
109
|
+
apiRef.current.selection.toggleSelectAll();
|
|
110
|
+
}
|
|
111
|
+
}, children: "Manual Toggle Select All" }), _jsx(Button, { variant: "outlined", onClick: () => {
|
|
112
|
+
if (apiRef.current) {
|
|
113
|
+
const payload = apiRef.current.selection.getSelectionState();
|
|
114
|
+
console.log('Current Selection Payload:', payload);
|
|
115
|
+
console.log('Selected Count:', apiRef.current.selection.getSelectedCount());
|
|
116
|
+
console.log('Is All Selected:', apiRef.current.selection.isAllSelected());
|
|
117
|
+
console.log('Is Some Selected:', apiRef.current.selection.isSomeSelected());
|
|
118
|
+
}
|
|
119
|
+
}, children: "Debug Selection State" })] })] }) }), _jsx(Card, { sx: { mt: 3 }, children: _jsxs(CardContent, { children: [_jsx(Typography, { variant: "h6", gutterBottom: true, children: "Key Implementation Details:" }), _jsx(Typography, { variant: "body2", component: "pre", sx: {
|
|
120
|
+
bgcolor: 'grey.100',
|
|
121
|
+
p: 2,
|
|
122
|
+
borderRadius: 1,
|
|
123
|
+
overflow: 'auto',
|
|
124
|
+
fontSize: '0.875rem',
|
|
125
|
+
fontFamily: 'monospace'
|
|
126
|
+
}, children: `// User's exact state structure
|
|
127
|
+
type ServerSelectionState = {
|
|
128
|
+
selectAllMatching: boolean; // true = all filtered rows across pages selected
|
|
129
|
+
selectedRowIds: string[]; // specific rows selected if selectAllMatching=false
|
|
130
|
+
excludedRowIds: string[]; // specific rows excluded if selectAllMatching=true
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
// Handler: Select All Matching Rows Across Pages
|
|
134
|
+
const handleSelectAllMatching = () => {
|
|
135
|
+
setServerSelection({
|
|
136
|
+
selectAllMatching: true,
|
|
137
|
+
selectedRowIds: [],
|
|
138
|
+
excludedRowIds: [],
|
|
139
|
+
});
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
// Handler: Toggle Individual Row Selection
|
|
143
|
+
const handleRowToggle = (rowId: string, isSelected: boolean) => {
|
|
144
|
+
setServerSelection(prev => {
|
|
145
|
+
if (prev.selectAllMatching) {
|
|
146
|
+
// If selecting all: manage exclusions
|
|
147
|
+
return {
|
|
148
|
+
...prev,
|
|
149
|
+
excludedRowIds: isSelected
|
|
150
|
+
? prev.excludedRowIds.filter(id => id !== rowId) // re-select row
|
|
151
|
+
: [...prev.excludedRowIds, rowId], // deselect row
|
|
152
|
+
};
|
|
153
|
+
} else {
|
|
154
|
+
// If not selecting all: manage individual selection
|
|
155
|
+
return {
|
|
156
|
+
...prev,
|
|
157
|
+
selectedRowIds: isSelected
|
|
158
|
+
? [...prev.selectedRowIds, rowId]
|
|
159
|
+
: prev.selectedRowIds.filter(id => id !== rowId),
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
});
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
// Payload for Bulk Actions
|
|
166
|
+
const getBulkActionPayload = () => ({
|
|
167
|
+
filters: table.getState().columnFilters,
|
|
168
|
+
selectAllMatching: serverSelection.selectAllMatching,
|
|
169
|
+
selectedRowIds: serverSelection.selectedRowIds,
|
|
170
|
+
excludedRowIds: serverSelection.excludedRowIds,
|
|
171
|
+
});` })] }) })] }));
|
|
172
|
+
}
|
|
173
|
+
// Separate component to demonstrate the server selection integration
|
|
174
|
+
function ServerSelectionDataTable({ columns, data, totalFilteredCount }) {
|
|
175
|
+
// This would be your DataTable component with server selection integrated
|
|
176
|
+
// For now, we'll create a simplified version to show the concept
|
|
177
|
+
return (_jsx(Card, { children: _jsxs(CardContent, { children: [_jsx(Typography, { variant: "h6", gutterBottom: true, children: "DataTable with Server Selection" }), _jsx(Typography, { variant: "body2", color: "text.secondary", children: "This is where your DataTable component would be integrated with the server selection hook. The actual implementation would connect the useServerSelection hook with your DataTable component." }), _jsxs(Stack, { spacing: 2, sx: { mt: 2 }, children: [_jsxs(Typography, { variant: "body2", children: [_jsx("strong", { children: "Total Employees:" }), " ", totalFilteredCount.toLocaleString()] }), _jsxs(Typography, { variant: "body2", children: [_jsx("strong", { children: "Columns:" }), " ", columns.map(col => col.header).join(', ')] })] }), _jsx(Alert, { severity: "warning", sx: { mt: 2 }, children: _jsxs(Typography, { variant: "body2", children: [_jsx("strong", { children: "Next Step:" }), " Integrate the useServerSelection hook with your DataTable component to enable the server selection functionality shown in the code example above."] }) })] }) }));
|
|
178
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"virtualized-example.d.ts","sourceRoot":"","sources":["../../../src/lib/examples/virtualized-example.tsx"],"names":[],"mappings":"AA0CA,wBAAgB,kBAAkB,4CA6MjC"}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Box, Typography, Button, ButtonGroup, Chip } from '@mui/material';
|
|
3
|
+
import { useState, useMemo } from 'react';
|
|
4
|
+
import { DataTable } from '../components';
|
|
5
|
+
// Generate sample data
|
|
6
|
+
const generateSampleData = (count) => {
|
|
7
|
+
const departments = [
|
|
8
|
+
'Engineering',
|
|
9
|
+
'Marketing',
|
|
10
|
+
'Sales',
|
|
11
|
+
'HR',
|
|
12
|
+
'Finance',
|
|
13
|
+
];
|
|
14
|
+
const statuses = ['active', 'inactive'];
|
|
15
|
+
return Array.from({ length: count }, (_, i) => ({
|
|
16
|
+
id: i + 1,
|
|
17
|
+
name: `User ${i + 1}`,
|
|
18
|
+
email: `user${i + 1}@example.com`,
|
|
19
|
+
age: Math.floor(Math.random() * 40) + 25,
|
|
20
|
+
department: departments[Math.floor(Math.random() * departments.length)],
|
|
21
|
+
salary: Math.floor(Math.random() * 100000) + 40000,
|
|
22
|
+
joinDate: new Date(2020 + Math.floor(Math.random() * 4), Math.floor(Math.random() * 12), Math.floor(Math.random() * 28) + 1).toISOString().split('T')[0],
|
|
23
|
+
status: statuses[Math.floor(Math.random() * statuses.length)],
|
|
24
|
+
}));
|
|
25
|
+
};
|
|
26
|
+
export function VirtualizedExample() {
|
|
27
|
+
const [datasetSize, setDatasetSize] = useState(1000);
|
|
28
|
+
const [enableVirtualization, setEnableVirtualization] = useState(true);
|
|
29
|
+
// Generate data based on selected size
|
|
30
|
+
const data = useMemo(() => generateSampleData(datasetSize), [datasetSize]);
|
|
31
|
+
// Define columns
|
|
32
|
+
const columns = [
|
|
33
|
+
{
|
|
34
|
+
id: 'id',
|
|
35
|
+
header: 'ID',
|
|
36
|
+
size: 80,
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
accessorKey: 'name',
|
|
40
|
+
header: 'Name',
|
|
41
|
+
size: 150,
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
accessorKey: 'email',
|
|
45
|
+
header: 'Email',
|
|
46
|
+
size: 200,
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
accessorKey: 'age',
|
|
50
|
+
header: 'Age',
|
|
51
|
+
size: 80,
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
accessorKey: 'department',
|
|
55
|
+
header: 'Department',
|
|
56
|
+
size: 120,
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
accessorKey: 'salary',
|
|
60
|
+
header: 'Salary',
|
|
61
|
+
size: 120,
|
|
62
|
+
cell: ({ getValue }) => `$${getValue().toLocaleString()}`,
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
accessorKey: 'joinDate',
|
|
66
|
+
header: 'Join Date',
|
|
67
|
+
size: 120,
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
accessorKey: 'status',
|
|
71
|
+
header: 'Status',
|
|
72
|
+
size: 100,
|
|
73
|
+
cell: ({ getValue }) => {
|
|
74
|
+
const status = getValue();
|
|
75
|
+
return (_jsx(Chip, { label: status, color: status === 'active' ? 'success' : 'default', size: "small" }));
|
|
76
|
+
},
|
|
77
|
+
},
|
|
78
|
+
];
|
|
79
|
+
const datasetOptions = [
|
|
80
|
+
{
|
|
81
|
+
size: 100,
|
|
82
|
+
label: '100 rows',
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
size: 500,
|
|
86
|
+
label: '500 rows',
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
size: 1000,
|
|
90
|
+
label: '1K rows',
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
size: 5000,
|
|
94
|
+
label: '5K rows',
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
size: 10000,
|
|
98
|
+
label: '10K rows',
|
|
99
|
+
},
|
|
100
|
+
];
|
|
101
|
+
return (_jsxs(Box, { sx: { p: 3 }, children: [_jsx(Typography, { variant: "h4", gutterBottom: true, children: "Virtualized DataTable Performance Test" }), _jsx(Typography, { variant: "body1", sx: { mb: 3 }, children: "Test the performance of the DataTable with different dataset sizes. Virtualization is recommended for datasets with 1000+ rows." }), _jsxs(Box, { sx: {
|
|
102
|
+
mb: 3,
|
|
103
|
+
display: 'flex',
|
|
104
|
+
gap: 2,
|
|
105
|
+
alignItems: 'center',
|
|
106
|
+
flexWrap: 'wrap',
|
|
107
|
+
}, children: [_jsx(Typography, { variant: "subtitle1", children: "Dataset Size:" }), _jsx(ButtonGroup, { size: "small", children: datasetOptions.map((option) => (_jsx(Button, { variant: datasetSize === option.size ? 'contained' : 'outlined', onClick: () => setDatasetSize(option.size), children: option.label }, option.size))) }), _jsxs(Button, { variant: enableVirtualization ? 'contained' : 'outlined', onClick: () => setEnableVirtualization(!enableVirtualization), color: enableVirtualization ? 'primary' : 'secondary', children: ["Virtualization:", ' ', enableVirtualization ? 'ON' : 'OFF'] })] }), _jsxs(Box, { sx: {
|
|
108
|
+
mb: 2,
|
|
109
|
+
p: 2,
|
|
110
|
+
bgcolor: 'background.paper',
|
|
111
|
+
borderRadius: 1,
|
|
112
|
+
border: '1px solid',
|
|
113
|
+
borderColor: 'divider',
|
|
114
|
+
}, children: [_jsx(Typography, { variant: "subtitle2", gutterBottom: true, children: "Current Configuration:" }), _jsxs(Typography, { variant: "body2", children: ["\u2022 Dataset:", ' ', datasetSize.toLocaleString(), ' ', "rows \u00D7", ' ', columns.length, ' ', "columns"] }), _jsxs(Typography, { variant: "body2", children: ["\u2022 Virtualization:", ' ', enableVirtualization ? 'Enabled' : 'Disabled'] }), _jsxs(Typography, { variant: "body2", children: ["\u2022 Pagination:", ' ', enableVirtualization ? 'Disabled (not compatible with virtualization)' : 'Enabled'] }), datasetSize >= 1000 && !enableVirtualization && (_jsx(Typography, { variant: "body2", color: "warning.main", children: "\u26A0\uFE0F Large dataset without virtualization may cause performance issues" }))] }), _jsx(DataTable, { columns: columns, data: data, enableRowSelection: true, enableColumnResizing: true, enableSorting: true, enableGlobalFilter: true, enableHover: true, enableStripes: true, fitToScreen: true, maxHeight: "500px", enableStickyHeaderOrFooter: true,
|
|
115
|
+
// Virtualization settings
|
|
116
|
+
enableVirtualization: enableVirtualization, estimateRowHeight: 52,
|
|
117
|
+
// Disable pagination when virtualization is enabled
|
|
118
|
+
enablePagination: !enableVirtualization })] }));
|
|
119
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"custom-column-filter.feature.d.ts","sourceRoot":"","sources":["../../../src/lib/features/custom-column-filter.feature.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EACH,KAAK,EACL,YAAY,EACZ,OAAO,EACP,OAAO,EAGP,QAAQ,EAGX,MAAM,uBAAuB,CAAC;AAG/B,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,sBAAsB,CAAC;AAIpE,MAAM,WAAW,gBAAgB;IAC7B,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,GAAG,CAAC;IACX,UAAU,CAAC,EAAE,MAAM,CAAC;CACvB;AAID,MAAM,WAAW,yBAAyB;IACtC,wBAAwB,CAAC,EAAE,OAAO,CAAC;IACnC,0BAA0B,CAAC,EAAE,CAAC,OAAO,EAAE,OAAO,CAAC,uBAAuB,CAAC,KAAK,IAAI,CAAC;IAEjF,yBAAyB,CAAC,EAAE,CAAC,KAAK,EAAE,uBAAuB,KAAK,IAAI,CAAC;CACxE;AAED,MAAM,WAAW,4BAA4B;IACzC,kBAAkB,EAAE,uBAAuB,CAAC;CAC/C;AAGD,OAAO,QAAQ,sBAAsB,CAAC;IAClC,UAAU,UAAW,SAAQ,4BAA4B;KAAI;IAC7D,UAAU,oBAAoB,CAAC,KAAK,SAAS,OAAO,CAChD,SAAQ,yBAAyB;KAAI;IACzC,UAAU,KAAK,CAAC,KAAK,SAAS,OAAO,CAAE,SAAQ,0BAA0B,CAAC,KAAK,CAAC;KAAI;CACvF;AAGD,MAAM,WAAW,0BAA0B,CAAC,KAAK,SAAS,OAAO;IAC7D,qBAAqB,EAAE,CAAC,OAAO,EAAE,OAAO,CAAC,uBAAuB,CAAC,KAAK,IAAI,CAAC;IAG3E,sBAAsB,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,KAAK,IAAI,CAAC;IACjF,yBAAyB,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,CAAC,gBAAgB,CAAC,KAAK,IAAI,CAAC;IAC1F,yBAAyB,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,IAAI,CAAC;IACtD,4BAA4B,EAAE,MAAM,IAAI,CAAC;IACzC,qBAAqB,EAAE,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI,KAAK,IAAI,CAAC;IAGrD,yBAAyB,EAAE,MAAM,IAAI,CAAC;IAGtC,eAAe,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,KAAK,IAAI,CAAC;IAC1E,kBAAkB,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,CAAC,gBAAgB,CAAC,KAAK,IAAI,CAAC;IACnF,kBAAkB,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,IAAI,CAAC;IAC/C,qBAAqB,EAAE,MAAM,IAAI,CAAC;IAClC,cAAc,EAAE,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI,KAAK,IAAI,CAAC;IAG9C,sBAAsB,EAAE,MAAM,gBAAgB,EAAE,CAAC;IACjD,uBAAuB,EAAE,MAAM,gBAAgB,EAAE,CAAC;IAClD,0BAA0B,EAAE,MAAM,uBAAuB,CAAC;CAC7D;AAGD,eAAO,MAAM,yBAAyB,EAAE,YAAY,CAAC,GAAG,CAyKvD,CAAC;AAEF;;;GAGG;AACH,wBAAgB,0BAA0B,CAAC,KAAK,SAAS,OAAO,EAC5D,GAAG,EAAE,GAAG,EACR,OAAO,EAAE,gBAAgB,EAAE,EAC3B,KAAK,GAAE,KAAK,GAAG,IAAY,GAC5B,OAAO,CA2BT;AAID,eAAO,MAAM,2BAA2B,GAAI,KAAK,QACrC,OAAO,KAAK,CAAC,KAAK,CAAC,WAAS,QAAQ,CAAC,KAAK,CAiCrD,CAAC"}
|