Skip to main content

Quick Start

Build a sortable, filterable, editable data grid in under 50 lines.

Install

npm install @alaarab/ogrid-react-radix

Full Example

import { OGrid, type IColumnDef } from '@alaarab/ogrid-react-radix';

interface Employee {
id: number;
name: string;
department: string;
salary: number;
}

const data: Employee[] = [
{ id: 1, name: 'Alice Johnson', department: 'Engineering', salary: 95000 },
{ id: 2, name: 'Bob Smith', department: 'Marketing', salary: 72000 },
{ id: 3, name: 'Carol Williams', department: 'Engineering', salary: 110000 },
{ id: 4, name: 'David Brown', department: 'Sales', salary: 68000 },
{ id: 5, name: 'Eva Martinez', department: 'Marketing', salary: 78000 },
];

const columns: IColumnDef<Employee>[] = [
{ columnId: 'name', name: 'Name', sortable: true },
{
columnId: 'department',
name: 'Department',
sortable: true,
filterable: { type: 'multiSelect', options: ['Engineering', 'Marketing', 'Sales'] },
},
{
columnId: 'salary',
name: 'Salary',
type: 'numeric',
sortable: true,
editable: true,
valueFormatter: (value) =>
new Intl.NumberFormat('en-US', { style: 'currency', currency: 'USD' }).format(value as number),
},
];

export default function App() {
return (
<OGrid<Employee>
columns={columns}
data={data}
getRowId={(row) => row.id}
defaultPageSize={10}
defaultSortBy="name"
statusBar
aria-label="Employee directory"
/>
);
}
Switching UI libraries

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>

What You Get

With just this code:

  • Sorting -- click column headers to sort ascending/descending
  • Filtering -- click the filter icon on Department to filter by value
  • Inline editing -- double-click any salary cell to edit
  • Numeric formatting -- type: 'numeric' right-aligns; valueFormatter displays currency
  • Pagination, keyboard nav, cell selection, status bar -- all built in

Key Concepts

ConceptDescription
IColumnDef<T>Column config. columnId matches a key on T (or use valueGetter).
getRowIdReturns a unique string | number per row for selection, editing, and re-rendering.
layoutMode'fill' (default) fills container; 'content' sizes to content.

Using the Grid API

import { useRef } from 'react';
import { OGrid, type IOGridApi } from '@alaarab/ogrid-react-radix';

function App() {
const gridRef = useRef<IOGridApi<Employee>>(null);

return (
<>
<button onClick={() => console.log(gridRef.current?.getColumnState())}>
Log State
</button>
<OGrid<Employee> ref={gridRef} columns={columns} data={data} getRowId={(row) => row.id} />
</>
);
}

Next Steps