@alaarab/ogrid-mcp 2.4.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 +68 -0
- package/bundled-docs/api/README.md +94 -0
- package/bundled-docs/api/column-def.mdx +379 -0
- package/bundled-docs/api/components-column-chooser.mdx +310 -0
- package/bundled-docs/api/components-column-header-filter.mdx +363 -0
- package/bundled-docs/api/components-datagrid-table.mdx +316 -0
- package/bundled-docs/api/components-pagination-controls.mdx +344 -0
- package/bundled-docs/api/components-sidebar.mdx +427 -0
- package/bundled-docs/api/components-status-bar.mdx +309 -0
- package/bundled-docs/api/grid-api.mdx +299 -0
- package/bundled-docs/api/js-api.mdx +198 -0
- package/bundled-docs/api/ogrid-props.mdx +244 -0
- package/bundled-docs/api/types.mdx +640 -0
- package/bundled-docs/features/cell-references.mdx +225 -0
- package/bundled-docs/features/column-chooser.mdx +279 -0
- package/bundled-docs/features/column-groups.mdx +290 -0
- package/bundled-docs/features/column-pinning.mdx +282 -0
- package/bundled-docs/features/column-reordering.mdx +359 -0
- package/bundled-docs/features/column-types.mdx +181 -0
- package/bundled-docs/features/context-menu.mdx +216 -0
- package/bundled-docs/features/csv-export.mdx +227 -0
- package/bundled-docs/features/editing.mdx +377 -0
- package/bundled-docs/features/filtering.mdx +330 -0
- package/bundled-docs/features/formulas.mdx +381 -0
- package/bundled-docs/features/grid-api.mdx +311 -0
- package/bundled-docs/features/keyboard-navigation.mdx +236 -0
- package/bundled-docs/features/pagination.mdx +245 -0
- package/bundled-docs/features/performance.mdx +433 -0
- package/bundled-docs/features/row-selection.mdx +256 -0
- package/bundled-docs/features/server-side-data.mdx +291 -0
- package/bundled-docs/features/sidebar.mdx +234 -0
- package/bundled-docs/features/sorting.mdx +241 -0
- package/bundled-docs/features/spreadsheet-selection.mdx +201 -0
- package/bundled-docs/features/status-bar.mdx +205 -0
- package/bundled-docs/features/toolbar.mdx +284 -0
- package/bundled-docs/features/virtual-scrolling.mdx +624 -0
- package/bundled-docs/getting-started/installation.mdx +216 -0
- package/bundled-docs/getting-started/overview.mdx +151 -0
- package/bundled-docs/getting-started/quick-start.mdx +425 -0
- package/bundled-docs/getting-started/vanilla-js.mdx +191 -0
- package/bundled-docs/guides/accessibility.mdx +550 -0
- package/bundled-docs/guides/controlled-vs-uncontrolled.mdx +153 -0
- package/bundled-docs/guides/custom-cell-editors.mdx +201 -0
- package/bundled-docs/guides/framework-showcase.mdx +200 -0
- package/bundled-docs/guides/mcp-live-testing.mdx +291 -0
- package/bundled-docs/guides/mcp.mdx +172 -0
- package/bundled-docs/guides/migration-from-ag-grid.mdx +223 -0
- package/bundled-docs/guides/theming.mdx +211 -0
- package/dist/esm/bridge-client.d.ts +87 -0
- package/dist/esm/bridge-client.js +162 -0
- package/dist/esm/index.js +1060 -0
- package/package.json +43 -0
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
---
|
|
2
|
+
sidebar_position: 13
|
|
3
|
+
title: Context Menu
|
|
4
|
+
description: Right-click cell menu with clipboard, undo/redo, and export actions
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
# Context Menu
|
|
9
|
+
|
|
10
|
+
Right-click any cell to open a context menu with clipboard operations, undo/redo, and selection actions. Keyboard shortcut labels are displayed alongside each item.
|
|
11
|
+
|
|
12
|
+
## Live Demo
|
|
13
|
+
|
|
14
|
+
<ContextMenuDemo />
|
|
15
|
+
|
|
16
|
+
:::tip Try it in your framework
|
|
17
|
+
The demo above uses Radix UI for styling. To see this feature with your framework's design system (Fluent UI, Material UI, Vuetify, PrimeNG, etc.), click **"Open in online demo"** below the demo.
|
|
18
|
+
:::
|
|
19
|
+
|
|
20
|
+
## Quick Example
|
|
21
|
+
|
|
22
|
+
<Tabs groupId="framework">
|
|
23
|
+
<TabItem value="react" label="React" default>
|
|
24
|
+
|
|
25
|
+
```tsx
|
|
26
|
+
|
|
27
|
+
function App() {
|
|
28
|
+
const undoRedo = useUndoRedo();
|
|
29
|
+
|
|
30
|
+
return (
|
|
31
|
+
<OGrid
|
|
32
|
+
columns={columns}
|
|
33
|
+
data={data}
|
|
34
|
+
getRowId={(r) => r.id}
|
|
35
|
+
editable
|
|
36
|
+
onCellValueChanged={(e) => {
|
|
37
|
+
undoRedo.pushChange(e);
|
|
38
|
+
// persist change...
|
|
39
|
+
}}
|
|
40
|
+
onUndo={undoRedo.undo}
|
|
41
|
+
onRedo={undoRedo.redo}
|
|
42
|
+
canUndo={undoRedo.canUndo}
|
|
43
|
+
canRedo={undoRedo.canRedo}
|
|
44
|
+
/>
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
:::tip Switching UI libraries
|
|
50
|
+
The `OGrid` component has the same props across all React UI packages. To switch, just change the import:
|
|
51
|
+
|
|
52
|
+
- **Radix** (lightweight, default): `from '@alaarab/ogrid-react-radix'`
|
|
53
|
+
- **Fluent UI** (Microsoft 365 / SPFx): `from '@alaarab/ogrid-react-fluent'` — wrap in `<FluentProvider>`
|
|
54
|
+
- **Material UI** (MUI v7): `from '@alaarab/ogrid-react-material'` — wrap in `<ThemeProvider>`
|
|
55
|
+
:::
|
|
56
|
+
|
|
57
|
+
</TabItem>
|
|
58
|
+
<TabItem value="angular" label="Angular">
|
|
59
|
+
|
|
60
|
+
```typescript
|
|
61
|
+
|
|
62
|
+
@Component({
|
|
63
|
+
standalone: true,
|
|
64
|
+
imports: [OGridComponent],
|
|
65
|
+
template: `<ogrid [props]="gridProps" />`
|
|
66
|
+
})
|
|
67
|
+
export class GridComponent {
|
|
68
|
+
gridProps = {
|
|
69
|
+
columns: [
|
|
70
|
+
{ columnId: 'name', name: 'Name', editable: true },
|
|
71
|
+
{ columnId: 'department', name: 'Department' },
|
|
72
|
+
{
|
|
73
|
+
columnId: 'salary', name: 'Salary', type: 'numeric', editable: true,
|
|
74
|
+
valueFormatter: (v: unknown) => `$${Number(v).toLocaleString()}`,
|
|
75
|
+
},
|
|
76
|
+
] as IColumnDef<Person>[],
|
|
77
|
+
data: people,
|
|
78
|
+
getRowId: (item: Person) => item.id,
|
|
79
|
+
editable: true,
|
|
80
|
+
contextMenu: true,
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
:::tip Switching UI libraries
|
|
86
|
+
Same component API across Angular packages. To switch, just change the import:
|
|
87
|
+
|
|
88
|
+
- **Radix (CDK)**: `from '@alaarab/ogrid-angular-radix'` *(default, lightweight)*
|
|
89
|
+
- **Angular Material**: `from '@alaarab/ogrid-angular-material'`
|
|
90
|
+
- **PrimeNG**: `from '@alaarab/ogrid-angular-primeng'`
|
|
91
|
+
|
|
92
|
+
All components are standalone — no NgModule required.
|
|
93
|
+
:::
|
|
94
|
+
|
|
95
|
+
</TabItem>
|
|
96
|
+
<TabItem value="vue" label="Vue">
|
|
97
|
+
|
|
98
|
+
```vue
|
|
99
|
+
<script setup lang="ts">
|
|
100
|
+
|
|
101
|
+
const columns: IColumnDef<Person>[] = [
|
|
102
|
+
{ columnId: 'name', name: 'Name', editable: true },
|
|
103
|
+
{ columnId: 'department', name: 'Department' },
|
|
104
|
+
{
|
|
105
|
+
columnId: 'salary', name: 'Salary', type: 'numeric', editable: true,
|
|
106
|
+
valueFormatter: (v) => `$${Number(v).toLocaleString()}`,
|
|
107
|
+
},
|
|
108
|
+
];
|
|
109
|
+
|
|
110
|
+
const gridProps = {
|
|
111
|
+
columns,
|
|
112
|
+
data: people,
|
|
113
|
+
getRowId: (item) => item.id,
|
|
114
|
+
editable: true,
|
|
115
|
+
contextMenu: true,
|
|
116
|
+
};
|
|
117
|
+
</script>
|
|
118
|
+
|
|
119
|
+
<template>
|
|
120
|
+
<OGrid :gridProps="gridProps" />
|
|
121
|
+
</template>
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
:::tip Switching UI libraries
|
|
125
|
+
Same component API across Vue packages. To switch, just change the import:
|
|
126
|
+
|
|
127
|
+
- **Radix (Headless UI)**: `from '@alaarab/ogrid-vue-radix'` *(default, lightweight)*
|
|
128
|
+
- **Vuetify**: `from '@alaarab/ogrid-vue-vuetify'` — wrap in `<v-app>` for theming
|
|
129
|
+
- **PrimeVue**: `from '@alaarab/ogrid-vue-primevue'`
|
|
130
|
+
:::
|
|
131
|
+
|
|
132
|
+
</TabItem>
|
|
133
|
+
<TabItem value="js" label="Vanilla JS">
|
|
134
|
+
|
|
135
|
+
```js
|
|
136
|
+
|
|
137
|
+
const grid = new OGrid(document.getElementById('grid'), {
|
|
138
|
+
columns: columns,
|
|
139
|
+
data: data,
|
|
140
|
+
getRowId: (r) => r.id,
|
|
141
|
+
editable: true,
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
// Right-click any cell to see the context menu
|
|
145
|
+
// Undo/redo is handled automatically by the JS package
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
</TabItem>
|
|
149
|
+
</Tabs>
|
|
150
|
+
|
|
151
|
+
Right-click a cell to see the context menu with all available actions.
|
|
152
|
+
|
|
153
|
+
## How It Works
|
|
154
|
+
|
|
155
|
+
The context menu is built in and requires no additional configuration. It appears when the user right-clicks on a data cell. Right-clicking on headers, empty space, or outside the grid does not open the menu.
|
|
156
|
+
|
|
157
|
+
### Built-in Menu Items
|
|
158
|
+
|
|
159
|
+
| Item | Shortcut | Description |
|
|
160
|
+
|---|---|---|
|
|
161
|
+
| Undo | Ctrl+Z | Undo the last cell edit |
|
|
162
|
+
| Redo | Ctrl+Y | Redo the last undone edit |
|
|
163
|
+
| Copy | Ctrl+C | Copy selected cells to clipboard |
|
|
164
|
+
| Cut | Ctrl+X | Cut selected cells to clipboard |
|
|
165
|
+
| Paste | Ctrl+V | Paste clipboard contents into selected cells |
|
|
166
|
+
| Select all | Ctrl+A | Select all **cells** in the grid (cell selection, not row selection) |
|
|
167
|
+
|
|
168
|
+
On macOS, "Ctrl" is automatically displayed as the Command symbol.
|
|
169
|
+
|
|
170
|
+
:::info Cell Selection vs Row Selection
|
|
171
|
+
The "Select all" menu item selects all **cells** for copy/paste/fill operations. This is different from row selection, where the header checkbox selects all **rows** for bulk operations. See [Row Selection](./row-selection) for details on row-level selection.
|
|
172
|
+
:::
|
|
173
|
+
|
|
174
|
+
### Undo/Redo State
|
|
175
|
+
|
|
176
|
+
The Undo and Redo items reflect their availability through the `canUndo` and `canRedo` props. When `canUndo` is `false`, the Undo item appears disabled (grayed out). Same for Redo.
|
|
177
|
+
|
|
178
|
+
```tsx
|
|
179
|
+
<OGrid
|
|
180
|
+
// ...
|
|
181
|
+
onUndo={undoRedo.undo}
|
|
182
|
+
onRedo={undoRedo.redo}
|
|
183
|
+
canUndo={undoRedo.canUndo}
|
|
184
|
+
canRedo={undoRedo.canRedo}
|
|
185
|
+
/>
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
If `onUndo` and `onRedo` are not provided, the undo/redo items still appear but do nothing.
|
|
189
|
+
|
|
190
|
+
### Cell-Only Activation
|
|
191
|
+
|
|
192
|
+
The context menu only opens on cell right-clicks. This is intentional:
|
|
193
|
+
|
|
194
|
+
- **Header right-click**: default browser context menu (no grid menu).
|
|
195
|
+
- **Empty space right-click**: default browser context menu.
|
|
196
|
+
- **Cell right-click**: grid context menu with actions scoped to the current selection.
|
|
197
|
+
|
|
198
|
+
### Copy/Cut Disabled State
|
|
199
|
+
|
|
200
|
+
The Copy and Cut items are disabled when no cells are selected. Once the user clicks a cell or selects a range, these items become active.
|
|
201
|
+
|
|
202
|
+
## Props Reference
|
|
203
|
+
|
|
204
|
+
| Type | Field | Description |
|
|
205
|
+
|---|---|---|
|
|
206
|
+
| `IOGridProps<T>` | `onUndo` | Callback invoked when Undo is clicked |
|
|
207
|
+
| `IOGridProps<T>` | `onRedo` | Callback invoked when Redo is clicked |
|
|
208
|
+
| `IOGridProps<T>` | `canUndo` | `boolean` -- disables Undo item when `false` |
|
|
209
|
+
| `IOGridProps<T>` | `canRedo` | `boolean` -- disables Redo item when `false` |
|
|
210
|
+
| `IOGridProps<T>` | `cellSelection` | `boolean` -- context menu requires cell selection (default `true`) |
|
|
211
|
+
|
|
212
|
+
## Related
|
|
213
|
+
|
|
214
|
+
- [Keyboard Navigation](./keyboard-navigation) -- same shortcuts work via keyboard
|
|
215
|
+
- [CSV Export](./csv-export) -- export is also available via the `exportToCsv` utility
|
|
216
|
+
- [Grid API](./grid-api) -- programmatic access to selection and data
|
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
---
|
|
2
|
+
sidebar_position: 15
|
|
3
|
+
title: CSV Export
|
|
4
|
+
description: Export grid data to a CSV file with one function call
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
# CSV Export
|
|
9
|
+
|
|
10
|
+
Export grid data to a downloadable CSV file using the `exportToCsv` utility from core. It respects column visibility and applies `valueFormatter` so the exported values match what the user sees.
|
|
11
|
+
|
|
12
|
+
## Live Demo
|
|
13
|
+
|
|
14
|
+
<CsvExportDemo />
|
|
15
|
+
|
|
16
|
+
:::tip Try it in your framework
|
|
17
|
+
The demo above uses Radix UI for styling. To see this feature with your framework's design system (Fluent UI, Material UI, Vuetify, PrimeNG, etc.), click **"Open in online demo"** below the demo.
|
|
18
|
+
:::
|
|
19
|
+
|
|
20
|
+
## Quick Example
|
|
21
|
+
|
|
22
|
+
<Tabs groupId="framework">
|
|
23
|
+
<TabItem value="react" label="React" default>
|
|
24
|
+
|
|
25
|
+
```tsx
|
|
26
|
+
|
|
27
|
+
function ExportButton({ data, columns }: { data: Row[]; columns: IColumnDef<Row>[] }) {
|
|
28
|
+
const handleExport = () => {
|
|
29
|
+
exportToCsv(
|
|
30
|
+
data,
|
|
31
|
+
columns.map((col) => ({ columnId: col.columnId, name: col.name })),
|
|
32
|
+
(item, columnId) => {
|
|
33
|
+
const col = columns.find((c) => c.columnId === columnId);
|
|
34
|
+
if (!col) return '';
|
|
35
|
+
const value = col.valueGetter ? col.valueGetter(item) : (item as Record<string, unknown>)[columnId];
|
|
36
|
+
return col.valueFormatter ? col.valueFormatter(value, item) : String(value ?? '');
|
|
37
|
+
},
|
|
38
|
+
'my-data.csv'
|
|
39
|
+
);
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
return <button onClick={handleExport}>Export to CSV</button>;
|
|
43
|
+
}
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
:::tip Switching UI libraries
|
|
47
|
+
The `OGrid` component has the same props across all React UI packages. To switch, just change the import:
|
|
48
|
+
|
|
49
|
+
- **Radix** (lightweight, default): `from '@alaarab/ogrid-react-radix'`
|
|
50
|
+
- **Fluent UI** (Microsoft 365 / SPFx): `from '@alaarab/ogrid-react-fluent'` — wrap in `<FluentProvider>`
|
|
51
|
+
- **Material UI** (MUI v7): `from '@alaarab/ogrid-react-material'` — wrap in `<ThemeProvider>`
|
|
52
|
+
:::
|
|
53
|
+
|
|
54
|
+
</TabItem>
|
|
55
|
+
<TabItem value="angular" label="Angular">
|
|
56
|
+
|
|
57
|
+
```typescript
|
|
58
|
+
|
|
59
|
+
@Component({
|
|
60
|
+
standalone: true,
|
|
61
|
+
template: `<button (click)="handleExport()">Export to CSV</button>`
|
|
62
|
+
})
|
|
63
|
+
export class ExportButtonComponent {
|
|
64
|
+
data: Row[] = [];
|
|
65
|
+
columns: IColumnDef<Row>[] = [];
|
|
66
|
+
|
|
67
|
+
handleExport() {
|
|
68
|
+
exportToCsv(
|
|
69
|
+
this.data,
|
|
70
|
+
this.columns.map((col) => ({ columnId: col.columnId, name: col.name })),
|
|
71
|
+
(item: Row, columnId: string) => {
|
|
72
|
+
const col = this.columns.find((c) => c.columnId === columnId);
|
|
73
|
+
if (!col) return '';
|
|
74
|
+
const value = col.valueGetter ? col.valueGetter(item) : (item as Record<string, unknown>)[columnId];
|
|
75
|
+
return col.valueFormatter ? col.valueFormatter(value as unknown, item) : String(value ?? '');
|
|
76
|
+
},
|
|
77
|
+
'my-data.csv'
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
:::tip Switching UI libraries
|
|
84
|
+
Same component API across Angular packages. To switch, just change the import:
|
|
85
|
+
|
|
86
|
+
- **Radix (CDK)**: `from '@alaarab/ogrid-angular-radix'` *(default, lightweight)*
|
|
87
|
+
- **Angular Material**: `from '@alaarab/ogrid-angular-material'`
|
|
88
|
+
- **PrimeNG**: `from '@alaarab/ogrid-angular-primeng'`
|
|
89
|
+
|
|
90
|
+
All components are standalone — no NgModule required.
|
|
91
|
+
:::
|
|
92
|
+
|
|
93
|
+
</TabItem>
|
|
94
|
+
<TabItem value="vue" label="Vue">
|
|
95
|
+
|
|
96
|
+
```vue
|
|
97
|
+
<script setup lang="ts">
|
|
98
|
+
|
|
99
|
+
const props = defineProps<{ data: Row[]; columns: IColumnDef<Row>[] }>();
|
|
100
|
+
|
|
101
|
+
function handleExport() {
|
|
102
|
+
exportToCsv(
|
|
103
|
+
props.data,
|
|
104
|
+
props.columns.map((col) => ({ columnId: col.columnId, name: col.name })),
|
|
105
|
+
(item, columnId) => {
|
|
106
|
+
const col = props.columns.find((c) => c.columnId === columnId);
|
|
107
|
+
if (!col) return '';
|
|
108
|
+
const value = col.valueGetter ? col.valueGetter(item) : (item as Record<string, unknown>)[columnId];
|
|
109
|
+
return col.valueFormatter ? col.valueFormatter(value, item) : String(value ?? '');
|
|
110
|
+
},
|
|
111
|
+
'my-data.csv'
|
|
112
|
+
);
|
|
113
|
+
}
|
|
114
|
+
</script>
|
|
115
|
+
|
|
116
|
+
<template>
|
|
117
|
+
<button @click="handleExport">Export to CSV</button>
|
|
118
|
+
</template>
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
:::tip Switching UI libraries
|
|
122
|
+
Same component API across Vue packages. To switch, just change the import:
|
|
123
|
+
|
|
124
|
+
- **Radix (Headless UI)**: `from '@alaarab/ogrid-vue-radix'` *(default, lightweight)*
|
|
125
|
+
- **Vuetify**: `from '@alaarab/ogrid-vue-vuetify'` — wrap in `<v-app>` for theming
|
|
126
|
+
- **PrimeVue**: `from '@alaarab/ogrid-vue-primevue'`
|
|
127
|
+
:::
|
|
128
|
+
|
|
129
|
+
</TabItem>
|
|
130
|
+
<TabItem value="js" label="Vanilla JS">
|
|
131
|
+
|
|
132
|
+
```js
|
|
133
|
+
|
|
134
|
+
const grid = new OGrid(document.getElementById('grid'), {
|
|
135
|
+
columns: columns,
|
|
136
|
+
data: data,
|
|
137
|
+
getRowId: (r) => r.id,
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
// Export to CSV
|
|
141
|
+
document.getElementById('export-btn').addEventListener('click', () => {
|
|
142
|
+
exportToCsv(
|
|
143
|
+
data,
|
|
144
|
+
columns.map((col) => ({ columnId: col.columnId, name: col.name })),
|
|
145
|
+
(item, columnId) => {
|
|
146
|
+
const col = columns.find((c) => c.columnId === columnId);
|
|
147
|
+
if (!col) return '';
|
|
148
|
+
const value = item[columnId];
|
|
149
|
+
return col.valueFormatter ? col.valueFormatter(value, item) : String(value ?? '');
|
|
150
|
+
},
|
|
151
|
+
'my-data.csv'
|
|
152
|
+
);
|
|
153
|
+
});
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
</TabItem>
|
|
157
|
+
</Tabs>
|
|
158
|
+
|
|
159
|
+
## How It Works
|
|
160
|
+
|
|
161
|
+
### The `exportToCsv` Function
|
|
162
|
+
|
|
163
|
+
```tsx
|
|
164
|
+
exportToCsv<T>(
|
|
165
|
+
items: T[],
|
|
166
|
+
columns: CsvColumn[],
|
|
167
|
+
getValue: (item: T, columnId: string) => string,
|
|
168
|
+
filename?: string
|
|
169
|
+
): void
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
| Parameter | Type | Description |
|
|
173
|
+
|---|---|---|
|
|
174
|
+
| `items` | `T[]` | The row data to export |
|
|
175
|
+
| `columns` | `CsvColumn[]` | Array of `{ columnId, name }` defining which columns to include and their header names |
|
|
176
|
+
| `getValue` | `(item, columnId) => string` | Function to extract the display value for each cell |
|
|
177
|
+
| `filename` | `string` (optional) | Download filename (default: `'export.csv'`) |
|
|
178
|
+
|
|
179
|
+
The function:
|
|
180
|
+
1. Builds a CSV header row from `columns[].name`.
|
|
181
|
+
2. Iterates over each item and calls `getValue` for each column.
|
|
182
|
+
3. Escapes values containing commas, quotes, or newlines.
|
|
183
|
+
4. Triggers a browser download with the specified filename.
|
|
184
|
+
|
|
185
|
+
### Context Menu Integration
|
|
186
|
+
|
|
187
|
+
When `cellSelection` is enabled (the default), the context menu does not include a dedicated "Export to CSV" item. Use the `exportToCsv` utility directly from a toolbar button or custom UI element.
|
|
188
|
+
|
|
189
|
+
### Exporting Visible Columns Only
|
|
190
|
+
|
|
191
|
+
Filter the columns array to only include visible columns before passing to `exportToCsv`.
|
|
192
|
+
|
|
193
|
+
```tsx
|
|
194
|
+
const visibleCols = columns.filter((col) => visibleColumns.has(col.columnId));
|
|
195
|
+
|
|
196
|
+
exportToCsv(
|
|
197
|
+
data,
|
|
198
|
+
visibleCols.map((col) => ({ columnId: col.columnId, name: col.name })),
|
|
199
|
+
getValue,
|
|
200
|
+
'filtered-export.csv'
|
|
201
|
+
);
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
### Formatted Values
|
|
205
|
+
|
|
206
|
+
Use `valueFormatter` in your `getValue` function so exported data matches the display. For example, a currency column that shows "$1,234.56" in the grid will export that same string.
|
|
207
|
+
|
|
208
|
+
```tsx
|
|
209
|
+
const getValue = (item: Row, columnId: string) => {
|
|
210
|
+
const col = columns.find((c) => c.columnId === columnId)!;
|
|
211
|
+
const raw = col.valueGetter ? col.valueGetter(item) : (item as any)[columnId];
|
|
212
|
+
return col.valueFormatter ? col.valueFormatter(raw, item) : String(raw ?? '');
|
|
213
|
+
};
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
## Props Reference
|
|
217
|
+
|
|
218
|
+
| Type | Field | Description |
|
|
219
|
+
|---|---|---|
|
|
220
|
+
| `CsvColumn` | `columnId` | Column identifier |
|
|
221
|
+
| `CsvColumn` | `name` | Header label in the CSV |
|
|
222
|
+
|
|
223
|
+
## Related
|
|
224
|
+
|
|
225
|
+
- [Context Menu](./context-menu) -- clipboard operations for quick copy/paste
|
|
226
|
+
- [Grid API](./grid-api) -- access current data and column state programmatically
|
|
227
|
+
- [Column Chooser](./column-chooser) -- determines which columns are visible for export
|