react-open-source-grid 1.0.0
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/README.md +254 -0
- package/dist/assets/index-DCnLBZA1.js +675 -0
- package/dist/assets/index-DzOsUHTl.css +1 -0
- package/dist/assets/layoutPersistence-BL6DMFaQ.js +1 -0
- package/dist/index.html +14 -0
- package/dist/vite.svg +1 -0
- package/package.json +64 -0
package/README.md
ADDED
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
# React DataGrid Component
|
|
2
|
+
|
|
3
|
+
A fully-featured, reusable DataGrid component built with React, TypeScript, and Tailwind CSS - similar to AG-Grid.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- ✅ Sortable columns (click header to sort)
|
|
8
|
+
- ✅ Column filtering (text search)
|
|
9
|
+
- ✅ Pagination (10, 20, 50 rows per page)
|
|
10
|
+
- ✅ Column resizing (drag borders)
|
|
11
|
+
- ✅ Column reordering (drag & drop)
|
|
12
|
+
- ✅ Row selection (single/multi/range)
|
|
13
|
+
- ✅ Editable cells (double-click to edit)
|
|
14
|
+
- ✅ Keyboard navigation (arrow keys)
|
|
15
|
+
- ✅ Sticky header
|
|
16
|
+
- ✅ Column pinning (freeze left/right columns)
|
|
17
|
+
- ✅ Row grouping (drag columns to group area)
|
|
18
|
+
- ✅ **Aggregation footer rows** (Total, Average, Min, Max, Count)
|
|
19
|
+
- ✅ **Group-level footers** (subtotals for each group)
|
|
20
|
+
- ✅ **Virtual Scrolling** (50,000+ rows, 200+ columns with ultra-fast rendering)
|
|
21
|
+
- ✅ **Cell Renderer Framework** (custom components: badges, progress bars, buttons, images, icons)
|
|
22
|
+
- ✅ **Layout Persistence** (save/load layouts with localStorage, server, or user profile storage)
|
|
23
|
+
- ✅ **Infinite Scrolling with Server-Side DataSource** (100M+ rows with server-side filtering, sorting, and caching)
|
|
24
|
+
|
|
25
|
+
## Quick Start
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
# Install dependencies
|
|
29
|
+
npm install
|
|
30
|
+
|
|
31
|
+
# Start development server
|
|
32
|
+
npm run dev
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
Open http://localhost:5173 to see the demo.
|
|
36
|
+
|
|
37
|
+
## Usage
|
|
38
|
+
|
|
39
|
+
```tsx
|
|
40
|
+
import { DataGrid } from './components/DataGrid';
|
|
41
|
+
import type { Column, Row } from './components/DataGrid';
|
|
42
|
+
|
|
43
|
+
const columns: Column[] = [
|
|
44
|
+
{ field: 'id', headerName: 'ID', width: 70 },
|
|
45
|
+
{ field: 'name', headerName: 'Name', width: 180, editable: true },
|
|
46
|
+
];
|
|
47
|
+
|
|
48
|
+
const rows: Row[] = [
|
|
49
|
+
{ id: 1, name: 'John Doe' },
|
|
50
|
+
{ id: 2, name: 'Jane Smith' },
|
|
51
|
+
];
|
|
52
|
+
|
|
53
|
+
<DataGrid
|
|
54
|
+
columns={columns}
|
|
55
|
+
rows={rows}
|
|
56
|
+
onCellEdit={(rowIndex, field, value) => {
|
|
57
|
+
console.log('Edited:', rowIndex, field, value);
|
|
58
|
+
}}
|
|
59
|
+
/>
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## Documentation
|
|
63
|
+
|
|
64
|
+
- **Full Documentation**: See [DATAGRID_README.md](./DATAGRID_README.md)
|
|
65
|
+
- **Quick Start Guide**: See [QUICKSTART.md](./QUICKSTART.md)
|
|
66
|
+
- **Architecture Guide**: See [src/components/DataGrid/ARCHITECTURE.md.ts](./src/components/DataGrid/ARCHITECTURE.md.ts)
|
|
67
|
+
- **Aggregation Footer Feature**: See [AGGREGATION_FOOTER_FEATURE.md](./AGGREGATION_FOOTER_FEATURE.md)
|
|
68
|
+
- **Footer Quick Reference**: See [FOOTER_QUICK_REFERENCE.md](./FOOTER_QUICK_REFERENCE.md)
|
|
69
|
+
- **Cell Renderer Framework**: See [CELL_RENDERER_FRAMEWORK.md](./CELL_RENDERER_FRAMEWORK.md)
|
|
70
|
+
- **Cell Renderer Quick Reference**: See [CELL_RENDERER_QUICK_REF.md](./CELL_RENDERER_QUICK_REF.md)
|
|
71
|
+
- **Layout Persistence**: See [LAYOUT_PERSISTENCE_INDEX.md](./LAYOUT_PERSISTENCE_INDEX.md) 🆕
|
|
72
|
+
- **Layout Persistence Feature Guide**: See [LAYOUT_PERSISTENCE_FEATURE.md](./LAYOUT_PERSISTENCE_FEATURE.md)
|
|
73
|
+
- **Layout Persistence Quick Reference**: See [LAYOUT_PERSISTENCE_QUICK_REF.md](./LAYOUT_PERSISTENCE_QUICK_REF.md)
|
|
74
|
+
|
|
75
|
+
## Technology Stack
|
|
76
|
+
|
|
77
|
+
- React 18 + TypeScript
|
|
78
|
+
- Vite (build tool)
|
|
79
|
+
- Tailwind CSS (styling)
|
|
80
|
+
|
|
81
|
+
---
|
|
82
|
+
|
|
83
|
+
## React + TypeScript + Vite
|
|
84
|
+
|
|
85
|
+
This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.
|
|
86
|
+
|
|
87
|
+
Currently, two official plugins are available:
|
|
88
|
+
|
|
89
|
+
- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react) uses [Babel](https://babeljs.io/) (or [oxc](https://oxc.rs) when used in [rolldown-vite](https://vite.dev/guide/rolldown)) for Fast Refresh
|
|
90
|
+
- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh
|
|
91
|
+
|
|
92
|
+
## React Compiler
|
|
93
|
+
|
|
94
|
+
The React Compiler is not enabled on this template because of its impact on dev & build performances. To add it, see [this documentation](https://react.dev/learn/react-compiler/installation).
|
|
95
|
+
|
|
96
|
+
## Expanding the ESLint configuration
|
|
97
|
+
|
|
98
|
+
If you are developing a production application, we recommend updating the configuration to enable type-aware lint rules:
|
|
99
|
+
|
|
100
|
+
```js
|
|
101
|
+
export default defineConfig([
|
|
102
|
+
globalIgnores(['dist']),
|
|
103
|
+
{
|
|
104
|
+
files: ['**/*.{ts,tsx}'],
|
|
105
|
+
extends: [
|
|
106
|
+
// Other configs...
|
|
107
|
+
|
|
108
|
+
// Remove tseslint.configs.recommended and replace with this
|
|
109
|
+
tseslint.configs.recommendedTypeChecked,
|
|
110
|
+
// Alternatively, use this for stricter rules
|
|
111
|
+
tseslint.configs.strictTypeChecked,
|
|
112
|
+
// Optionally, add this for stylistic rules
|
|
113
|
+
tseslint.configs.stylisticTypeChecked,
|
|
114
|
+
|
|
115
|
+
// Other configs...
|
|
116
|
+
],
|
|
117
|
+
languageOptions: {
|
|
118
|
+
parserOptions: {
|
|
119
|
+
project: ['./tsconfig.node.json', './tsconfig.app.json'],
|
|
120
|
+
tsconfigRootDir: import.meta.dirname,
|
|
121
|
+
},
|
|
122
|
+
// other options...
|
|
123
|
+
},
|
|
124
|
+
},
|
|
125
|
+
])
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
You can also install [eslint-plugin-react-x](https://github.com/Rel1cx/eslint-react/tree/main/packages/plugins/eslint-plugin-react-x) and [eslint-plugin-react-dom](https://github.com/Rel1cx/eslint-react/tree/main/packages/plugins/eslint-plugin-react-dom) for React-specific lint rules:
|
|
129
|
+
|
|
130
|
+
```js
|
|
131
|
+
// eslint.config.js
|
|
132
|
+
import reactX from 'eslint-plugin-react-x'
|
|
133
|
+
import reactDom from 'eslint-plugin-react-dom'
|
|
134
|
+
|
|
135
|
+
export default defineConfig([
|
|
136
|
+
globalIgnores(['dist']),
|
|
137
|
+
{
|
|
138
|
+
files: ['**/*.{ts,tsx}'],
|
|
139
|
+
extends: [
|
|
140
|
+
// Other configs...
|
|
141
|
+
// Enable lint rules for React
|
|
142
|
+
reactX.configs['recommended-typescript'],
|
|
143
|
+
// Enable lint rules for React DOM
|
|
144
|
+
reactDom.configs.recommended,
|
|
145
|
+
],
|
|
146
|
+
languageOptions: {
|
|
147
|
+
parserOptions: {
|
|
148
|
+
project: ['./tsconfig.node.json', './tsconfig.app.json'],
|
|
149
|
+
tsconfigRootDir: import.meta.dirname,
|
|
150
|
+
},
|
|
151
|
+
// other options...
|
|
152
|
+
},
|
|
153
|
+
},
|
|
154
|
+
])
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
## Virtual Scrolling
|
|
158
|
+
|
|
159
|
+
For large datasets (50,000+ rows, 200+ columns), enable virtual scrolling:
|
|
160
|
+
|
|
161
|
+
```tsx
|
|
162
|
+
import { DataGrid, VirtualScrollConfig } from './components/DataGrid';
|
|
163
|
+
|
|
164
|
+
const virtualConfig: VirtualScrollConfig = {
|
|
165
|
+
enabled: true,
|
|
166
|
+
rowHeight: 35,
|
|
167
|
+
containerHeight: 600,
|
|
168
|
+
enableColumnVirtualization: true,
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
<DataGrid
|
|
172
|
+
columns={columns}
|
|
173
|
+
rows={largeDataset}
|
|
174
|
+
virtualScrollConfig={virtualConfig}
|
|
175
|
+
/>
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
**Benefits:**
|
|
179
|
+
- Handles 100,000+ rows smoothly
|
|
180
|
+
- Supports 200+ columns with column virtualization
|
|
181
|
+
- 100x faster rendering vs non-virtual mode
|
|
182
|
+
- 100x less memory usage
|
|
183
|
+
- Smooth 60 FPS scrolling
|
|
184
|
+
|
|
185
|
+
**See also:**
|
|
186
|
+
- [VIRTUAL_SCROLLING.md](./VIRTUAL_SCROLLING.md) - Complete documentation
|
|
187
|
+
- [VIRTUAL_SCROLLING_QUICK_REF.md](./VIRTUAL_SCROLLING_QUICK_REF.md) - Quick reference guide
|
|
188
|
+
|
|
189
|
+
## Infinite Scrolling with Server-Side DataSource
|
|
190
|
+
|
|
191
|
+
For massive datasets (100M+ rows), use server-side infinite scrolling:
|
|
192
|
+
|
|
193
|
+
```tsx
|
|
194
|
+
import { InfiniteScrollDataGrid, ServerSideDataSource } from './components/DataGrid';
|
|
195
|
+
|
|
196
|
+
// Create data source
|
|
197
|
+
const dataSource = new ServerSideDataSource({
|
|
198
|
+
blockSize: 100, // Rows per block
|
|
199
|
+
maxConcurrentRequests: 2, // Max parallel requests
|
|
200
|
+
cacheBlockCount: 20, // Cache up to 20 blocks
|
|
201
|
+
cacheTimeout: 5 * 60 * 1000, // 5 minutes
|
|
202
|
+
|
|
203
|
+
// Implement server communication
|
|
204
|
+
getRows: async (request) => {
|
|
205
|
+
const response = await fetch('/api/data', {
|
|
206
|
+
method: 'POST',
|
|
207
|
+
body: JSON.stringify(request)
|
|
208
|
+
});
|
|
209
|
+
return await response.json();
|
|
210
|
+
},
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
// Use the grid
|
|
214
|
+
<InfiniteScrollDataGrid
|
|
215
|
+
columns={columns}
|
|
216
|
+
dataSource={dataSource}
|
|
217
|
+
pageSize={100}
|
|
218
|
+
virtualScrollConfig={{ enabled: true }}
|
|
219
|
+
/>
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
**Features:**
|
|
223
|
+
- Handles 100M+ rows efficiently
|
|
224
|
+
- Server-side filtering and sorting
|
|
225
|
+
- Intelligent block caching with LRU eviction
|
|
226
|
+
- Prefetching for smooth scrolling
|
|
227
|
+
- Configurable concurrent requests
|
|
228
|
+
- AG Grid-like API
|
|
229
|
+
|
|
230
|
+
**Server API Format:**
|
|
231
|
+
|
|
232
|
+
Request:
|
|
233
|
+
```json
|
|
234
|
+
{
|
|
235
|
+
"startRow": 0,
|
|
236
|
+
"endRow": 100,
|
|
237
|
+
"sortModel": [{ "field": "name", "direction": "asc" }],
|
|
238
|
+
"filterModel": { "age": { "type": "greaterThan", "value": 25 } }
|
|
239
|
+
}
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
Response:
|
|
243
|
+
```json
|
|
244
|
+
{
|
|
245
|
+
"rows": [...],
|
|
246
|
+
"totalRows": 100000000,
|
|
247
|
+
"lastRow": undefined
|
|
248
|
+
}
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
**See also:**
|
|
252
|
+
- [INFINITE_SCROLLING_INDEX.md](./INFINITE_SCROLLING_INDEX.md) - Documentation index
|
|
253
|
+
- [INFINITE_SCROLLING_FEATURE.md](./INFINITE_SCROLLING_FEATURE.md) - Complete guide
|
|
254
|
+
- [INFINITE_SCROLLING_QUICK_REF.md](./INFINITE_SCROLLING_QUICK_REF.md) - Quick reference
|