Column Chooser
The Column Chooser gives users a dropdown with checkboxes to show or hide columns at runtime. Columns marked required cannot be hidden.
Live Demo
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.
Quick Example
- React
- Angular
- Vue
- Vanilla JS
import { OGrid } from '@alaarab/ogrid-react-radix';
import type { IColumnDef } from '@alaarab/ogrid-react-radix';
interface Person {
id: number;
name: string;
email: string;
age: number;
department: string;
salary: number;
startDate: string;
}
const columns: IColumnDef<Person>[] = [
{ columnId: 'name', name: 'Name', required: true },
{ columnId: 'email', name: 'Email' },
{ columnId: 'age', name: 'Age', type: 'numeric', defaultVisible: false },
{ columnId: 'department', name: 'Department' },
{
columnId: 'salary',
name: 'Salary',
type: 'numeric',
valueFormatter: (v) => `$${Number(v).toLocaleString()}`,
},
{ columnId: 'startDate', name: 'Start Date', defaultVisible: false },
];
function App() {
return (
<OGrid
columns={columns}
data={people}
getRowId={(p) => p.id}
defaultPageSize={10}
/>
);
}
The OGrid component has the same props across all React UI packages. To switch, just change the import:
- Radix (lightweight, default):
from '@alaarab/ogrid-react-radix' - Fluent UI (Microsoft 365 / SPFx):
from '@alaarab/ogrid-react-fluent'— wrap in<FluentProvider> - Material UI (MUI v7):
from '@alaarab/ogrid-react-material'— wrap in<ThemeProvider>
import { Component } from '@angular/core';
import { OGridComponent, type IColumnDef } from '@alaarab/ogrid-angular-material';
interface Person {
id: number;
name: string;
email: string;
age: number;
department: string;
salary: number;
startDate: string;
}
const columns: IColumnDef<Person>[] = [
{ columnId: 'name', name: 'Name', required: true },
{ columnId: 'email', name: 'Email' },
{ columnId: 'age', name: 'Age', type: 'numeric', defaultVisible: false },
{ columnId: 'department', name: 'Department' },
{
columnId: 'salary',
name: 'Salary',
type: 'numeric',
valueFormatter: (v: unknown) => `$${Number(v).toLocaleString()}`,
},
{ columnId: 'startDate', name: 'Start Date', defaultVisible: false },
];
@Component({
standalone: true,
imports: [OGridComponent],
template: `<ogrid [props]="gridProps" />`
})
export class GridComponent {
gridProps = {
columns,
data: people,
getRowId: (p: Person) => p.id,
defaultPageSize: 10,
};
}
Same component API across Angular packages. To switch, just change the import:
- Radix (CDK):
from '@alaarab/ogrid-angular-radix'(default, lightweight) - Angular Material:
from '@alaarab/ogrid-angular-material' - PrimeNG:
from '@alaarab/ogrid-angular-primeng'
All components are standalone — no NgModule required.
<script setup lang="ts">
import { OGrid, type IColumnDef } from '@alaarab/ogrid-vue-vuetify';
interface Person {
id: number;
name: string;
email: string;
age: number;
department: string;
salary: number;
startDate: string;
}
const columns: IColumnDef<Person>[] = [
{ columnId: 'name', name: 'Name', required: true },
{ columnId: 'email', name: 'Email' },
{ columnId: 'age', name: 'Age', type: 'numeric', defaultVisible: false },
{ columnId: 'department', name: 'Department' },
{
columnId: 'salary',
name: 'Salary',
type: 'numeric',
valueFormatter: (v) => `$${Number(v).toLocaleString()}`,
},
{ columnId: 'startDate', name: 'Start Date', defaultVisible: false },
];
const gridProps = {
columns,
data: people,
getRowId: (p: Person) => p.id,
defaultPageSize: 10,
};
</script>
<template>
<OGrid :gridProps="gridProps" />
</template>
Same component API across Vue packages. To switch, just change the import:
- Radix (Headless UI):
from '@alaarab/ogrid-vue-radix'(default, lightweight) - Vuetify:
from '@alaarab/ogrid-vue-vuetify'— wrap in<v-app>for theming - PrimeVue:
from '@alaarab/ogrid-vue-primevue'
import { OGrid } from '@alaarab/ogrid-js';
import '@alaarab/ogrid-js/styles';
const grid = new OGrid(document.getElementById('grid'), {
columns: [
{ columnId: 'name', name: 'Name', required: true },
{ columnId: 'email', name: 'Email' },
{ columnId: 'age', name: 'Age', type: 'numeric', defaultVisible: false },
{ columnId: 'department', name: 'Department' },
{
columnId: 'salary',
name: 'Salary',
type: 'numeric',
valueFormatter: (v) => `$${Number(v).toLocaleString()}`,
},
{ columnId: 'startDate', name: 'Start Date', defaultVisible: false },
],
data: people,
getRowId: (p) => p.id,
pageSize: 10,
});
In this example:
- Name is always visible (cannot be unchecked because
required: true). - Age and Start Date are hidden by default but the user can enable them.
- Email, Department, and Salary are visible by default and can be toggled.
How It Works
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.
Hiding Columns by Default
Set defaultVisible: false on a column definition to hide it when the grid first renders. Users can still show it via the Column Chooser.
{ columnId: 'phone', name: 'Phone', defaultVisible: false }
Preventing Users from Hiding a Column
Set required: true to lock a column as always visible. Its checkbox in the Column Chooser will be disabled.
{ columnId: 'name', name: 'Name', required: true }
Controlled Visibility
For full control over which columns are visible, pass visibleColumns and onVisibleColumnsChange.
function App() {
const [visible, setVisible] = useState<Set<string>>(
new Set(['name', 'email', 'department'])
);
return (
<OGrid
columns={columns}
data={rows}
getRowId={(r) => r.id}
visibleColumns={visible}
onVisibleColumnsChange={setVisible}
/>
);
}
When these props are provided, OGrid uses them instead of its internal visibility state.
Standalone ColumnChooser Component
Each UI package also exports a standalone ColumnChooser component that you can render anywhere in your UI.
import { ColumnChooser } from '@alaarab/ogrid-react-radix';
<ColumnChooser
columns={columns}
visibleColumns={visibleColumns}
onVisibleColumnsChange={setVisibleColumns}
/>
Props Reference
| Type | Field | Description |
|---|---|---|
IColumnMeta | defaultVisible | false to hide on initial render (default: true) |
IColumnMeta | required | true to prevent the user from hiding this column |
IOGridProps<T> | visibleColumns | Controlled Set<string> of visible column IDs |
IOGridProps<T> | onVisibleColumnsChange | Callback when visibility changes: (cols: Set<string>) => void |
Related
- Column Groups -- visibility applies to leaf columns within groups
- Column Pinning -- pinned columns can also be toggled
- Grid API --
getColumnState()/applyColumnState()to save and restore visibility