@gp-grid/core 0.7.2
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 +203 -0
- package/README.md +440 -0
- package/dist/index.d.ts +2067 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +5203 -0
- package/dist/index.js.map +1 -0
- package/package.json +55 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
|
203
|
+
|
package/README.md
ADDED
|
@@ -0,0 +1,440 @@
|
|
|
1
|
+
# gp-grid-core 🏁 🏎️
|
|
2
|
+
|
|
3
|
+
<div align="center">
|
|
4
|
+
<a href="https://www.gp-grid.io">
|
|
5
|
+
<picture>
|
|
6
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/GioPat/gp-grid-docs/refs/heads/master/public/logo-light.svg"/>
|
|
7
|
+
<source media="(prefers-color-scheme: light)" srcset="https://raw.githubusercontent.com/GioPat/gp-grid-docs/refs/heads/master/public/logo-dark.svg"/>
|
|
8
|
+
<img width="50%" alt="AG Grid Logo" src="https://raw.githubusercontent.com/GioPat/gp-grid-docs/refs/heads/master/public/logo-dark.svg"/>
|
|
9
|
+
</picture>
|
|
10
|
+
</a>
|
|
11
|
+
<div align="center">
|
|
12
|
+
Logo by <a href="https://github.com/camillo18tre">camillo18tre ❤️</a>
|
|
13
|
+
<h4><a href="https://www.gp-grid.io/">🎮 Demo</a> • <a href="https://www.gp-grid.io/docs">📖 Documentation</a>
|
|
14
|
+
</div>
|
|
15
|
+
</div>
|
|
16
|
+
|
|
17
|
+
[](https://deepwiki.com/GioPat/gp-grid)
|
|
18
|
+
|
|
19
|
+
A framework-agnostic TypeScript library for building high-performance data grids with high (millions) number of rows with ease.
|
|
20
|
+
|
|
21
|
+
## Table of Contents
|
|
22
|
+
|
|
23
|
+
- [Philosophy](#philosophy)
|
|
24
|
+
- [Installation](#installation)
|
|
25
|
+
- [Architecture Overview](#architecture-overview)
|
|
26
|
+
- [Data Sources](#data-sources)
|
|
27
|
+
- [Types Reference](#types-reference)
|
|
28
|
+
- [Creating a Framework Adapter](#creating-a-framework-adapter)
|
|
29
|
+
- [API Reference](#api-reference)
|
|
30
|
+
- [Donations](#donations)
|
|
31
|
+
|
|
32
|
+
## Available implementations
|
|
33
|
+
|
|
34
|
+
- [**gp-grid-react**](https://www.npmjs.com/package/gp-grid-react) | Official
|
|
35
|
+
- [**gp-grid-vue**](https://www.npmjs.com/package/gp-grid-vue) | Official
|
|
36
|
+
|
|
37
|
+
## Philosophy
|
|
38
|
+
|
|
39
|
+
**gp-grid-core** is built on three core principles:
|
|
40
|
+
|
|
41
|
+
### 1. Slot-Based Virtual Scrolling
|
|
42
|
+
|
|
43
|
+
Instead of rendering all rows, the grid maintains a pool of reusable "slots" (DOM containers) that are recycled as users scroll. This approach:
|
|
44
|
+
|
|
45
|
+
- Renders only visible rows plus a small overscan buffer
|
|
46
|
+
- Recycles DOM elements instead of creating/destroying them
|
|
47
|
+
- Maintains consistent performance regardless of dataset size
|
|
48
|
+
|
|
49
|
+
### 2. Instruction-Based Architecture
|
|
50
|
+
|
|
51
|
+
The core emits declarative **instructions** (commands) that describe what the UI should do, rather than manipulating the DOM directly. This pattern:
|
|
52
|
+
|
|
53
|
+
- Keeps the core framework-agnostic (works with React, Vue, Svelte, vanilla JS)
|
|
54
|
+
- Enables batched updates for optimal rendering performance
|
|
55
|
+
- Provides a clean separation between logic and presentation
|
|
56
|
+
|
|
57
|
+
### 3. DataSource Abstraction
|
|
58
|
+
|
|
59
|
+
Data fetching is abstracted through a `DataSource` interface, supporting both:
|
|
60
|
+
|
|
61
|
+
- **Client-side**: All data loaded in memory, with local sorting/filtering
|
|
62
|
+
- **Server-side**: Data fetched on-demand from an API with server-side operations
|
|
63
|
+
|
|
64
|
+
## Installation
|
|
65
|
+
|
|
66
|
+
npm/pnpm/yarn
|
|
67
|
+
|
|
68
|
+
```bash
|
|
69
|
+
pnpm add gp-grid-core
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
## Architecture Overview
|
|
73
|
+
|
|
74
|
+
### GridCore
|
|
75
|
+
|
|
76
|
+
The main orchestrator class that manages:
|
|
77
|
+
|
|
78
|
+
- Viewport tracking and scroll synchronization
|
|
79
|
+
- Slot pool lifecycle (create, assign, move, destroy)
|
|
80
|
+
- Data fetching and caching
|
|
81
|
+
- Sort and filter state
|
|
82
|
+
|
|
83
|
+
```typescript
|
|
84
|
+
import { GridCore, createClientDataSource } from "gp-grid-core";
|
|
85
|
+
|
|
86
|
+
const dataSource = createClientDataSource(myData);
|
|
87
|
+
|
|
88
|
+
const grid = new GridCore({
|
|
89
|
+
columns: [
|
|
90
|
+
{ field: "name", cellDataType: "text", width: 150 },
|
|
91
|
+
{ field: "age", cellDataType: "number", width: 80 },
|
|
92
|
+
],
|
|
93
|
+
dataSource,
|
|
94
|
+
rowHeight: 36,
|
|
95
|
+
headerHeight: 40,
|
|
96
|
+
overscan: 3,
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
// Subscribe to instructions
|
|
100
|
+
grid.onBatchInstruction((instructions) => {
|
|
101
|
+
// Handle UI updates based on instructions
|
|
102
|
+
instructions.forEach((instruction) => {
|
|
103
|
+
switch (instruction.type) {
|
|
104
|
+
case "CREATE_SLOT":
|
|
105
|
+
// Create a new row container
|
|
106
|
+
break;
|
|
107
|
+
case "ASSIGN_SLOT":
|
|
108
|
+
// Assign row data to a slot
|
|
109
|
+
break;
|
|
110
|
+
case "MOVE_SLOT":
|
|
111
|
+
// Position slot via translateY
|
|
112
|
+
break;
|
|
113
|
+
// ... handle other instructions
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
// Initialize and start
|
|
119
|
+
await grid.initialize();
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
### Managers
|
|
123
|
+
|
|
124
|
+
GridCore includes specialized managers for complex behaviors:
|
|
125
|
+
|
|
126
|
+
- **SelectionManager**: Handles cell selection, range selection, keyboard navigation
|
|
127
|
+
- **FillManager**: Implements Excel-like fill handle drag operations
|
|
128
|
+
|
|
129
|
+
### Instruction Types
|
|
130
|
+
|
|
131
|
+
The core emits these instruction types:
|
|
132
|
+
|
|
133
|
+
| Instruction | Description |
|
|
134
|
+
| --------------------------------------------- | --------------------------------- |
|
|
135
|
+
| `CREATE_SLOT` | Create a new slot in the DOM pool |
|
|
136
|
+
| `DESTROY_SLOT` | Remove a slot from the pool |
|
|
137
|
+
| `ASSIGN_SLOT` | Assign row data to a slot |
|
|
138
|
+
| `MOVE_SLOT` | Update slot position (translateY) |
|
|
139
|
+
| `SET_ACTIVE_CELL` | Update active cell highlight |
|
|
140
|
+
| `SET_SELECTION_RANGE` | Update selection range |
|
|
141
|
+
| `START_EDIT` / `STOP_EDIT` | Toggle edit mode |
|
|
142
|
+
| `COMMIT_EDIT` | Commit edited value |
|
|
143
|
+
| `UPDATE_HEADER` | Update header with sort state |
|
|
144
|
+
| `DATA_LOADING` / `DATA_LOADED` / `DATA_ERROR` | Data fetch lifecycle |
|
|
145
|
+
|
|
146
|
+
## Data Sources
|
|
147
|
+
|
|
148
|
+
### Client-Side Data Source
|
|
149
|
+
|
|
150
|
+
For datasets that can be loaded entirely in memory. Sorting and filtering are performed client-side.
|
|
151
|
+
|
|
152
|
+
```typescript
|
|
153
|
+
import { createClientDataSource } from "gp-grid-core";
|
|
154
|
+
|
|
155
|
+
interface Person {
|
|
156
|
+
id: number;
|
|
157
|
+
name: string;
|
|
158
|
+
age: number;
|
|
159
|
+
email: string;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
const data: Person[] = [
|
|
163
|
+
{ id: 1, name: "Alice", age: 30, email: "alice@example.com" },
|
|
164
|
+
{ id: 2, name: "Bob", age: 25, email: "bob@example.com" },
|
|
165
|
+
// ... more rows
|
|
166
|
+
];
|
|
167
|
+
|
|
168
|
+
const dataSource = createClientDataSource(data);
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
**With custom field accessor** (for nested properties):
|
|
172
|
+
|
|
173
|
+
```typescript
|
|
174
|
+
const dataSource = createClientDataSource(data, {
|
|
175
|
+
getFieldValue: (row, field) => {
|
|
176
|
+
// Custom logic for accessing nested fields
|
|
177
|
+
if (field === "address.city") {
|
|
178
|
+
return row.address?.city;
|
|
179
|
+
}
|
|
180
|
+
return row[field];
|
|
181
|
+
},
|
|
182
|
+
});
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
### Server-Side Data Source
|
|
186
|
+
|
|
187
|
+
For large datasets that require server-side pagination, sorting, and filtering.
|
|
188
|
+
|
|
189
|
+
```typescript
|
|
190
|
+
import {
|
|
191
|
+
createServerDataSource,
|
|
192
|
+
DataSourceRequest,
|
|
193
|
+
DataSourceResponse,
|
|
194
|
+
} from "gp-grid-core";
|
|
195
|
+
|
|
196
|
+
interface Person {
|
|
197
|
+
id: number;
|
|
198
|
+
name: string;
|
|
199
|
+
age: number;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
const dataSource = createServerDataSource<Person>(
|
|
203
|
+
async (request: DataSourceRequest) => {
|
|
204
|
+
// Build query parameters from request
|
|
205
|
+
const params = new URLSearchParams({
|
|
206
|
+
page: String(request.pagination.pageIndex),
|
|
207
|
+
pageSize: String(request.pagination.pageSize),
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
// Add sort parameters
|
|
211
|
+
if (request.sort && request.sort.length > 0) {
|
|
212
|
+
params.set(
|
|
213
|
+
"sortBy",
|
|
214
|
+
request.sort.map((s) => `${s.colId}:${s.direction}`).join(","),
|
|
215
|
+
);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
// Add filter parameters
|
|
219
|
+
if (request.filter) {
|
|
220
|
+
Object.entries(request.filter).forEach(([field, value]) => {
|
|
221
|
+
params.set(`filter_${field}`, value);
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
// Fetch from your API
|
|
226
|
+
const response = await fetch(`/api/people?${params}`);
|
|
227
|
+
const data = await response.json();
|
|
228
|
+
|
|
229
|
+
return {
|
|
230
|
+
rows: data.items,
|
|
231
|
+
totalRows: data.totalCount,
|
|
232
|
+
};
|
|
233
|
+
},
|
|
234
|
+
);
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
### DataSource Interface
|
|
238
|
+
|
|
239
|
+
Both data source types implement this interface:
|
|
240
|
+
|
|
241
|
+
```typescript
|
|
242
|
+
interface DataSource<TData = Row> {
|
|
243
|
+
fetch(request: DataSourceRequest): Promise<DataSourceResponse<TData>>;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
interface DataSourceRequest {
|
|
247
|
+
pagination: {
|
|
248
|
+
pageIndex: number;
|
|
249
|
+
pageSize: number;
|
|
250
|
+
};
|
|
251
|
+
sort?: SortModel[];
|
|
252
|
+
filter?: FilterModel;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
interface DataSourceResponse<TData> {
|
|
256
|
+
rows: TData[];
|
|
257
|
+
totalRows: number;
|
|
258
|
+
}
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
## Types Reference
|
|
262
|
+
|
|
263
|
+
### ColumnDefinition
|
|
264
|
+
|
|
265
|
+
```typescript
|
|
266
|
+
interface ColumnDefinition {
|
|
267
|
+
field: string; // Property path in row data
|
|
268
|
+
colId?: string; // Unique column ID (defaults to field)
|
|
269
|
+
cellDataType: CellDataType; // "text" | "number" | "boolean" | "date" | "object"
|
|
270
|
+
width: number; // Column width in pixels
|
|
271
|
+
headerName?: string; // Display name (defaults to field)
|
|
272
|
+
editable?: boolean; // Enable cell editing
|
|
273
|
+
cellRenderer?: string; // Custom renderer key
|
|
274
|
+
editRenderer?: string; // Custom edit renderer key
|
|
275
|
+
headerRenderer?: string; // Custom header renderer key
|
|
276
|
+
}
|
|
277
|
+
```
|
|
278
|
+
|
|
279
|
+
### Renderer Params
|
|
280
|
+
|
|
281
|
+
When building framework adapters, these params are passed to custom renderers:
|
|
282
|
+
|
|
283
|
+
```typescript
|
|
284
|
+
interface CellRendererParams {
|
|
285
|
+
value: CellValue;
|
|
286
|
+
rowData: Row;
|
|
287
|
+
column: ColumnDefinition;
|
|
288
|
+
rowIndex: number;
|
|
289
|
+
colIndex: number;
|
|
290
|
+
isActive: boolean;
|
|
291
|
+
isSelected: boolean;
|
|
292
|
+
isEditing: boolean;
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
interface EditRendererParams extends CellRendererParams {
|
|
296
|
+
initialValue: CellValue;
|
|
297
|
+
onValueChange: (newValue: CellValue) => void;
|
|
298
|
+
onCommit: () => void;
|
|
299
|
+
onCancel: () => void;
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
interface HeaderRendererParams {
|
|
303
|
+
column: ColumnDefinition;
|
|
304
|
+
colIndex: number;
|
|
305
|
+
sortDirection?: SortDirection;
|
|
306
|
+
sortIndex?: number;
|
|
307
|
+
onSort: (direction: SortDirection | null, addToExisting: boolean) => void;
|
|
308
|
+
}
|
|
309
|
+
```
|
|
310
|
+
|
|
311
|
+
## Creating a Framework Adapter
|
|
312
|
+
|
|
313
|
+
To integrate gp-grid-core with any UI framework:
|
|
314
|
+
|
|
315
|
+
1. **Subscribe to instructions** using `onBatchInstruction()`
|
|
316
|
+
2. **Maintain UI state** by processing instructions
|
|
317
|
+
3. **Render slots** based on the slot pool state
|
|
318
|
+
4. **Forward user interactions** back to GridCore
|
|
319
|
+
|
|
320
|
+
### Example: Minimal Adapter Pattern
|
|
321
|
+
|
|
322
|
+
```typescript
|
|
323
|
+
import { GridCore, GridInstruction } from "gp-grid-core";
|
|
324
|
+
|
|
325
|
+
class MyGridAdapter {
|
|
326
|
+
private core: GridCore;
|
|
327
|
+
private slots: Map<string, SlotUIElement> = new Map();
|
|
328
|
+
|
|
329
|
+
constructor(options: GridCoreOptions) {
|
|
330
|
+
this.core = new GridCore(options);
|
|
331
|
+
|
|
332
|
+
// Process instructions to update UI
|
|
333
|
+
this.core.onBatchInstruction((instructions) => {
|
|
334
|
+
this.processInstructions(instructions);
|
|
335
|
+
this.render();
|
|
336
|
+
});
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
private processInstructions(instructions: GridInstruction[]) {
|
|
340
|
+
for (const instr of instructions) {
|
|
341
|
+
switch (instr.type) {
|
|
342
|
+
case "CREATE_SLOT":
|
|
343
|
+
this.slots.set(instr.slotId, this.createSlotElement());
|
|
344
|
+
break;
|
|
345
|
+
case "DESTROY_SLOT":
|
|
346
|
+
this.slots.delete(instr.slotId);
|
|
347
|
+
break;
|
|
348
|
+
case "ASSIGN_SLOT":
|
|
349
|
+
const slot = this.slots.get(instr.slotId);
|
|
350
|
+
if (slot) {
|
|
351
|
+
slot.rowIndex = instr.rowIndex;
|
|
352
|
+
slot.rowData = instr.rowData;
|
|
353
|
+
}
|
|
354
|
+
break;
|
|
355
|
+
case "MOVE_SLOT":
|
|
356
|
+
const moveSlot = this.slots.get(instr.slotId);
|
|
357
|
+
if (moveSlot) {
|
|
358
|
+
moveSlot.translateY = instr.translateY;
|
|
359
|
+
}
|
|
360
|
+
break;
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
// Handle scroll events
|
|
366
|
+
onScroll(
|
|
367
|
+
scrollTop: number,
|
|
368
|
+
scrollLeft: number,
|
|
369
|
+
width: number,
|
|
370
|
+
height: number,
|
|
371
|
+
) {
|
|
372
|
+
this.core.setViewport(scrollTop, scrollLeft, width, height);
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
// Handle cell click
|
|
376
|
+
onCellClick(
|
|
377
|
+
row: number,
|
|
378
|
+
col: number,
|
|
379
|
+
modifiers: { shift: boolean; ctrl: boolean },
|
|
380
|
+
) {
|
|
381
|
+
this.core.selection.startSelection({ row, col }, modifiers);
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
async initialize() {
|
|
385
|
+
await this.core.initialize();
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
```
|
|
389
|
+
|
|
390
|
+
## API Reference
|
|
391
|
+
|
|
392
|
+
### GridCore Methods
|
|
393
|
+
|
|
394
|
+
| Method | Description |
|
|
395
|
+
| --------------------------------------------------- | ------------------------------------- |
|
|
396
|
+
| `initialize()` | Initialize grid and load initial data |
|
|
397
|
+
| `setViewport(scrollTop, scrollLeft, width, height)` | Update viewport on scroll/resize |
|
|
398
|
+
| `setSort(colId, direction, addToExisting)` | Set column sort |
|
|
399
|
+
| `setFilter(colId, value)` | Set column filter |
|
|
400
|
+
| `startEdit(row, col)` | Start editing a cell |
|
|
401
|
+
| `commitEdit()` | Commit current edit |
|
|
402
|
+
| `cancelEdit()` | Cancel current edit |
|
|
403
|
+
| `refresh()` | Refetch data from source |
|
|
404
|
+
| `getRowCount()` | Get total row count |
|
|
405
|
+
| `getRowData(rowIndex)` | Get data for a specific row |
|
|
406
|
+
|
|
407
|
+
### GridCore Properties
|
|
408
|
+
|
|
409
|
+
| Property | Description |
|
|
410
|
+
| ----------- | ------------------------- |
|
|
411
|
+
| `selection` | SelectionManager instance |
|
|
412
|
+
| `fill` | FillManager instance |
|
|
413
|
+
|
|
414
|
+
## Donations
|
|
415
|
+
|
|
416
|
+
Keeping this library requires effort and passion, I'm a full time engineer employed on other project and I'm trying my best to keep this work free! For all the features.
|
|
417
|
+
|
|
418
|
+
If you think this project helped you achieve your goals, it's hopefully worth a beer! 🍻
|
|
419
|
+
|
|
420
|
+
<div align="center">
|
|
421
|
+
|
|
422
|
+
### Paypal
|
|
423
|
+
|
|
424
|
+
[](https://www.paypal.com/donate/?hosted_button_id=XCNMG6BR4ZMLY)
|
|
425
|
+
|
|
426
|
+
[https://www.paypal.com/donate/?hosted_button_id=XCNMG6BR4ZMLY](https://www.paypal.com/donate/?hosted_button_id=XCNMG6BR4ZMLY)
|
|
427
|
+
|
|
428
|
+
### Bitcoin
|
|
429
|
+
|
|
430
|
+
[](bitcoin:bc1qcukwmzver59eyqq442xyzscmxavqjt568kkc9m)
|
|
431
|
+
|
|
432
|
+
bitcoin:bc1qcukwmzver59eyqq442xyzscmxavqjt568kkc9m
|
|
433
|
+
|
|
434
|
+
### Lightning Network
|
|
435
|
+
|
|
436
|
+
[](lnurl1dp68gurn8ghj7ampd3kx2ar0veekzar0wd5xjtnrdakj7tnhv4kxctttdehhwm30d3h82unvwqhhx6rpvanhjetdvfjhyvf4xs0xu5p7)
|
|
437
|
+
|
|
438
|
+
lnurl1dp68gurn8ghj7ampd3kx2ar0veekzar0wd5xjtnrdakj7tnhv4kxctttdehhwm30d3h82unvwqhhx6rpvanhjetdvfjhyvf4xs0xu5p7
|
|
439
|
+
|
|
440
|
+
</div>
|