@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,359 @@
|
|
|
1
|
+
---
|
|
2
|
+
sidebar_position: 11.5
|
|
3
|
+
title: Column Reordering
|
|
4
|
+
description: Rearrange columns by dragging their headers to a new position
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
# Column Reordering
|
|
9
|
+
|
|
10
|
+
Let users rearrange columns by dragging a column header and dropping it at a new position. The grid shows a visual drop indicator while dragging.
|
|
11
|
+
|
|
12
|
+
## Live Demo
|
|
13
|
+
|
|
14
|
+
<ColumnReorderingDemo />
|
|
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
|
+
interface Person {
|
|
28
|
+
id: number;
|
|
29
|
+
name: string;
|
|
30
|
+
email: string;
|
|
31
|
+
department: string;
|
|
32
|
+
salary: number;
|
|
33
|
+
status: string;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const columns: IColumnDef<Person>[] = [
|
|
37
|
+
{ columnId: 'name', name: 'Name' },
|
|
38
|
+
{ columnId: 'email', name: 'Email' },
|
|
39
|
+
{ columnId: 'department', name: 'Department' },
|
|
40
|
+
{ columnId: 'salary', name: 'Salary', type: 'numeric',
|
|
41
|
+
valueFormatter: (v) => `$${Number(v).toLocaleString()}` },
|
|
42
|
+
{ columnId: 'status', name: 'Status' },
|
|
43
|
+
];
|
|
44
|
+
|
|
45
|
+
function App() {
|
|
46
|
+
return (
|
|
47
|
+
<OGrid
|
|
48
|
+
columns={columns}
|
|
49
|
+
data={people}
|
|
50
|
+
getRowId={(p) => p.id}
|
|
51
|
+
columnReorder
|
|
52
|
+
defaultPageSize={10}
|
|
53
|
+
/>
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
:::tip Switching UI libraries
|
|
59
|
+
The `OGrid` component has the same props across all React UI packages. To switch, just change the import:
|
|
60
|
+
|
|
61
|
+
- **Radix** (lightweight, default): `from '@alaarab/ogrid-react-radix'`
|
|
62
|
+
- **Fluent UI** (Microsoft 365 / SPFx): `from '@alaarab/ogrid-react-fluent'` — wrap in `<FluentProvider>`
|
|
63
|
+
- **Material UI** (MUI v7): `from '@alaarab/ogrid-react-material'` — wrap in `<ThemeProvider>`
|
|
64
|
+
:::
|
|
65
|
+
|
|
66
|
+
</TabItem>
|
|
67
|
+
<TabItem value="angular" label="Angular">
|
|
68
|
+
|
|
69
|
+
```typescript
|
|
70
|
+
|
|
71
|
+
@Component({
|
|
72
|
+
standalone: true,
|
|
73
|
+
imports: [OGridComponent],
|
|
74
|
+
template: `<ogrid [props]="gridProps" />`
|
|
75
|
+
})
|
|
76
|
+
export class GridComponent {
|
|
77
|
+
gridProps = {
|
|
78
|
+
columns: [
|
|
79
|
+
{ columnId: 'name', name: 'Name' },
|
|
80
|
+
{ columnId: 'email', name: 'Email' },
|
|
81
|
+
{ columnId: 'department', name: 'Department' },
|
|
82
|
+
{
|
|
83
|
+
columnId: 'salary', name: 'Salary', type: 'numeric',
|
|
84
|
+
valueFormatter: (v: unknown) => `$${Number(v).toLocaleString()}`,
|
|
85
|
+
},
|
|
86
|
+
{ columnId: 'status', name: 'Status' },
|
|
87
|
+
] as IColumnDef<Person>[],
|
|
88
|
+
data: people,
|
|
89
|
+
getRowId: (item: Person) => item.id,
|
|
90
|
+
columnReorder: true,
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
:::tip Switching UI libraries
|
|
96
|
+
Same component API across Angular packages. To switch, just change the import:
|
|
97
|
+
|
|
98
|
+
- **Radix (CDK)**: `from '@alaarab/ogrid-angular-radix'` *(default, lightweight)*
|
|
99
|
+
- **Angular Material**: `from '@alaarab/ogrid-angular-material'`
|
|
100
|
+
- **PrimeNG**: `from '@alaarab/ogrid-angular-primeng'`
|
|
101
|
+
|
|
102
|
+
All components are standalone — no NgModule required.
|
|
103
|
+
:::
|
|
104
|
+
|
|
105
|
+
</TabItem>
|
|
106
|
+
<TabItem value="vue" label="Vue">
|
|
107
|
+
|
|
108
|
+
```vue
|
|
109
|
+
<script setup lang="ts">
|
|
110
|
+
|
|
111
|
+
const columns: IColumnDef<Person>[] = [
|
|
112
|
+
{ columnId: 'name', name: 'Name' },
|
|
113
|
+
{ columnId: 'email', name: 'Email' },
|
|
114
|
+
{ columnId: 'department', name: 'Department' },
|
|
115
|
+
{
|
|
116
|
+
columnId: 'salary', name: 'Salary', type: 'numeric',
|
|
117
|
+
valueFormatter: (v) => `$${Number(v).toLocaleString()}`,
|
|
118
|
+
},
|
|
119
|
+
{ columnId: 'status', name: 'Status' },
|
|
120
|
+
];
|
|
121
|
+
|
|
122
|
+
const gridProps = {
|
|
123
|
+
columns,
|
|
124
|
+
data: people,
|
|
125
|
+
getRowId: (item) => item.id,
|
|
126
|
+
columnReorder: true,
|
|
127
|
+
};
|
|
128
|
+
</script>
|
|
129
|
+
|
|
130
|
+
<template>
|
|
131
|
+
<OGrid :gridProps="gridProps" />
|
|
132
|
+
</template>
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
:::tip Switching UI libraries
|
|
136
|
+
Same component API across Vue packages. To switch, just change the import:
|
|
137
|
+
|
|
138
|
+
- **Radix (Headless UI)**: `from '@alaarab/ogrid-vue-radix'` *(default, lightweight)*
|
|
139
|
+
- **Vuetify**: `from '@alaarab/ogrid-vue-vuetify'` — wrap in `<v-app>` for theming
|
|
140
|
+
- **PrimeVue**: `from '@alaarab/ogrid-vue-primevue'`
|
|
141
|
+
:::
|
|
142
|
+
|
|
143
|
+
</TabItem>
|
|
144
|
+
<TabItem value="js" label="Vanilla JS">
|
|
145
|
+
|
|
146
|
+
```js
|
|
147
|
+
|
|
148
|
+
const grid = new OGrid(document.getElementById('grid'), {
|
|
149
|
+
columns: [
|
|
150
|
+
{ columnId: 'name', name: 'Name' },
|
|
151
|
+
{ columnId: 'email', name: 'Email' },
|
|
152
|
+
{ columnId: 'department', name: 'Department' },
|
|
153
|
+
{
|
|
154
|
+
columnId: 'salary',
|
|
155
|
+
name: 'Salary',
|
|
156
|
+
type: 'numeric',
|
|
157
|
+
valueFormatter: (v) => `$${Number(v).toLocaleString()}`,
|
|
158
|
+
},
|
|
159
|
+
{ columnId: 'status', name: 'Status' },
|
|
160
|
+
],
|
|
161
|
+
data: people,
|
|
162
|
+
getRowId: (p) => p.id,
|
|
163
|
+
columnReorder: true,
|
|
164
|
+
pageSize: 10,
|
|
165
|
+
});
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
</TabItem>
|
|
169
|
+
</Tabs>
|
|
170
|
+
|
|
171
|
+
Drag any column header to rearrange it. A vertical indicator line shows where the column will be placed.
|
|
172
|
+
|
|
173
|
+
## How It Works
|
|
174
|
+
|
|
175
|
+
Set `columnReorder` to `true` on the grid to enable drag-and-drop column reordering. When a user presses and drags a column header at least 5 pixels horizontally, the grid enters reorder mode:
|
|
176
|
+
|
|
177
|
+
1. A vertical drop indicator appears between columns as the user drags.
|
|
178
|
+
2. On mouse-up, the column is moved to the target position.
|
|
179
|
+
3. The grid fires `onColumnOrderChange` with the updated order array.
|
|
180
|
+
|
|
181
|
+
OGrid supports both **uncontrolled** and **controlled** column order:
|
|
182
|
+
|
|
183
|
+
- **Uncontrolled** -- the grid manages column order internally. Just set `columnReorder` and it works.
|
|
184
|
+
- **Controlled** -- you own the state. Pass `columnOrder` and `onColumnOrderChange` to the grid.
|
|
185
|
+
|
|
186
|
+
### Controlled Column Order
|
|
187
|
+
|
|
188
|
+
<Tabs groupId="framework">
|
|
189
|
+
<TabItem value="react" label="React" default>
|
|
190
|
+
|
|
191
|
+
```tsx
|
|
192
|
+
|
|
193
|
+
function App() {
|
|
194
|
+
const [columnOrder, setColumnOrder] = useState([
|
|
195
|
+
'name', 'email', 'department', 'salary', 'status',
|
|
196
|
+
]);
|
|
197
|
+
|
|
198
|
+
return (
|
|
199
|
+
<OGrid
|
|
200
|
+
columns={columns}
|
|
201
|
+
data={people}
|
|
202
|
+
getRowId={(p) => p.id}
|
|
203
|
+
columnReorder
|
|
204
|
+
columnOrder={columnOrder}
|
|
205
|
+
onColumnOrderChange={setColumnOrder}
|
|
206
|
+
defaultPageSize={10}
|
|
207
|
+
/>
|
|
208
|
+
);
|
|
209
|
+
}
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
</TabItem>
|
|
213
|
+
<TabItem value="angular" label="Angular">
|
|
214
|
+
|
|
215
|
+
```typescript
|
|
216
|
+
|
|
217
|
+
@Component({
|
|
218
|
+
standalone: true,
|
|
219
|
+
imports: [OGridComponent],
|
|
220
|
+
template: `<ogrid [props]="gridProps()" />`
|
|
221
|
+
})
|
|
222
|
+
export class GridComponent {
|
|
223
|
+
columnOrder = signal(['name', 'email', 'department', 'salary', 'status']);
|
|
224
|
+
|
|
225
|
+
gridProps = () => ({
|
|
226
|
+
columns,
|
|
227
|
+
data: people,
|
|
228
|
+
getRowId: (item: Person) => item.id,
|
|
229
|
+
columnReorder: true,
|
|
230
|
+
columnOrder: this.columnOrder(),
|
|
231
|
+
onColumnOrderChange: (order: string[]) => this.columnOrder.set(order),
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
</TabItem>
|
|
237
|
+
<TabItem value="vue" label="Vue">
|
|
238
|
+
|
|
239
|
+
```vue
|
|
240
|
+
<script setup lang="ts">
|
|
241
|
+
|
|
242
|
+
const columnOrder = ref(['name', 'email', 'department', 'salary', 'status']);
|
|
243
|
+
|
|
244
|
+
const gridProps = computed(() => ({
|
|
245
|
+
columns,
|
|
246
|
+
data: people,
|
|
247
|
+
getRowId: (item) => item.id,
|
|
248
|
+
columnReorder: true,
|
|
249
|
+
columnOrder: columnOrder.value,
|
|
250
|
+
onColumnOrderChange: (order: string[]) => { columnOrder.value = order; },
|
|
251
|
+
}));
|
|
252
|
+
</script>
|
|
253
|
+
|
|
254
|
+
<template>
|
|
255
|
+
<OGrid :gridProps="gridProps" />
|
|
256
|
+
</template>
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
</TabItem>
|
|
260
|
+
<TabItem value="js" label="Vanilla JS">
|
|
261
|
+
|
|
262
|
+
```js
|
|
263
|
+
|
|
264
|
+
const grid = new OGrid(document.getElementById('grid'), {
|
|
265
|
+
columns,
|
|
266
|
+
data: people,
|
|
267
|
+
getRowId: (p) => p.id,
|
|
268
|
+
columnReorder: true,
|
|
269
|
+
columnOrder: ['name', 'email', 'department', 'salary', 'status'],
|
|
270
|
+
onColumnOrderChange: (order) => {
|
|
271
|
+
console.log('New column order:', order);
|
|
272
|
+
},
|
|
273
|
+
});
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
</TabItem>
|
|
277
|
+
</Tabs>
|
|
278
|
+
|
|
279
|
+
### With Pinned Columns
|
|
280
|
+
|
|
281
|
+
Pinned columns can only be reordered within their own pinning zone. A left-pinned column cannot be dragged into the unpinned zone, and vice versa. This prevents accidental loss of pinned state during reorder.
|
|
282
|
+
|
|
283
|
+
```tsx
|
|
284
|
+
const columns = [
|
|
285
|
+
{ columnId: 'id', name: 'ID', pinned: 'left' },
|
|
286
|
+
{ columnId: 'name', name: 'Name', pinned: 'left' },
|
|
287
|
+
{ columnId: 'email', name: 'Email' },
|
|
288
|
+
{ columnId: 'department', name: 'Department' },
|
|
289
|
+
{ columnId: 'salary', name: 'Salary' },
|
|
290
|
+
];
|
|
291
|
+
|
|
292
|
+
<OGrid
|
|
293
|
+
columns={columns}
|
|
294
|
+
data={people}
|
|
295
|
+
getRowId={(p) => p.id}
|
|
296
|
+
columnReorder
|
|
297
|
+
defaultPageSize={10}
|
|
298
|
+
/>
|
|
299
|
+
```
|
|
300
|
+
|
|
301
|
+
In this example, "ID" and "Name" can be swapped with each other but cannot be dragged into the unpinned section. The unpinned columns ("Email", "Department", "Salary") can be freely rearranged among themselves.
|
|
302
|
+
|
|
303
|
+
### Edge Cases
|
|
304
|
+
|
|
305
|
+
- **Column groups:** Group headers are not draggable. Only leaf columns (with a `columnId`) participate in reordering.
|
|
306
|
+
- **Resize handle zone:** The rightmost 8 pixels of each header cell are reserved for column resizing. Dragging in that zone starts a resize, not a reorder.
|
|
307
|
+
- **Minimum drag distance:** A 5-pixel horizontal threshold prevents accidental reorders from clicks.
|
|
308
|
+
|
|
309
|
+
## Grid API
|
|
310
|
+
|
|
311
|
+
Column order can be read and updated programmatically through the Grid API:
|
|
312
|
+
|
|
313
|
+
```tsx
|
|
314
|
+
const gridRef = useRef<IOGridApi<Row>>(null);
|
|
315
|
+
|
|
316
|
+
// Get the current column display order
|
|
317
|
+
const order = gridRef.current.getColumnOrder();
|
|
318
|
+
// ['name', 'department', 'email', 'salary', 'status']
|
|
319
|
+
|
|
320
|
+
// Programmatically set column order
|
|
321
|
+
gridRef.current.setColumnOrder(['department', 'name', 'email', 'salary', 'status']);
|
|
322
|
+
|
|
323
|
+
// Save and restore via column state
|
|
324
|
+
const state = gridRef.current.getColumnState();
|
|
325
|
+
// state.columnOrder → ['name', 'department', 'email', 'salary', 'status']
|
|
326
|
+
localStorage.setItem('gridState', JSON.stringify(state));
|
|
327
|
+
|
|
328
|
+
// Restore on mount
|
|
329
|
+
const saved = JSON.parse(localStorage.getItem('gridState'));
|
|
330
|
+
gridRef.current.applyColumnState(saved);
|
|
331
|
+
```
|
|
332
|
+
|
|
333
|
+
## Props Reference
|
|
334
|
+
|
|
335
|
+
| Prop | Type | Default | Description |
|
|
336
|
+
|------|------|---------|-------------|
|
|
337
|
+
| `columnReorder` | `boolean` | `false` | Enable drag-and-drop column reordering. |
|
|
338
|
+
| `columnOrder` | `string[]` | -- | Controlled column display order (array of column ids). |
|
|
339
|
+
| `onColumnOrderChange` | `(order: string[]) => void` | -- | Called when column order changes via drag-and-drop. |
|
|
340
|
+
|
|
341
|
+
### Grid API Methods
|
|
342
|
+
|
|
343
|
+
| Method | Signature | Description |
|
|
344
|
+
|--------|-----------|-------------|
|
|
345
|
+
| `getColumnOrder` | `() => string[]` | Returns the current column display order. |
|
|
346
|
+
| `setColumnOrder` | `(order: string[]) => void` | Programmatically set column display order. |
|
|
347
|
+
| `getColumnState` | `() => IGridColumnState` | Returns full column state including order, widths, sort, filters. |
|
|
348
|
+
| `applyColumnState` | `(state: Partial<IGridColumnState>) => void` | Restores column state (including order). |
|
|
349
|
+
|
|
350
|
+
:::tip
|
|
351
|
+
Combine `columnReorder` with `columnChooser` and `sideBar` for a full column management experience -- users can show/hide, reorder, and resize columns to build their ideal layout.
|
|
352
|
+
:::
|
|
353
|
+
|
|
354
|
+
## Related
|
|
355
|
+
|
|
356
|
+
- [Column Pinning](./column-pinning) -- pin columns that stay fixed during reorder
|
|
357
|
+
- [Column Chooser](./column-chooser) -- show/hide columns
|
|
358
|
+
- [Grid API](./grid-api) -- save and restore column order via API
|
|
359
|
+
- [Sidebar](./sidebar) -- manage columns from a side panel
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
---
|
|
2
|
+
sidebar_position: 12.5
|
|
3
|
+
title: Column Types
|
|
4
|
+
description: Built-in column types for common data patterns — text, numeric, date, and boolean.
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
# Column Types
|
|
9
|
+
|
|
10
|
+
OGrid provides built-in column types that automatically configure alignment, display formatting, cell editors, and filter types. Set `type` on a column definition to opt in.
|
|
11
|
+
|
|
12
|
+
## Available Types
|
|
13
|
+
|
|
14
|
+
| Type | Alignment | Default Editor | Default Filter | Display Format |
|
|
15
|
+
|------|-----------|---------------|----------------|----------------|
|
|
16
|
+
| `'text'` | Left (default) | Text input | Text search | `String()` |
|
|
17
|
+
| `'numeric'` | Right | Text input | Text search | `String()` |
|
|
18
|
+
| `'date'` | Left | Date picker | Date range (from/to) | `toLocaleDateString()` |
|
|
19
|
+
| `'boolean'` | Center | Checkbox | — | `True` / `False` |
|
|
20
|
+
|
|
21
|
+
## Quick Example
|
|
22
|
+
|
|
23
|
+
```tsx
|
|
24
|
+
const columns = [
|
|
25
|
+
{ columnId: 'name', name: 'Name' },
|
|
26
|
+
{ columnId: 'age', name: 'Age', type: 'numeric' },
|
|
27
|
+
{
|
|
28
|
+
columnId: 'hireDate',
|
|
29
|
+
name: 'Hire Date',
|
|
30
|
+
type: 'date',
|
|
31
|
+
filterable: { type: 'date' },
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
columnId: 'active',
|
|
35
|
+
name: 'Active',
|
|
36
|
+
type: 'boolean',
|
|
37
|
+
editable: true,
|
|
38
|
+
},
|
|
39
|
+
];
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
### Usage
|
|
43
|
+
|
|
44
|
+
<Tabs groupId="framework">
|
|
45
|
+
<TabItem value="react" label="React" default>
|
|
46
|
+
|
|
47
|
+
```tsx
|
|
48
|
+
|
|
49
|
+
function App() {
|
|
50
|
+
return (
|
|
51
|
+
<OGrid
|
|
52
|
+
columns={columns}
|
|
53
|
+
data={data}
|
|
54
|
+
getRowId={(r) => r.id}
|
|
55
|
+
editable
|
|
56
|
+
/>
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
:::tip Switching UI libraries
|
|
62
|
+
The `OGrid` component has the same props across all React UI packages. To switch, just change the import:
|
|
63
|
+
|
|
64
|
+
- **Radix** (lightweight, default): `from '@alaarab/ogrid-react-radix'`
|
|
65
|
+
- **Fluent UI** (Microsoft 365 / SPFx): `from '@alaarab/ogrid-react-fluent'` — wrap in `<FluentProvider>`
|
|
66
|
+
- **Material UI** (MUI v7): `from '@alaarab/ogrid-react-material'` — wrap in `<ThemeProvider>`
|
|
67
|
+
:::
|
|
68
|
+
|
|
69
|
+
</TabItem>
|
|
70
|
+
<TabItem value="angular" label="Angular">
|
|
71
|
+
|
|
72
|
+
```typescript
|
|
73
|
+
|
|
74
|
+
@Component({
|
|
75
|
+
standalone: true,
|
|
76
|
+
imports: [OGridComponent],
|
|
77
|
+
template: `<ogrid [props]="gridProps" />`
|
|
78
|
+
})
|
|
79
|
+
export class GridComponent {
|
|
80
|
+
gridProps = {
|
|
81
|
+
columns: columns,
|
|
82
|
+
data: data,
|
|
83
|
+
getRowId: (r: Row) => r.id,
|
|
84
|
+
editable: true,
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
:::tip Switching UI libraries
|
|
90
|
+
Same component API across Angular packages. To switch, just change the import:
|
|
91
|
+
|
|
92
|
+
- **Radix (CDK)**: `from '@alaarab/ogrid-angular-radix'` *(default, lightweight)*
|
|
93
|
+
- **Angular Material**: `from '@alaarab/ogrid-angular-material'`
|
|
94
|
+
- **PrimeNG**: `from '@alaarab/ogrid-angular-primeng'`
|
|
95
|
+
|
|
96
|
+
All components are standalone — no NgModule required.
|
|
97
|
+
:::
|
|
98
|
+
|
|
99
|
+
</TabItem>
|
|
100
|
+
<TabItem value="vue" label="Vue">
|
|
101
|
+
|
|
102
|
+
```vue
|
|
103
|
+
<script setup lang="ts">
|
|
104
|
+
|
|
105
|
+
const gridProps = {
|
|
106
|
+
columns,
|
|
107
|
+
data,
|
|
108
|
+
getRowId: (r) => r.id,
|
|
109
|
+
editable: true,
|
|
110
|
+
};
|
|
111
|
+
</script>
|
|
112
|
+
|
|
113
|
+
<template>
|
|
114
|
+
<OGrid :gridProps="gridProps" />
|
|
115
|
+
</template>
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
:::tip Switching UI libraries
|
|
119
|
+
Same component API across Vue packages. To switch, just change the import:
|
|
120
|
+
|
|
121
|
+
- **Radix (Headless UI)**: `from '@alaarab/ogrid-vue-radix'` *(default, lightweight)*
|
|
122
|
+
- **Vuetify**: `from '@alaarab/ogrid-vue-vuetify'` — wrap in `<v-app>` for theming
|
|
123
|
+
- **PrimeVue**: `from '@alaarab/ogrid-vue-primevue'`
|
|
124
|
+
:::
|
|
125
|
+
|
|
126
|
+
</TabItem>
|
|
127
|
+
<TabItem value="js" label="Vanilla JS">
|
|
128
|
+
|
|
129
|
+
```js
|
|
130
|
+
|
|
131
|
+
const grid = new OGrid(document.getElementById('grid'), {
|
|
132
|
+
columns: columns,
|
|
133
|
+
data: data,
|
|
134
|
+
getRowId: (r) => r.id,
|
|
135
|
+
editable: true,
|
|
136
|
+
});
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
</TabItem>
|
|
140
|
+
</Tabs>
|
|
141
|
+
|
|
142
|
+
## Date Columns
|
|
143
|
+
|
|
144
|
+
Setting `type: 'date'` provides:
|
|
145
|
+
|
|
146
|
+
- **Display**: Values are automatically formatted via `toLocaleDateString()` (unless you provide a custom `valueFormatter` or `renderCell`).
|
|
147
|
+
- **Sorting**: Dates are compared chronologically via `Date.getTime()`, not alphabetically.
|
|
148
|
+
- **Cell editor**: Uses `<input type="date">` (native browser date picker) by default.
|
|
149
|
+
- **Filter**: When `filterable: { type: 'date' }` is set, the column header filter shows **From** and **To** date inputs. Both are optional — you can filter by "after", "before", or a range.
|
|
150
|
+
|
|
151
|
+
### Date Filter Values
|
|
152
|
+
|
|
153
|
+
Date filter values use ISO `YYYY-MM-DD` strings wrapped in the `FilterValue` discriminated union:
|
|
154
|
+
|
|
155
|
+
```ts
|
|
156
|
+
// In IFilters
|
|
157
|
+
{ hireDate: { type: 'date', value: { from: '2024-01-01', to: '2024-12-31' } } }
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
## Boolean Columns
|
|
161
|
+
|
|
162
|
+
Setting `type: 'boolean'` provides:
|
|
163
|
+
|
|
164
|
+
- **Display**: Shows `True` or `False` text (override with `valueFormatter` or `renderCell`).
|
|
165
|
+
- **Alignment**: Center-aligned.
|
|
166
|
+
- **Cell editor**: Defaults to checkbox editor.
|
|
167
|
+
|
|
168
|
+
## Custom Formatting
|
|
169
|
+
|
|
170
|
+
The `type` sets sensible defaults, but you can always override with `valueFormatter`, `renderCell`, or `cellEditor`:
|
|
171
|
+
|
|
172
|
+
```tsx
|
|
173
|
+
{
|
|
174
|
+
columnId: 'hireDate',
|
|
175
|
+
name: 'Hire Date',
|
|
176
|
+
type: 'date',
|
|
177
|
+
valueFormatter: (value) => new Date(String(value)).toLocaleDateString('en-US', {
|
|
178
|
+
year: 'numeric', month: 'short', day: 'numeric',
|
|
179
|
+
}),
|
|
180
|
+
}
|
|
181
|
+
```
|