@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.
Files changed (52) hide show
  1. package/README.md +68 -0
  2. package/bundled-docs/api/README.md +94 -0
  3. package/bundled-docs/api/column-def.mdx +379 -0
  4. package/bundled-docs/api/components-column-chooser.mdx +310 -0
  5. package/bundled-docs/api/components-column-header-filter.mdx +363 -0
  6. package/bundled-docs/api/components-datagrid-table.mdx +316 -0
  7. package/bundled-docs/api/components-pagination-controls.mdx +344 -0
  8. package/bundled-docs/api/components-sidebar.mdx +427 -0
  9. package/bundled-docs/api/components-status-bar.mdx +309 -0
  10. package/bundled-docs/api/grid-api.mdx +299 -0
  11. package/bundled-docs/api/js-api.mdx +198 -0
  12. package/bundled-docs/api/ogrid-props.mdx +244 -0
  13. package/bundled-docs/api/types.mdx +640 -0
  14. package/bundled-docs/features/cell-references.mdx +225 -0
  15. package/bundled-docs/features/column-chooser.mdx +279 -0
  16. package/bundled-docs/features/column-groups.mdx +290 -0
  17. package/bundled-docs/features/column-pinning.mdx +282 -0
  18. package/bundled-docs/features/column-reordering.mdx +359 -0
  19. package/bundled-docs/features/column-types.mdx +181 -0
  20. package/bundled-docs/features/context-menu.mdx +216 -0
  21. package/bundled-docs/features/csv-export.mdx +227 -0
  22. package/bundled-docs/features/editing.mdx +377 -0
  23. package/bundled-docs/features/filtering.mdx +330 -0
  24. package/bundled-docs/features/formulas.mdx +381 -0
  25. package/bundled-docs/features/grid-api.mdx +311 -0
  26. package/bundled-docs/features/keyboard-navigation.mdx +236 -0
  27. package/bundled-docs/features/pagination.mdx +245 -0
  28. package/bundled-docs/features/performance.mdx +433 -0
  29. package/bundled-docs/features/row-selection.mdx +256 -0
  30. package/bundled-docs/features/server-side-data.mdx +291 -0
  31. package/bundled-docs/features/sidebar.mdx +234 -0
  32. package/bundled-docs/features/sorting.mdx +241 -0
  33. package/bundled-docs/features/spreadsheet-selection.mdx +201 -0
  34. package/bundled-docs/features/status-bar.mdx +205 -0
  35. package/bundled-docs/features/toolbar.mdx +284 -0
  36. package/bundled-docs/features/virtual-scrolling.mdx +624 -0
  37. package/bundled-docs/getting-started/installation.mdx +216 -0
  38. package/bundled-docs/getting-started/overview.mdx +151 -0
  39. package/bundled-docs/getting-started/quick-start.mdx +425 -0
  40. package/bundled-docs/getting-started/vanilla-js.mdx +191 -0
  41. package/bundled-docs/guides/accessibility.mdx +550 -0
  42. package/bundled-docs/guides/controlled-vs-uncontrolled.mdx +153 -0
  43. package/bundled-docs/guides/custom-cell-editors.mdx +201 -0
  44. package/bundled-docs/guides/framework-showcase.mdx +200 -0
  45. package/bundled-docs/guides/mcp-live-testing.mdx +291 -0
  46. package/bundled-docs/guides/mcp.mdx +172 -0
  47. package/bundled-docs/guides/migration-from-ag-grid.mdx +223 -0
  48. package/bundled-docs/guides/theming.mdx +211 -0
  49. package/dist/esm/bridge-client.d.ts +87 -0
  50. package/dist/esm/bridge-client.js +162 -0
  51. package/dist/esm/index.js +1060 -0
  52. package/package.json +43 -0
@@ -0,0 +1,309 @@
1
+ ---
2
+ sidebar_position: 14
3
+ title: StatusBar
4
+ ---
5
+
6
+ # StatusBar
7
+
8
+ A status bar component that displays row counts, filtered counts, selected counts, and aggregations for selected numeric cells. Rendered below the grid table, above the pagination controls.
9
+
10
+ ## Import
11
+
12
+
13
+ <Tabs groupId="framework">
14
+ <TabItem value="react" label="React">
15
+
16
+ ```typescript
17
+ // or
18
+ // or
19
+ ```
20
+
21
+ </TabItem>
22
+ <TabItem value="angular" label="Angular">
23
+
24
+ ```typescript
25
+ // StatusBar is rendered internally by DataGridTable in Angular packages
26
+ ```
27
+
28
+ </TabItem>
29
+ <TabItem value="vue" label="Vue">
30
+
31
+ ```typescript
32
+ // StatusBar is rendered internally by DataGridTable in Vue packages
33
+ ```
34
+
35
+ </TabItem>
36
+ <TabItem value="js" label="Vanilla JS">
37
+
38
+ ```typescript
39
+ // StatusBar is an internal component in vanilla JS
40
+ ```
41
+
42
+ </TabItem>
43
+ </Tabs>
44
+
45
+ ## Props (React)
46
+
47
+ | Prop | Type | Default | Description |
48
+ |------|------|---------|-------------|
49
+ | `totalCount` | `number` | **Required** | Total row count (unfiltered). |
50
+ | `filteredCount` | `number` | `undefined` | Filtered row count (after filters applied). Omit to hide. |
51
+ | `selectedCount` | `number` | `undefined` | Number of selected rows. Omit or 0 to hide. |
52
+ | `selectedCellCount` | `number` | `undefined` | Number of selected cells in a cell range. Omit or 0 to hide. |
53
+ | `aggregation` | `{ sum, avg, min, max, count }` | `null` | Aggregation values for selected numeric cells. See [Aggregation](#aggregation) below. |
54
+ | `suppressRowCount` | `boolean` | `false` | When true, hides the "Rows: X" label (useful when pagination already shows it). |
55
+
56
+ ## Aggregation
57
+
58
+ When the user selects a range of numeric cells, the status bar can display aggregations:
59
+
60
+ ```typescript
61
+ interface Aggregation {
62
+ sum: number;
63
+ avg: number;
64
+ min: number;
65
+ max: number;
66
+ count: number;
67
+ }
68
+ ```
69
+
70
+ | Field | Description |
71
+ |-------|-------------|
72
+ | `sum` | Sum of all numeric cells in the selection. |
73
+ | `avg` | Average of all numeric cells in the selection. |
74
+ | `min` | Minimum value in the selection. |
75
+ | `max` | Maximum value in the selection. |
76
+ | `count` | Number of numeric cells in the selection. |
77
+
78
+ **Example:** If the user selects a 3×3 range of cells with values `[10, 20, 30, 40, 50, 60, 70, 80, 90]`:
79
+ - `sum: 450`
80
+ - `avg: 50`
81
+ - `min: 10`
82
+ - `max: 90`
83
+ - `count: 9`
84
+
85
+ ## Usage
86
+
87
+ ### Basic Example (React)
88
+
89
+ ```tsx
90
+
91
+ function MyGrid() {
92
+ return (
93
+ <StatusBar
94
+ totalCount={1000}
95
+ filteredCount={250}
96
+ selectedCount={5}
97
+ />
98
+ );
99
+ }
100
+ ```
101
+
102
+ **Output:**
103
+ ```
104
+ Rows: 1,000 | Filtered: 250 | Selected: 5
105
+ ```
106
+
107
+ ### With Cell Selection Aggregation (React)
108
+
109
+ ```tsx
110
+
111
+ function MyGrid() {
112
+ const aggregation = {
113
+ sum: 450,
114
+ avg: 50,
115
+ min: 10,
116
+ max: 90,
117
+ count: 9,
118
+ };
119
+
120
+ return (
121
+ <StatusBar
122
+ totalCount={1000}
123
+ selectedCellCount={9}
124
+ aggregation={aggregation}
125
+ />
126
+ );
127
+ }
128
+ ```
129
+
130
+ **Output:**
131
+ ```
132
+ Rows: 1,000 | Selected Cells: 9 | Sum: 450 | Avg: 50 | Min: 10 | Max: 90
133
+ ```
134
+
135
+ ### Suppress Row Count (React)
136
+
137
+ When pagination controls already show "Showing X to Y of Z rows", you can hide the redundant "Rows: Z" label:
138
+
139
+ ```tsx
140
+
141
+ function MyGrid() {
142
+ return (
143
+ <StatusBar
144
+ totalCount={1000}
145
+ filteredCount={250}
146
+ suppressRowCount={true}
147
+ />
148
+ );
149
+ }
150
+ ```
151
+
152
+ **Output:**
153
+ ```
154
+ Filtered: 250
155
+ ```
156
+
157
+ ## Display Logic
158
+
159
+ The status bar intelligently shows/hides sections based on available data:
160
+
161
+ | Condition | Displayed |
162
+ |-----------|-----------|
163
+ | Always | `Rows: {totalCount}` (unless `suppressRowCount` is true) |
164
+ | `filteredCount` provided and differs from `totalCount` | `Filtered: {filteredCount}` |
165
+ | `selectedCount` > 0 | `Selected: {selectedCount}` |
166
+ | `selectedCellCount` > 0 | `Selected Cells: {selectedCellCount}` |
167
+ | `aggregation` provided | `Sum: X`, `Avg: X`, `Min: X`, `Max: X` |
168
+
169
+ Sections are separated by `|` (pipe) characters.
170
+
171
+ ## Angular Usage
172
+
173
+ In Angular packages, the status bar is rendered internally by `DataGridTable` when `statusBar` is enabled. You don't need to import or use the component directly.
174
+
175
+ ```typescript
176
+
177
+ @Component({
178
+ selector: 'app-my-grid',
179
+ template: `
180
+ <ogrid-datagrid-table [propsInput]="gridProps" />
181
+ `
182
+ })
183
+ export class MyGridComponent {
184
+ ogridService = new OGridService<Product>();
185
+
186
+ constructor() {
187
+ // Enable status bar via props
188
+ this.ogridService.setProps({ statusBar: true });
189
+ }
190
+
191
+ gridProps = this.ogridService.getDataGridProps();
192
+ }
193
+ ```
194
+
195
+ ## Vue Usage
196
+
197
+ In Vue packages, the status bar is rendered internally by `DataGridTable` when `statusBar` is enabled.
198
+
199
+ ```vue
200
+ <template>
201
+ <DataGridTable :grid-props="gridProps" />
202
+ </template>
203
+
204
+ <script setup lang="ts">
205
+
206
+ const { dataGridProps: gridProps } = useOGrid({
207
+ data: products,
208
+ columns: columns,
209
+ getRowId: (item) => item.id,
210
+ statusBar: true, // Enable status bar
211
+ });
212
+ </script>
213
+ ```
214
+
215
+ ## Enabling in OGrid
216
+
217
+ The top-level `OGrid` component accepts a `statusBar` prop:
218
+
219
+ ```tsx
220
+
221
+ // Boolean mode: show with default configuration
222
+ <OGrid statusBar={true} {...props} />
223
+
224
+ // Custom configuration
225
+ <OGrid
226
+ statusBar={{
227
+ totalCount: 1000,
228
+ filteredCount: 250,
229
+ selectedCount: 5,
230
+ suppressRowCount: false,
231
+ }}
232
+ {...props}
233
+ />
234
+ ```
235
+
236
+ When `statusBar` is `true`, the grid automatically computes the counts from the current state.
237
+
238
+ ## Accessibility
239
+
240
+ `StatusBar` implements WCAG 2.1 AA standards with screen reader support for dynamic content announcements.
241
+
242
+ ### ARIA Attributes
243
+
244
+ ```html
245
+ <div role="status" aria-live="polite">
246
+ <span>Rows: 1,000</span>
247
+ <span>Filtered: 250</span>
248
+ <span>Selected: 5</span>
249
+ <span>Sum: 450</span>
250
+ <span>Avg: 90</span>
251
+ </div>
252
+ ```
253
+
254
+ | Attribute | Element | Purpose |
255
+ |-----------|---------|---------|
256
+ | `role="status"` | Status bar container | Identifies region containing status information |
257
+ | `aria-live="polite"` | Status bar container | Announces changes when user is idle (non-intrusive) |
258
+
259
+ ### Screen Reader Support
260
+
261
+ Screen readers announce changes to the status bar:
262
+ - **Initial render:** "Status: Rows 1000, Filtered 250, Selected 5"
263
+ - **Selection change:** "Selected 10"
264
+ - **Filter change:** "Filtered 150"
265
+ - **Aggregation update:** "Sum 450, Average 90, Minimum 10, Maximum 90"
266
+
267
+ The `aria-live="polite"` setting ensures announcements don't interrupt the user's current task. Screen readers wait for a natural pause before announcing status changes.
268
+
269
+ ### Semantic HTML
270
+
271
+ The status bar uses semantic `<span>` elements with clear text labels:
272
+ - "Rows: 1,000" — Total row count
273
+ - "Filtered: 250" — Filtered row count
274
+ - "Selected: 5" — Selected row count
275
+ - "Sum: 450" — Aggregation values
276
+
277
+ No additional ARIA labels are needed because the text content is already descriptive.
278
+
279
+ ### High Contrast Mode
280
+
281
+ - Text remains visible in all high contrast themes
282
+ - Background uses system colors
283
+ - Border uses system `ButtonText` color
284
+
285
+ See the [Accessibility Guide](/docs/guides/accessibility) for complete documentation.
286
+
287
+ ## Styling
288
+
289
+ All UI packages provide default styles matching their design system. The status bar is styled with a subtle background and border-top.
290
+
291
+ **CSS custom properties** (all packages):
292
+ - `--ogrid-header-bg` — Background color (matches header)
293
+ - `--ogrid-border` — Border color
294
+ - `--ogrid-fg` — Foreground text color
295
+
296
+ ## Layout Integration
297
+
298
+ The status bar is rendered inside `DataGridTable` at the bottom, just above the pagination controls (when pagination is enabled).
299
+
300
+ ## Related Components
301
+
302
+ - [DataGridTable](./components-datagrid-table.mdx) — Main grid component that renders the status bar
303
+ - [PaginationControls](./components-pagination-controls.mdx) — Pagination UI below the status bar
304
+ - [OGrid](./ogrid-props.mdx) — Top-level wrapper with `statusBar` prop
305
+
306
+ ## See Also
307
+
308
+ - [Types: IStatusBarProps](./types.mdx#istatusbarprops) — Status bar props reference
309
+ - [Spreadsheet Selection Feature Guide](/docs/features/spreadsheet-selection) — How aggregations are computed
@@ -0,0 +1,299 @@
1
+ ---
2
+ sidebar_position: 4
3
+ title: Grid API
4
+ ---
5
+
6
+ # Grid API
7
+
8
+ The `IOGridApi<T>` interface provides imperative methods for controlling the grid programmatically. Access it via a React ref on the `OGrid` component.
9
+
10
+ ## Accessing the API
11
+
12
+ ```typescript
13
+
14
+ interface Employee {
15
+ id: number;
16
+ name: string;
17
+ department: string;
18
+ }
19
+
20
+ function EmployeeGrid() {
21
+ const apiRef = useRef<IOGridApi<Employee>>(null);
22
+
23
+ const handleClearFilters = () => {
24
+ apiRef.current?.setFilterModel({});
25
+ };
26
+
27
+ return (
28
+ <>
29
+ <button onClick={handleClearFilters}>Clear Filters</button>
30
+ <OGrid<Employee>
31
+ ref={apiRef}
32
+ columns={columns}
33
+ data={data}
34
+ getRowId={(e) => e.id}
35
+ />
36
+ </>
37
+ );
38
+ }
39
+ ```
40
+
41
+ ## IOGridApi&lt;T&gt;
42
+
43
+ ```typescript
44
+ interface IOGridApi<T> {
45
+ setRowData: (data: T[]) => void;
46
+ setLoading: (loading: boolean) => void;
47
+ getColumnState: () => IGridColumnState;
48
+ applyColumnState: (state: Partial<IGridColumnState>) => void;
49
+ setFilterModel: (filters: IFilters) => void;
50
+ clearFilters: () => void;
51
+ clearSort: () => void;
52
+ resetGridState: (options?: { keepSelection?: boolean }) => void;
53
+ getSelectedRows: () => RowId[];
54
+ setSelectedRows: (rowIds: RowId[]) => void;
55
+ selectAll: () => void;
56
+ deselectAll: () => void;
57
+ getDisplayedRows: () => T[];
58
+ refreshData: () => void;
59
+ scrollToRow: (index: number, options?: { align?: 'start' | 'center' | 'end' }) => void;
60
+ getColumnOrder: () => string[];
61
+ setColumnOrder: (order: string[]) => void;
62
+ }
63
+ ```
64
+
65
+ ### Data Methods
66
+
67
+ | Method | Signature | Description |
68
+ |--------|-----------|-------------|
69
+ | `setRowData` | `(data: T[]) => void` | Replaces the grid's data with a new array. Useful for client-side mode when you want to update data imperatively rather than through the `data` prop. |
70
+ | `setLoading` | `(loading: boolean) => void` | Sets the loading state of the grid. When `true`, the grid displays a loading indicator. |
71
+ | `getDisplayedRows` | `() => T[]` | Returns the currently displayed (filtered, sorted, paginated) rows. |
72
+ | `refreshData` | `() => void` | Re-triggers a data fetch. Server-side only; no-op for client-side grids. |
73
+
74
+ ### Column State Methods
75
+
76
+ | Method | Signature | Description |
77
+ |--------|-----------|-------------|
78
+ | `getColumnState` | `() => IGridColumnState` | Returns the current column state including visibility, sort, order, widths, and filters. See [IGridColumnState](#igridcolumnstate) below. |
79
+ | `applyColumnState` | `(state: Partial<IGridColumnState>) => void` | Applies a partial column state. Any fields not included in the object are left unchanged. Useful for restoring saved state. |
80
+ | `getColumnOrder` | `() => string[]` | Returns the current column display order as an array of column IDs. |
81
+ | `setColumnOrder` | `(order: string[]) => void` | Programmatically sets the column display order. |
82
+
83
+ ### Filter Methods
84
+
85
+ | Method | Signature | Description |
86
+ |--------|-----------|-------------|
87
+ | `setFilterModel` | `(filters: IFilters) => void` | Sets the filter state. Pass an empty object `{}` to clear all filters. See [Types](./types) for `IFilters`. |
88
+ | `clearFilters` | `() => void` | Clears all active filters. Shorthand for `setFilterModel({})`. |
89
+ | `clearSort` | `() => void` | Resets the sort to the default (no active sort). |
90
+ | `resetGridState` | `(options?: { keepSelection?: boolean }) => void` | Resets all grid state (filters, sort, and optionally selection). |
91
+
92
+ ### Row Selection Methods
93
+
94
+ | Method | Signature | Description |
95
+ |--------|-----------|-------------|
96
+ | `getSelectedRows` | `() => RowId[]` | Returns an array of selected row IDs. |
97
+ | `setSelectedRows` | `(rowIds: RowId[]) => void` | Sets the selected rows to the given IDs. Any previously selected rows not in the array are deselected. |
98
+ | `selectAll` | `() => void` | Selects all rows in the current data set. |
99
+ | `deselectAll` | `() => void` | Deselects all rows. |
100
+
101
+ ### Virtual Scrolling Methods
102
+
103
+ | Method | Signature | Description |
104
+ |--------|-----------|-------------|
105
+ | `scrollToRow` | `(index: number, options?: { align?: 'start' \| 'center' \| 'end' }) => void` | Scrolls to a specific row by index. Only effective when virtual scrolling is enabled. |
106
+
107
+ ## IGridColumnState
108
+
109
+ Represents the complete column state of the grid. Returned by `getColumnState()` and accepted by `applyColumnState()`.
110
+
111
+ ```typescript
112
+ interface IGridColumnState {
113
+ visibleColumns: string[];
114
+ sort?: { field: string; direction: 'asc' | 'desc' };
115
+ columnOrder?: string[];
116
+ columnWidths?: Record<string, number>;
117
+ filters?: IFilters;
118
+ pinnedColumns?: Record<string, 'left' | 'right'>;
119
+ }
120
+ ```
121
+
122
+ | Name | Type | Description |
123
+ |------|------|-------------|
124
+ | `visibleColumns` | `string[]` | Array of visible column IDs. |
125
+ | `sort` | `{ field: string; direction: 'asc' \| 'desc' }` | Current sort configuration, or `undefined` if no sort is active. |
126
+ | `columnOrder` | `string[]` | Current column display order as an array of column IDs. |
127
+ | `columnWidths` | `Record<string, number>` | Map of column IDs to their current pixel widths. Only includes columns that have been explicitly sized. |
128
+ | `filters` | `IFilters` | Current filter state. |
129
+ | `pinnedColumns` | `Record<string, 'left' \| 'right'>` | Map of column IDs to their pinned position. Only includes columns that are pinned. |
130
+
131
+ ## Save and Restore State
132
+
133
+ A common use case is persisting the grid's column state to `localStorage` so it survives page reloads.
134
+
135
+ ```typescript
136
+
137
+ const STORAGE_KEY = 'employee-grid-state';
138
+
139
+ function EmployeeGrid() {
140
+ const apiRef = useRef<IOGridApi<Employee>>(null);
141
+
142
+ // Restore state on mount
143
+ useEffect(() => {
144
+ const saved = localStorage.getItem(STORAGE_KEY);
145
+ if (saved) {
146
+ try {
147
+ const state: Partial<IGridColumnState> = JSON.parse(saved);
148
+ apiRef.current?.applyColumnState(state);
149
+ } catch {
150
+ // Ignore corrupted state
151
+ }
152
+ }
153
+ }, []);
154
+
155
+ // Save state on any column change
156
+ const handleSaveState = useCallback(() => {
157
+ const state = apiRef.current?.getColumnState();
158
+ if (state) {
159
+ localStorage.setItem(STORAGE_KEY, JSON.stringify(state));
160
+ }
161
+ }, []);
162
+
163
+ return (
164
+ <OGrid<Employee>
165
+ ref={apiRef}
166
+ columns={columns}
167
+ data={data}
168
+ getRowId={(e) => e.id}
169
+ onSortChange={handleSaveState}
170
+ onFiltersChange={handleSaveState}
171
+ onVisibleColumnsChange={handleSaveState}
172
+ onColumnOrderChange={handleSaveState}
173
+ onColumnResized={handleSaveState}
174
+ />
175
+ );
176
+ }
177
+ ```
178
+
179
+ ## Dynamic Data Updates
180
+
181
+ Use `setRowData` and `setLoading` for imperative data updates, such as polling or WebSocket-driven refresh.
182
+
183
+ ```typescript
184
+ function LiveGrid() {
185
+ const apiRef = useRef<IOGridApi<StockQuote>>(null);
186
+
187
+ useEffect(() => {
188
+ const ws = new WebSocket('wss://quotes.example.com');
189
+
190
+ ws.onmessage = (event) => {
191
+ const quotes: StockQuote[] = JSON.parse(event.data);
192
+ apiRef.current?.setRowData(quotes);
193
+ };
194
+
195
+ ws.onopen = () => {
196
+ apiRef.current?.setLoading(false);
197
+ };
198
+
199
+ return () => ws.close();
200
+ }, []);
201
+
202
+ return (
203
+ <OGrid<StockQuote>
204
+ ref={apiRef}
205
+ columns={columns}
206
+ data={[]}
207
+ isLoading={true}
208
+ getRowId={(q) => q.symbol}
209
+ />
210
+ );
211
+ }
212
+ ```
213
+
214
+ ## Programmatic Row Selection
215
+
216
+ ```typescript
217
+ function SelectableGrid() {
218
+ const apiRef = useRef<IOGridApi<Employee>>(null);
219
+
220
+ return (
221
+ <>
222
+ <div>
223
+ <button onClick={() => apiRef.current?.selectAll()}>
224
+ Select All
225
+ </button>
226
+ <button onClick={() => apiRef.current?.deselectAll()}>
227
+ Deselect All
228
+ </button>
229
+ <button
230
+ onClick={() => {
231
+ const selected = apiRef.current?.getSelectedRows() ?? [];
232
+ console.log('Selected IDs:', selected);
233
+ }}
234
+ >
235
+ Log Selection
236
+ </button>
237
+ <button
238
+ onClick={() => {
239
+ // Select specific rows by their IDs
240
+ apiRef.current?.setSelectedRows([1, 3, 5]);
241
+ }}
242
+ >
243
+ Select Rows 1, 3, 5
244
+ </button>
245
+ </div>
246
+ <OGrid<Employee>
247
+ ref={apiRef}
248
+ columns={columns}
249
+ data={data}
250
+ getRowId={(e) => e.id}
251
+ rowSelection="multiple"
252
+ />
253
+ </>
254
+ );
255
+ }
256
+ ```
257
+
258
+ ## Programmatic Filter Control
259
+
260
+ ```typescript
261
+ function FilteredGrid() {
262
+ const apiRef = useRef<IOGridApi<Employee>>(null);
263
+
264
+ const showOnlyEngineering = () => {
265
+ apiRef.current?.setFilterModel({
266
+ department: { type: 'multiSelect', value: ['Engineering'] },
267
+ });
268
+ };
269
+
270
+ const clearFilters = () => {
271
+ apiRef.current?.setFilterModel({});
272
+ };
273
+
274
+ const applyMultipleFilters = () => {
275
+ // Apply column state which includes filters along with other state
276
+ apiRef.current?.applyColumnState({
277
+ filters: {
278
+ department: { type: 'multiSelect', value: ['Engineering', 'Product'] },
279
+ name: { type: 'text', value: 'John' },
280
+ },
281
+ sort: { field: 'name', direction: 'asc' },
282
+ });
283
+ };
284
+
285
+ return (
286
+ <>
287
+ <button onClick={showOnlyEngineering}>Engineering Only</button>
288
+ <button onClick={clearFilters}>Clear Filters</button>
289
+ <button onClick={applyMultipleFilters}>Apply Preset</button>
290
+ <OGrid<Employee>
291
+ ref={apiRef}
292
+ columns={columns}
293
+ data={data}
294
+ getRowId={(e) => e.id}
295
+ />
296
+ </>
297
+ );
298
+ }
299
+ ```