@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,225 @@
|
|
|
1
|
+
---
|
|
2
|
+
sidebar_position: 22
|
|
3
|
+
title: Cell References
|
|
4
|
+
description: Excel-style column letters (A, B, C...), row numbers, and a name box showing the active cell reference.
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
# Cell References
|
|
9
|
+
|
|
10
|
+
Enable Excel-style cell references with a single prop. Column letter headers (A, B, C...) appear above the header row, row numbers show in the left gutter, and a name box in the toolbar displays the active cell reference (e.g. "A1", "C15").
|
|
11
|
+
|
|
12
|
+
## Live Demo
|
|
13
|
+
|
|
14
|
+
<CellReferencesDemo />
|
|
15
|
+
|
|
16
|
+
:::tip Framework-Specific Styling
|
|
17
|
+
The live demo above shows **React Radix UI** styling (lightweight default). To see how cell references look in your framework's design system, click the framework buttons above the demo to open online demo:
|
|
18
|
+
- **React** -- Radix UI default theme
|
|
19
|
+
- **Angular** -- Angular Material theme
|
|
20
|
+
- **Vue** -- Vuetify theme
|
|
21
|
+
- **JS** -- Vanilla JS default theme
|
|
22
|
+
|
|
23
|
+
Each framework renders with its native components, so the styling matches your design system.
|
|
24
|
+
:::
|
|
25
|
+
|
|
26
|
+
## Quick Example
|
|
27
|
+
|
|
28
|
+
<Tabs groupId="framework">
|
|
29
|
+
<TabItem value="react" label="React" default>
|
|
30
|
+
|
|
31
|
+
```tsx
|
|
32
|
+
|
|
33
|
+
const columns = [
|
|
34
|
+
{ columnId: 'name', name: 'Name' },
|
|
35
|
+
{ columnId: 'age', name: 'Age', type: 'numeric' as const },
|
|
36
|
+
{ columnId: 'email', name: 'Email' },
|
|
37
|
+
{ columnId: 'department', name: 'Department' },
|
|
38
|
+
{ columnId: 'salary', name: 'Salary', type: 'numeric' as const,
|
|
39
|
+
valueFormatter: (v) => `$${Number(v).toLocaleString()}` },
|
|
40
|
+
];
|
|
41
|
+
|
|
42
|
+
function App() {
|
|
43
|
+
return (
|
|
44
|
+
<OGrid
|
|
45
|
+
columns={columns}
|
|
46
|
+
data={people}
|
|
47
|
+
getRowId={(item) => item.id}
|
|
48
|
+
cellReferences
|
|
49
|
+
defaultPageSize={25}
|
|
50
|
+
entityLabelPlural="people"
|
|
51
|
+
/>
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
:::tip Switching UI libraries
|
|
57
|
+
The `OGrid` component has the same props across all React UI packages. To switch, just change the import:
|
|
58
|
+
|
|
59
|
+
- **Radix** (lightweight, default): `from '@alaarab/ogrid-react-radix'`
|
|
60
|
+
- **Fluent UI** (Microsoft 365 / SPFx): `from '@alaarab/ogrid-react-fluent'` -- wrap in `<FluentProvider>`
|
|
61
|
+
- **Material UI** (MUI v7): `from '@alaarab/ogrid-react-material'` -- wrap in `<ThemeProvider>`
|
|
62
|
+
:::
|
|
63
|
+
|
|
64
|
+
</TabItem>
|
|
65
|
+
<TabItem value="angular" label="Angular">
|
|
66
|
+
|
|
67
|
+
```typescript
|
|
68
|
+
|
|
69
|
+
@Component({
|
|
70
|
+
standalone: true,
|
|
71
|
+
imports: [OGridComponent],
|
|
72
|
+
template: `<ogrid [props]="gridProps" />`
|
|
73
|
+
})
|
|
74
|
+
export class GridComponent {
|
|
75
|
+
gridProps = {
|
|
76
|
+
columns: [
|
|
77
|
+
{ columnId: 'name', name: 'Name' },
|
|
78
|
+
{ columnId: 'age', name: 'Age', type: 'numeric' },
|
|
79
|
+
{ columnId: 'email', name: 'Email' },
|
|
80
|
+
{ columnId: 'department', name: 'Department' },
|
|
81
|
+
{
|
|
82
|
+
columnId: 'salary', name: 'Salary', type: 'numeric',
|
|
83
|
+
valueFormatter: (v: unknown) => `$${Number(v).toLocaleString()}`,
|
|
84
|
+
},
|
|
85
|
+
] as IColumnDef<Person>[],
|
|
86
|
+
data: people,
|
|
87
|
+
getRowId: (item: Person) => item.id,
|
|
88
|
+
cellReferences: true,
|
|
89
|
+
defaultPageSize: 25,
|
|
90
|
+
entityLabelPlural: 'people',
|
|
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: 'age', name: 'Age', type: 'numeric' },
|
|
114
|
+
{ columnId: 'email', name: 'Email' },
|
|
115
|
+
{ columnId: 'department', name: 'Department' },
|
|
116
|
+
{
|
|
117
|
+
columnId: 'salary', name: 'Salary', type: 'numeric',
|
|
118
|
+
valueFormatter: (v) => `$${Number(v).toLocaleString()}`,
|
|
119
|
+
},
|
|
120
|
+
];
|
|
121
|
+
|
|
122
|
+
const gridProps = {
|
|
123
|
+
columns,
|
|
124
|
+
data: people,
|
|
125
|
+
getRowId: (item) => item.id,
|
|
126
|
+
cellReferences: true,
|
|
127
|
+
defaultPageSize: 25,
|
|
128
|
+
entityLabelPlural: 'people',
|
|
129
|
+
};
|
|
130
|
+
</script>
|
|
131
|
+
|
|
132
|
+
<template>
|
|
133
|
+
<OGrid :gridProps="gridProps" />
|
|
134
|
+
</template>
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
:::tip Switching UI libraries
|
|
138
|
+
Same component API across Vue packages. To switch, just change the import:
|
|
139
|
+
|
|
140
|
+
- **Radix (Headless UI)**: `from '@alaarab/ogrid-vue-radix'` *(default, lightweight)*
|
|
141
|
+
- **Vuetify**: `from '@alaarab/ogrid-vue-vuetify'` -- wrap in `<v-app>` for theming
|
|
142
|
+
- **PrimeVue**: `from '@alaarab/ogrid-vue-primevue'`
|
|
143
|
+
:::
|
|
144
|
+
|
|
145
|
+
</TabItem>
|
|
146
|
+
<TabItem value="js" label="Vanilla JS">
|
|
147
|
+
|
|
148
|
+
```js
|
|
149
|
+
|
|
150
|
+
const grid = new OGrid(document.getElementById('grid'), {
|
|
151
|
+
columns: [
|
|
152
|
+
{ columnId: 'name', name: 'Name' },
|
|
153
|
+
{ columnId: 'age', name: 'Age', type: 'numeric' },
|
|
154
|
+
{ columnId: 'email', name: 'Email' },
|
|
155
|
+
{ columnId: 'department', name: 'Department' },
|
|
156
|
+
{
|
|
157
|
+
columnId: 'salary',
|
|
158
|
+
name: 'Salary',
|
|
159
|
+
type: 'numeric',
|
|
160
|
+
valueFormatter: (v) => `$${Number(v).toLocaleString()}`,
|
|
161
|
+
},
|
|
162
|
+
],
|
|
163
|
+
data: people,
|
|
164
|
+
getRowId: (item) => item.id,
|
|
165
|
+
cellReferences: true,
|
|
166
|
+
pageSize: 25,
|
|
167
|
+
entityLabelPlural: 'people',
|
|
168
|
+
});
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
</TabItem>
|
|
172
|
+
</Tabs>
|
|
173
|
+
|
|
174
|
+
## How It Works
|
|
175
|
+
|
|
176
|
+
Setting `cellReferences` on the `OGrid` component enables three visual features together:
|
|
177
|
+
|
|
178
|
+
### 1. Column Letter Headers
|
|
179
|
+
|
|
180
|
+
A row of Excel-style column letters (A, B, C, ..., Z, AA, AB, ...) appears above the normal header row. These letters use base-26 encoding, matching the Excel convention:
|
|
181
|
+
|
|
182
|
+
| Columns | Letters |
|
|
183
|
+
|---------|---------|
|
|
184
|
+
| 1--26 | A--Z |
|
|
185
|
+
| 27--52 | AA--AZ |
|
|
186
|
+
| 53--78 | BA--BZ |
|
|
187
|
+
| 703+ | AAA, AAB, ... |
|
|
188
|
+
|
|
189
|
+
### 2. Row Numbers
|
|
190
|
+
|
|
191
|
+
A numbered gutter column appears on the left side of the grid showing the absolute row number (1, 2, 3, ...). Row numbers are consistent across pages -- page 2 with a page size of 25 starts at row 26, not row 1.
|
|
192
|
+
|
|
193
|
+
:::info Row numbers without cell references
|
|
194
|
+
You can show row numbers independently without the full cell references feature by using the `showRowNumbers` prop:
|
|
195
|
+
|
|
196
|
+
```tsx
|
|
197
|
+
<OGrid
|
|
198
|
+
columns={columns}
|
|
199
|
+
data={people}
|
|
200
|
+
getRowId={(item) => item.id}
|
|
201
|
+
showRowNumbers
|
|
202
|
+
/>
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
This gives you the numbered gutter column without column letters or the name box.
|
|
206
|
+
:::
|
|
207
|
+
|
|
208
|
+
### 3. Name Box
|
|
209
|
+
|
|
210
|
+
A small read-only text field appears in the toolbar showing the currently active cell reference (e.g. "A1", "C15", "G3"). It updates automatically when you click a cell or navigate with the keyboard.
|
|
211
|
+
|
|
212
|
+
The name box uses the column letter and absolute row number, so clicking the third column on row 5 of page 2 (with a page size of 10) shows "C15", not "C5".
|
|
213
|
+
|
|
214
|
+
## Props
|
|
215
|
+
|
|
216
|
+
| Prop | Type | Default | Description |
|
|
217
|
+
|------|------|---------|-------------|
|
|
218
|
+
| `cellReferences` | `boolean` | `false` | Enable Excel-style cell references: column letter headers, row number gutter, and name box. Implies `showRowNumbers`. |
|
|
219
|
+
| `showRowNumbers` | `boolean` | `false` | Show only the row number gutter column (no column letters or name box). Automatically enabled when `cellReferences` is `true`. |
|
|
220
|
+
|
|
221
|
+
## Related
|
|
222
|
+
|
|
223
|
+
- [Spreadsheet Selection](./spreadsheet-selection) -- cell-level selection with drag and shift-click
|
|
224
|
+
- [Keyboard Navigation](./keyboard-navigation) -- arrow key navigation updates the name box
|
|
225
|
+
- [Toolbar](./toolbar) -- the name box renders inside the toolbar strip
|
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
---
|
|
2
|
+
sidebar_position: 12
|
|
3
|
+
title: Column Chooser
|
|
4
|
+
description: Let users show and hide columns with a dropdown control
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
# Column Chooser
|
|
9
|
+
|
|
10
|
+
The Column Chooser gives users a dropdown with checkboxes to show or hide columns at runtime. Columns marked `required` cannot be hidden.
|
|
11
|
+
|
|
12
|
+
## Live Demo
|
|
13
|
+
|
|
14
|
+
<ColumnChooserDemo />
|
|
15
|
+
|
|
16
|
+
:::tip Framework-Specific Styling
|
|
17
|
+
The live demo above shows **React Radix UI** styling (lightweight default). To see how the column chooser dropdown looks in your framework's design system, click the framework buttons above the demo to open online demo. Each framework renders with its native dropdown and checkbox components, so the styling matches your design system.
|
|
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
|
+
age: number;
|
|
32
|
+
department: string;
|
|
33
|
+
salary: number;
|
|
34
|
+
startDate: string;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const columns: IColumnDef<Person>[] = [
|
|
38
|
+
{ columnId: 'name', name: 'Name', required: true },
|
|
39
|
+
{ columnId: 'email', name: 'Email' },
|
|
40
|
+
{ columnId: 'age', name: 'Age', type: 'numeric', defaultVisible: false },
|
|
41
|
+
{ columnId: 'department', name: 'Department' },
|
|
42
|
+
{
|
|
43
|
+
columnId: 'salary',
|
|
44
|
+
name: 'Salary',
|
|
45
|
+
type: 'numeric',
|
|
46
|
+
valueFormatter: (v) => `$${Number(v).toLocaleString()}`,
|
|
47
|
+
},
|
|
48
|
+
{ columnId: 'startDate', name: 'Start Date', defaultVisible: false },
|
|
49
|
+
];
|
|
50
|
+
|
|
51
|
+
function App() {
|
|
52
|
+
return (
|
|
53
|
+
<OGrid
|
|
54
|
+
columns={columns}
|
|
55
|
+
data={people}
|
|
56
|
+
getRowId={(p) => p.id}
|
|
57
|
+
defaultPageSize={10}
|
|
58
|
+
/>
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
:::tip Switching UI libraries
|
|
64
|
+
The `OGrid` component has the same props across all React UI packages. To switch, just change the import:
|
|
65
|
+
|
|
66
|
+
- **Radix** (lightweight, default): `from '@alaarab/ogrid-react-radix'`
|
|
67
|
+
- **Fluent UI** (Microsoft 365 / SPFx): `from '@alaarab/ogrid-react-fluent'` — wrap in `<FluentProvider>`
|
|
68
|
+
- **Material UI** (MUI v7): `from '@alaarab/ogrid-react-material'` — wrap in `<ThemeProvider>`
|
|
69
|
+
:::
|
|
70
|
+
|
|
71
|
+
</TabItem>
|
|
72
|
+
<TabItem value="angular" label="Angular">
|
|
73
|
+
|
|
74
|
+
```typescript
|
|
75
|
+
|
|
76
|
+
interface Person {
|
|
77
|
+
id: number;
|
|
78
|
+
name: string;
|
|
79
|
+
email: string;
|
|
80
|
+
age: number;
|
|
81
|
+
department: string;
|
|
82
|
+
salary: number;
|
|
83
|
+
startDate: string;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const columns: IColumnDef<Person>[] = [
|
|
87
|
+
{ columnId: 'name', name: 'Name', required: true },
|
|
88
|
+
{ columnId: 'email', name: 'Email' },
|
|
89
|
+
{ columnId: 'age', name: 'Age', type: 'numeric', defaultVisible: false },
|
|
90
|
+
{ columnId: 'department', name: 'Department' },
|
|
91
|
+
{
|
|
92
|
+
columnId: 'salary',
|
|
93
|
+
name: 'Salary',
|
|
94
|
+
type: 'numeric',
|
|
95
|
+
valueFormatter: (v: unknown) => `$${Number(v).toLocaleString()}`,
|
|
96
|
+
},
|
|
97
|
+
{ columnId: 'startDate', name: 'Start Date', defaultVisible: false },
|
|
98
|
+
];
|
|
99
|
+
|
|
100
|
+
@Component({
|
|
101
|
+
standalone: true,
|
|
102
|
+
imports: [OGridComponent],
|
|
103
|
+
template: `<ogrid [props]="gridProps" />`
|
|
104
|
+
})
|
|
105
|
+
export class GridComponent {
|
|
106
|
+
gridProps = {
|
|
107
|
+
columns,
|
|
108
|
+
data: people,
|
|
109
|
+
getRowId: (p: Person) => p.id,
|
|
110
|
+
defaultPageSize: 10,
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
:::tip Switching UI libraries
|
|
116
|
+
Same component API across Angular packages. To switch, just change the import:
|
|
117
|
+
|
|
118
|
+
- **Radix (CDK)**: `from '@alaarab/ogrid-angular-radix'` *(default, lightweight)*
|
|
119
|
+
- **Angular Material**: `from '@alaarab/ogrid-angular-material'`
|
|
120
|
+
- **PrimeNG**: `from '@alaarab/ogrid-angular-primeng'`
|
|
121
|
+
|
|
122
|
+
All components are standalone — no NgModule required.
|
|
123
|
+
:::
|
|
124
|
+
|
|
125
|
+
</TabItem>
|
|
126
|
+
<TabItem value="vue" label="Vue">
|
|
127
|
+
|
|
128
|
+
```vue
|
|
129
|
+
<script setup lang="ts">
|
|
130
|
+
|
|
131
|
+
interface Person {
|
|
132
|
+
id: number;
|
|
133
|
+
name: string;
|
|
134
|
+
email: string;
|
|
135
|
+
age: number;
|
|
136
|
+
department: string;
|
|
137
|
+
salary: number;
|
|
138
|
+
startDate: string;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
const columns: IColumnDef<Person>[] = [
|
|
142
|
+
{ columnId: 'name', name: 'Name', required: true },
|
|
143
|
+
{ columnId: 'email', name: 'Email' },
|
|
144
|
+
{ columnId: 'age', name: 'Age', type: 'numeric', defaultVisible: false },
|
|
145
|
+
{ columnId: 'department', name: 'Department' },
|
|
146
|
+
{
|
|
147
|
+
columnId: 'salary',
|
|
148
|
+
name: 'Salary',
|
|
149
|
+
type: 'numeric',
|
|
150
|
+
valueFormatter: (v) => `$${Number(v).toLocaleString()}`,
|
|
151
|
+
},
|
|
152
|
+
{ columnId: 'startDate', name: 'Start Date', defaultVisible: false },
|
|
153
|
+
];
|
|
154
|
+
|
|
155
|
+
const gridProps = {
|
|
156
|
+
columns,
|
|
157
|
+
data: people,
|
|
158
|
+
getRowId: (p: Person) => p.id,
|
|
159
|
+
defaultPageSize: 10,
|
|
160
|
+
};
|
|
161
|
+
</script>
|
|
162
|
+
|
|
163
|
+
<template>
|
|
164
|
+
<OGrid :gridProps="gridProps" />
|
|
165
|
+
</template>
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
:::tip Switching UI libraries
|
|
169
|
+
Same component API across Vue packages. To switch, just change the import:
|
|
170
|
+
|
|
171
|
+
- **Radix (Headless UI)**: `from '@alaarab/ogrid-vue-radix'` *(default, lightweight)*
|
|
172
|
+
- **Vuetify**: `from '@alaarab/ogrid-vue-vuetify'` — wrap in `<v-app>` for theming
|
|
173
|
+
- **PrimeVue**: `from '@alaarab/ogrid-vue-primevue'`
|
|
174
|
+
:::
|
|
175
|
+
|
|
176
|
+
</TabItem>
|
|
177
|
+
<TabItem value="js" label="Vanilla JS">
|
|
178
|
+
|
|
179
|
+
```js
|
|
180
|
+
|
|
181
|
+
const grid = new OGrid(document.getElementById('grid'), {
|
|
182
|
+
columns: [
|
|
183
|
+
{ columnId: 'name', name: 'Name', required: true },
|
|
184
|
+
{ columnId: 'email', name: 'Email' },
|
|
185
|
+
{ columnId: 'age', name: 'Age', type: 'numeric', defaultVisible: false },
|
|
186
|
+
{ columnId: 'department', name: 'Department' },
|
|
187
|
+
{
|
|
188
|
+
columnId: 'salary',
|
|
189
|
+
name: 'Salary',
|
|
190
|
+
type: 'numeric',
|
|
191
|
+
valueFormatter: (v) => `$${Number(v).toLocaleString()}`,
|
|
192
|
+
},
|
|
193
|
+
{ columnId: 'startDate', name: 'Start Date', defaultVisible: false },
|
|
194
|
+
],
|
|
195
|
+
data: people,
|
|
196
|
+
getRowId: (p) => p.id,
|
|
197
|
+
pageSize: 10,
|
|
198
|
+
});
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
</TabItem>
|
|
202
|
+
</Tabs>
|
|
203
|
+
|
|
204
|
+
In this example:
|
|
205
|
+
- **Name** is always visible (cannot be unchecked because `required: true`).
|
|
206
|
+
- **Age** and **Start Date** are hidden by default but the user can enable them.
|
|
207
|
+
- **Email**, **Department**, and **Salary** are visible by default and can be toggled.
|
|
208
|
+
|
|
209
|
+
## How It Works
|
|
210
|
+
|
|
211
|
+
OGrid includes a built-in Column Chooser that appears in the grid toolbar. Users click it to open a dropdown listing all columns with checkboxes.
|
|
212
|
+
|
|
213
|
+
### Hiding Columns by Default
|
|
214
|
+
|
|
215
|
+
Set `defaultVisible: false` on a column definition to hide it when the grid first renders. Users can still show it via the Column Chooser.
|
|
216
|
+
|
|
217
|
+
```tsx
|
|
218
|
+
{ columnId: 'phone', name: 'Phone', defaultVisible: false }
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
### Preventing Users from Hiding a Column
|
|
222
|
+
|
|
223
|
+
Set `required: true` to lock a column as always visible. Its checkbox in the Column Chooser will be disabled.
|
|
224
|
+
|
|
225
|
+
```tsx
|
|
226
|
+
{ columnId: 'name', name: 'Name', required: true }
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
### Controlled Visibility
|
|
230
|
+
|
|
231
|
+
For full control over which columns are visible, pass `visibleColumns` and `onVisibleColumnsChange`.
|
|
232
|
+
|
|
233
|
+
```tsx
|
|
234
|
+
function App() {
|
|
235
|
+
const [visible, setVisible] = useState<Set<string>>(
|
|
236
|
+
new Set(['name', 'email', 'department'])
|
|
237
|
+
);
|
|
238
|
+
|
|
239
|
+
return (
|
|
240
|
+
<OGrid
|
|
241
|
+
columns={columns}
|
|
242
|
+
data={rows}
|
|
243
|
+
getRowId={(r) => r.id}
|
|
244
|
+
visibleColumns={visible}
|
|
245
|
+
onVisibleColumnsChange={setVisible}
|
|
246
|
+
/>
|
|
247
|
+
);
|
|
248
|
+
}
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
When these props are provided, OGrid uses them instead of its internal visibility state.
|
|
252
|
+
|
|
253
|
+
### Standalone ColumnChooser Component
|
|
254
|
+
|
|
255
|
+
Each UI package also exports a standalone `ColumnChooser` component that you can render anywhere in your UI.
|
|
256
|
+
|
|
257
|
+
```tsx
|
|
258
|
+
|
|
259
|
+
<ColumnChooser
|
|
260
|
+
columns={columns}
|
|
261
|
+
visibleColumns={visibleColumns}
|
|
262
|
+
onVisibleColumnsChange={setVisibleColumns}
|
|
263
|
+
/>
|
|
264
|
+
```
|
|
265
|
+
|
|
266
|
+
## Props Reference
|
|
267
|
+
|
|
268
|
+
| Type | Field | Description |
|
|
269
|
+
|---|---|---|
|
|
270
|
+
| `IColumnMeta` | `defaultVisible` | `false` to hide on initial render (default: `true`) |
|
|
271
|
+
| `IColumnMeta` | `required` | `true` to prevent the user from hiding this column |
|
|
272
|
+
| `IOGridProps<T>` | `visibleColumns` | Controlled `Set<string>` of visible column IDs |
|
|
273
|
+
| `IOGridProps<T>` | `onVisibleColumnsChange` | Callback when visibility changes: `(cols: Set<string>) => void` |
|
|
274
|
+
|
|
275
|
+
## Related
|
|
276
|
+
|
|
277
|
+
- [Column Groups](./column-groups) -- visibility applies to leaf columns within groups
|
|
278
|
+
- [Column Pinning](./column-pinning) -- pinned columns can also be toggled
|
|
279
|
+
- [Grid API](./grid-api) -- `getColumnState()` / `applyColumnState()` to save and restore visibility
|