Skip to content

Commit 86220c0

Browse files
Copilothotlong
andcommitted
Update documentation for batch editing and multi-row save features
Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
1 parent d47aaf4 commit 86220c0

2 files changed

Lines changed: 103 additions & 0 deletions

File tree

content/docs/plugins/plugin-grid.mdx

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,52 @@ function handleCellChange(rowIndex, columnKey, newValue, row) {
263263
}
264264
```
265265

266+
### Batch Editing & Multi-Row Save
267+
268+
Edit multiple cells across multiple rows and save them individually or all at once:
269+
270+
```json
271+
{
272+
"type": "object-grid",
273+
"objectName": "products",
274+
"columns": [
275+
{ "header": "SKU", "accessorKey": "sku", "editable": false },
276+
{ "header": "Name", "accessorKey": "name" },
277+
{ "header": "Price", "accessorKey": "price" }
278+
],
279+
"editable": true,
280+
"rowActions": true,
281+
"onRowSave": "handleRowSave",
282+
"onBatchSave": "handleBatchSave"
283+
}
284+
```
285+
286+
**Features:**
287+
- **Pending changes tracking**: Edit multiple cells across rows before saving
288+
- **Visual indicators**: Modified rows highlighted in amber, modified cells in bold
289+
- **Row-level save/cancel**: Individual row save and cancel buttons
290+
- **Batch operations**: Save All and Cancel All buttons for bulk actions
291+
- **Flexible callbacks**: `onRowSave` for single row, `onBatchSave` for multiple rows
292+
293+
**Example Handlers:**
294+
```javascript
295+
function handleRowSave(rowIndex, changes, row) {
296+
console.log('Saving row:', rowIndex, changes);
297+
// Save single row to backend
298+
await dataSource.update(row.id, changes);
299+
}
300+
301+
function handleBatchSave(allChanges) {
302+
console.log('Batch saving:', allChanges.length, 'rows');
303+
// Save all changes at once
304+
await Promise.all(
305+
allChanges.map(({ row, changes }) =>
306+
dataSource.update(row.id, changes)
307+
)
308+
);
309+
}
310+
```
311+
266312
## TypeScript Support
267313

268314
```plaintext

packages/plugin-grid/README.md

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,63 @@ const schema = {
284284
- Spreadsheet-like editing experience
285285
- Real-time updates with backend synchronization
286286

287+
### Batch Editing & Multi-Row Save
288+
289+
Edit multiple cells across multiple rows and save them individually or all at once:
290+
291+
```typescript
292+
const schema = {
293+
type: 'object-grid',
294+
objectName: 'products',
295+
columns: [
296+
{ header: 'SKU', accessorKey: 'sku', editable: false },
297+
{ header: 'Name', accessorKey: 'name' },
298+
{ header: 'Price', accessorKey: 'price' },
299+
{ header: 'Stock', accessorKey: 'stock' }
300+
],
301+
editable: true,
302+
rowActions: true, // Show row-level save/cancel buttons
303+
onRowSave: async (rowIndex, changes, row) => {
304+
// Save a single row
305+
console.log('Saving row:', rowIndex, changes);
306+
await dataSource.update(row.id, changes);
307+
},
308+
onBatchSave: async (allChanges) => {
309+
// Save all modified rows at once
310+
console.log('Batch saving:', allChanges);
311+
await Promise.all(
312+
allChanges.map(({ row, changes }) =>
313+
dataSource.update(row.id, changes)
314+
)
315+
);
316+
}
317+
};
318+
```
319+
320+
**Batch Editing Features:**
321+
- **Pending changes tracking**: Edit multiple cells across multiple rows before saving
322+
- **Visual indicators**:
323+
- Modified rows are highlighted with amber background
324+
- Modified cells are shown in bold with amber text
325+
- Toolbar shows count of modified rows
326+
- **Row-level actions**: Save or cancel changes for individual rows
327+
- **Batch operations**:
328+
- "Save All" button to save all modified rows at once
329+
- "Cancel All" button to discard all pending changes
330+
- **Flexible callbacks**:
331+
- `onRowSave`: Called when saving a single row
332+
- `onBatchSave`: Called when saving multiple rows at once
333+
- `onCellChange`: Still called for immediate cell updates (legacy support)
334+
335+
**Example Workflow:**
336+
1. User edits multiple cells across different rows
337+
2. Modified rows are visually highlighted
338+
3. Toolbar shows "X rows modified" with Save All/Cancel All buttons
339+
4. User can:
340+
- Save individual rows using row-level save button
341+
- Save all changes at once using "Save All" button
342+
- Cancel individual row changes or all changes
343+
287344
## TypeScript Support
288345

289346
```typescript

0 commit comments

Comments
 (0)