Performance
A grid that handles 100 rows fine but chokes at 50,000 isn't production-ready. OGrid ships with three complementary features to handle large datasets without framework-level heroics:
| Feature | Opt-in? | What it does |
|---|---|---|
| CSS Containment | No (automatic) | Browser skips layout and paint for off-screen cells |
| Column Virtualization | Yes | Renders only visible columns — scales to hundreds of columns |
| Web Worker Sort/Filter | Yes | Sort and filter run in a background thread — UI stays responsive |
For rendering only visible rows (usually the most impactful optimization for tall datasets), see Virtual Scrolling.
CSS Containment — you get this for free
Every grid cell already has contain: content applied — you don't configure anything. This tells the browser that what happens inside a cell doesn't affect anything outside it, so it can skip layout and paint work for cells not visible in the viewport.
/* Applied automatically to every body cell */
td.ogrid-cell {
contain: content; /* isolate layout + paint + style */
}
/* Pinned columns use position: sticky — containment relaxed to avoid conflicts */
td.ogrid-cell[data-pinned] {
contain: none;
}
Containment limits how far a change inside one cell spreads, but every rendered row is still in the DOM. Without row virtualization, a grid with defaultPageSize: 'all' mounts every row: 2,000 rows x 20 columns is 40,000 cells, and selecting a cell, sorting or editing then costs hundreds of milliseconds of layout. Turn on row virtualization for anything past a few hundred rows.
Web Worker Sort/Filter — keeps the UI responsive
Sorting 50,000 rows on the main thread can freeze the UI for a visible moment. With workerSort: true, the work happens in a background thread — the grid stays interactive while it processes.
<OGrid
columns={columns}
data={largeDataset} // 50,000 rows
getRowId={(r) => r.id}
workerSort={true}
/>
Full example
- React
import { OGrid } from '@alaarab/ogrid-react-radix';
import type { IColumnDef } from '@alaarab/ogrid-react-radix';
interface Row {
id: number;
name: string;
revenue: number;
region: string;
}
const columns: IColumnDef<Row>[] = [
{ columnId: 'id', name: 'ID', type: 'numeric' },
{ columnId: 'name', name: 'Name', sortable: true },
{ columnId: 'revenue', name: 'Revenue', type: 'numeric', sortable: true },
{ columnId: 'region', name: 'Region', sortable: true },
];
function App() {
return (
<OGrid
columns={columns}
data={largeDataset} // e.g. 50,000 rows
getRowId={(r) => r.id}
workerSort={true}
statusBar
/>
);
}
Same props across all React packages — 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>
Not sure about your data size? Use 'auto'
workerSort: 'auto' uses the worker only when your dataset exceeds 5,000 rows. For smaller datasets it runs synchronously — no overhead, no complexity:
<OGrid workerSort="auto" ... />
This is the right default if you're not sure how large your data will get.
How it works under the hood
- Before sort/filter, the grid extracts a flat value matrix from your row data.
- The matrix is sent to an inline Blob Web Worker via
postMessage. - The worker sorts/filters and returns the resulting row indices.
- The grid re-renders using those indices — no row data is ever copied back, only the index array.
The worker is created once per grid instance and reused for all subsequent sort/filter operations.
When the worker falls back to sync
The worker can't run in every situation. It falls back silently in these cases:
| Situation | Why |
|---|---|
Column has a custom compare function | Functions can't cross the worker boundary |
people filter type | Requires rich object comparison |
Worker API unavailable (old browser, sandboxed iframe) | No Worker API to use |
In all cases, the grid sorts and filters correctly — just on the main thread.
CSP gotcha
The worker uses an inline Blob URL. If your app has a Content-Security-Policy header, add blob: to worker-src:
Content-Security-Policy: worker-src 'self' blob:;
Without it, the browser blocks the worker and the grid falls back to synchronous processing. If you can't change the CSP, workerSort still works — it just runs on the main thread.
Putting it all together
Row virtualization, column virtualization, and worker sort/filter stack together cleanly. For a 100-column, 100,000-row dataset, enable all three:
- React
import { OGrid } from '@alaarab/ogrid-react-radix';
function App() {
return (
<OGrid
columns={columns} // 100 columns
data={data} // 100,000 rows
getRowId={(r) => r.id}
virtualScroll={{
enabled: true, // renders ~30 rows instead of 100,000
rowHeight: 36,
overscan: 5,
columns: true, // renders only visible columns
columnOverscan: 2,
}}
workerSort={true} // sort/filter off the main thread
statusBar
/>
);
}
Same props across all React packages — 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>
Large editable grids
The numbers below come from the repo's large-grid benchmark (npm run bench:large-grid): 2,000 rows x 20 columns, ten of them custom React renderers (badges, avatar stacks, two-line cells), with editing and range selection.
| Setup | First render | Scroll | Click a cell |
|---|---|---|---|
defaultPageSize: 'all', no virtualization | 3.5 to 7.7 s, 40,000 cells | 6 to 22 fps | 0.4 to 2 s |
virtualScroll: { enabled: true, rowHeight: 44 } | 80 to 280 ms, 460 cells | 60 fps on an idle machine | 20 to 60 ms |
A grid stays fast when a change repaints only the rows it touches. Each row is memoized: it re-renders when its own data, selection or editing state changes, or when something every row reads changes identity. The guidelines below keep it that way.
Virtualize, and give rowHeight your real row height
<OGrid virtualScroll={{ enabled: true, rowHeight: 44 }} defaultPageSize="all" ... />
Rows with renderCell or wrapText columns are measured, so mixed heights (a two-line cell next to a one-line cell) don't make the scrollbar drift. Set rowHeight to the common height so unmeasured rows are estimated well.
Keep columns stable
The column definitions, their renderCell/valueGetter/valueFormatter functions and their cellEditorParams are compared by identity. A new columns array repaints every visible row and recomputes column state, so build it once:
// Bad: new columns on every render, and on every data change.
const columns = buildColumns(rows, onOpen);
// Good: columns depend only on things that change how columns look.
const onOpen = useCallback((row: Row) => setOpenId(row.id), []);
const columns = useMemo(() => buildColumns(onOpen), [onOpen]);
Don't derive columns from data. If a renderer or parser needs a lookup built from the rows (for example a name-to-id map), keep it in a ref that the column functions read:
const ownerIds = useRef(new Map<string, string>());
ownerIds.current = useMemo(() => buildOwnerMap(rows), [rows]);
const columns = useMemo(() => [
{ columnId: 'owner', name: 'Owner', valueParser: ({ newValue }) => ownerIds.current.get(String(newValue)) },
], []);
Event callbacks such as onCellValueChanged and onSelectionChange can be inline functions: OGrid reads them through refs, so a new function does not repaint rows.
Make renderers cheap, and memoize the expensive ones
renderCell runs for every visible cell of every row that repaints, so keep it a plain function of the row. Render heavy pieces (avatars, popovers, tooltips) as memoized components keyed on the values they show:
const AvatarStack = React.memo(function AvatarStack({ people }: { people: Person[] }) {
return <span className="avatars">{people.slice(0, 3).map((p) => <Avatar key={p.id} person={p} />)}</span>;
});
const columns = useMemo<IColumnDef<Row>[]>(() => [
{ columnId: 'reviewers', name: 'Reviewed by', renderCell: (r) => <AvatarStack people={r.reviewers} /> },
], []);
Replace edited rows with new objects and leave the others as they are (rows.map((r) => r.id === id ? { ...r, ...patch } : r)), so React.memo children of unchanged rows keep their props. Mount tooltips and popovers on hover or focus, not in every cell, and don't fetch per cell: cache images and lookups outside the renderer.
Know what repaints every row
Some inputs are read by every cell, so a change to them repaints all visible rows. That is expected; just don't trigger them on every keystroke:
- a new
columnsarray, or a newvisibleColumns,columnOrderorpinnedColumns; - a column resize (each drag step), a sort or a filter;
- with
dataValidationsrules, any data change (rules can read other cells); - with
conditionalFormatsrules, any data change (rules such as top 10 and data bars depend on every value); - with
formulas, every recalculation.
A cell edit, paste, fill, undo or a range delete without those features repaints only the rows it changed, plus the rows the selection moves through.
Alignment in mixed cells
A type: 'numeric' column right-aligns its cell content as one box. Plain values sit at the right edge, and so does a custom renderer's root element, with its lines right-aligned inside it:
{
columnId: 'access',
name: 'Access',
type: 'numeric',
renderCell: (r) => (
<span style={{ display: 'block', minWidth: 0 }}>
<span>{r.people}</span>
<span style={{ display: 'block' }}>{r.groups.join(', ')}</span>
</span>
),
}
Both lines end at the right edge. To align part of a numeric cell differently, give the renderer's root the full width and set alignment on its parts:
renderCell: (r) => (
<span style={{ display: 'block', width: '100%' }}>
<span style={{ display: 'block', textAlign: 'right' }}>{r.people}</span>
<span style={{ display: 'block', textAlign: 'left' }}>{r.groups.join(', ')}</span>
</span>
),
Text columns align to the start. For a right-aligned custom cell in a text column, use marginLeft: 'auto' on the renderer's root.
Which features do I actually need?
Start here, add as needed:
| Dataset | Recommended setup |
|---|---|
| < 300 rows, < 20 columns | Nothing. |
| 300 to 10,000 rows | Add row virtualization: virtualScroll: { enabled: true, rowHeight: 36 }. |
| > 10,000 rows | Row virtualization + workerSort: 'auto'. |
| > 30 columns with horizontal scroll | Add columns: true to the virtualScroll config. |
| Very large + very wide | All three: row virtualization, column virtualization, and workerSort: true. |
If you're unsure whether you need column virtualization, open DevTools and look at how many <td> elements render in a single row. If it's more than you can count comfortably, add columns: true.
Props reference
workerSort
| Value | When to use it |
|---|---|
false (default) | Small datasets, or when you have custom compare functions |
true | Large datasets where you want the worker always active |
'auto' | You don't know the data size ahead of time — use this as the safe default |
Column virtualization fields (inside virtualScroll)
| Field | Type | Default | Description |
|---|---|---|---|
columns | boolean | false | Enable column virtualization. Requires row virtualization to also be enabled. |
columnOverscan | number | 2 | Extra columns rendered beyond the visible range on each side (prevents blank flash on fast scroll). |
For the full virtualScroll API, see Virtual Scrolling — Props Reference.
Next steps
- Virtual Scrolling — row virtualization, scroll-to-row, and the full virtualScroll API
- Sorting — configure sortable columns and custom comparators
- Filtering — filter types and server-side filtering
- Server-Side Data — skip client-side processing entirely for the largest datasets
- Column Pinning — pinned columns always render regardless of column virtualization