Front-End System Design for Large Datasets with Fixed Headers
A deep dive into designing a reusable, high-performance data table component — from virtual scrolling and sticky headers to sorting, filtering, and column resizing.
Data TableVirtual ScrollingSticky HeadersColumn ResizingSortingFiltering
0. What Are We Building?
We are designing a reusable, client-rendered data table component for a shared component library. The table handles large datasets (thousands of rows), keeps the header fixed while scrolling, supports horizontal overflow for many columns, and allows consumers to configure columns declaratively with custom cell renderers. Think of it as the kind of table you would see in AG Grid, MUI Data Grid, or TanStack Table — but we are designing our own from first principles.
The primary use case is reading and scanning tabular data across admin dashboards, analytics views, moderation queues, billing pages, and CRM surfaces. This is not a spreadsheet — no inline editing, no formulas, no cell-level collaboration. It is a read-heavy surface that happens to need sorting, filtering, and column management.
Key Insight
Data tables are one of the most common UI patterns in internal tools, yet they are surprisingly hard to get right. The challenge is not the table itself — it is the interaction between virtualization, column sizing, scroll syncing, and accessibility. Each feature is simple in isolation, but together they create a complex design surface.
1. Requirements & Scoping
Before writing any code, I need to define what this table looks like, what it does, and — just as importantly — what it does not do. The hardest part of system design is knowing what to leave out.
Functional Requirements
Display tabular data with declarative column definitions — header, accessor, renderer, sizing
Fixed header — remains visible while body rows scroll vertically
Horizontal scrolling when column widths exceed container viewport
Row virtualization — render only the visible window for datasets with thousands of rows
Sorting by any column — single-column, toggle ascending/descending/none
Text-based filtering across all visible columns with debounced input
Column resizing via drag handle on column header edges
Custom cell rendering — consumers supply renderers for badges, avatars, links, etc.
Non-Functional Requirements
Performance: 60fps scrolling even with 10,000+ rows and 20+ columns
Accessibility: WCAG 2.1 AA — role=grid, aria-sort, keyboard navigation
Reusability: generic over any data shape, works across product surfaces
Predictable column sizing — natural widths by default, constrained-width mode when bounded
Security: XSS protection for cell data rendered via custom renderers
Out of Scope
Inline editing, formulas, or spreadsheet-style keyboard navigation
Frozen columns, tree rows, grouped rows, or merged cells
Server-side sorting, filtering, or pagination protocol (client-only for v1)
Canvas/webgl rendering as the default renderer
Tip
Start with the non-functional requirements first — they determine your architecture. Virtualization, for instance, is not a feature; it is a performance requirement that cascades into every design decision from row identity to cell rendering.
2. Architecture & High-Level Design
Here is where the rubber meets the road. The architecture revolves around one key decision: do we use native HTML <table> semantics or build a custom <div>-based grid with ARIA roles?
I considered both approaches carefully. Native <table> gives us correct accessibility for free — screen readers already understand headers, rows, and cell relationships without any ARIA annotations. But a div-based approach gives more control over layout, which matters for virtualization. After prototyping both, I chose a hybrid: stay on native table elements for the header-body relationship, but use spacer rows inside <tbody> for windowing. This keeps accessibility semantics intact while still supporting virtualization.
Markup Approach
The table renders inside one bounded scroll container. The scroll container owns both horizontal and vertical overflow. The <thead> uses position: sticky with top: 0 to stay fixed while the body scrolls underneath. I considered splitting the header and body into separate scroll containers, but that creates a scroll-sync problem — any mismatch between the two surfaces shows up as visibly drifting column alignment. A single shared container is simpler and more robust.
A div or grid-style implementation becomes more appropriate only once the component needs absolutely positioned rows, spreadsheet-like keyboard navigation, or aggressive two-axis virtualization. For a read-heavy table with fixed row heights, native table semantics are the better default.
Component Responsibilities
Each piece of the table has a single job, and they compose together through the shared column sizing model.
example.text
Component Role
─────────────────────────────────────────────────
DataTable (root) Coordinates subcomponents, resolves
static vs virtualized mode
ScrollContainer Defines bounded viewport, handles
horizontal + vertical overflow
HeaderRow Sticky row with column labels, sort
triggers, and resize handles
HeaderCell Renders label, sort indicator,
resize handle, aria-sort
VirtualBody Mounts only the visible row window
plus overscan buffer
DataRow Renders one data row with stable key
DataCell Applies default or custom renderer,
alignment, truncation rules
ColumnSizer Computes widths from column model,
handles redistribution, shares via <colgroup>
FilterInput Debounced text field that filters
rows by visible text content
DataTable component hierarchy — single scroll container with sticky header and virtualized body
Warning
Do not split the header and body into separate scroll surfaces. A shared scroll container with a sticky <thead> is simpler and more robust. Two separate scroll surfaces require manual scroll synchronization on every scroll event, and any hiccup shows up as visibly drifting column alignment.
3. Data Model & State Shape
Good data models make the rest of the design easy. Bad data models make every feature feel like a hack. For this table, the data model is a mix of consumer-provided inputs and internally derived layout state. The table should never mutate the caller's row data.
External Input — Row Data & Column Definitions
The two most important external structures are the row collection and the column definition model. Columns are first-class configuration objects, not something inferred from the first row of data. This makes the component much easier to reason about across a large codebase.
Columns as a single array make reordering trivial — you only need to modify the array elements. Approaches that separate header and body cell definitions do not enjoy this benefit.
Internal State
Internally, the component tracks scroll state, column widths, and the visible row window. Everything else is derived.
Derived state is your friend. Total scrollable height, visible row window, and resolved column widths can all be computed from the core inputs. Storing them explicitly risks them getting out of sync.
4. Interface Definition (API)
The API should make the happy path obvious: pass in rows, declare columns, provide a stable row identity, and optionally configure the viewport and sizing behavior. A good table API feels reusable across many product surfaces without requiring every consumer to understand the internal virtualization machinery.
The base design assumes the caller already has row data in memory. But in practice, many tables fetch data from a server. Here is the API contract for the server-paginated extension:
example.ts
GET /api/table/users?page=1&pageSize=50&sort=name:asc&filter=alice
→ Response: {
rows: User[],
total: 1042,
page: 1,
pageSize: 50,
}
→ Headers: X-Total-Count: 1042
// The table stays decoupled from the fetching strategy.
// Consumers wrap it with their data-fetching hook:
function UserTable() {
const { data, isLoading } = useQuery(
["users", page, sortKey, sortDir, filter],
() => fetchUsers({ page, sortKey, sortDir, filter })
);
return <DataTable rows={data?.rows ?? []} columns={COLUMNS} ... />;
}
Note
The getRowId prop is critical for virtualization. In React, it serves the same purpose as the key prop — the component passes it to each row's key. Without a stable identity, rows get reconciled to different underlying records as the scroll window shifts, causing visual glitches.
5. Component Deep Dive
This is where we get our hands dirty. Three features deserve closer attention: virtual scrolling (the performance backbone), the sticky header (the most visible UX detail), and column resizing (the trickiest interaction).
Virtual Scrolling (Windowing)
For datasets with thousands of rows, mounting every row in the DOM is not feasible. The core idea is simple: render only the visible window plus a small overscan buffer. With fixed row height, the math is straightforward:
The top and bottom spacers are invisible rows with aria-hidden="true". They exist solely to preserve the scrollbar height so the browser thinks the full dataset is mounted. The spacer rows should have one cell with colSpan equal to the total column count, no focusable content, and no readable text.
Virtual scrolling window — only visible rows + overscan are mounted in the DOM; top/bottom spacers maintain scrollbar height
Sticky Header Implementation
The sticky header uses native CSS positioning. The <thead> stays fixed with position: sticky; top: 0; z-index: 1 relative to the scroll container. The header cells need an explicit background color so scrolling rows do not bleed through visually. I use a small z-index stack: header cells at 1, resize handles at 2, sort popovers at 3.
Column resizing is the trickiest interaction because it involves mouse tracking, minimum/maximum constraints, and live width updates. Here is the approach I settled on:
The key decision here was to use mousedown on the handle rather than click. The former gives us continuous tracking as the user drags; the latter only fires on release. I also add user-select: none on the table during resize to prevent text selection while dragging.
Sorting
Sorting cycles through three states: none → ascending → descending → none. Clicking a sortable column header toggles to the next state. The sort indicator uses aria-sort so screen readers know the current sort direction.
Three sort indicator states: unsorted (muted arrows), ascending (active up arrow), descending (active down arrow)
Filtering is a text-based search across all visible columns. I debounce the input at 300ms to avoid filtering on every keystroke. The filter function checks if any column's rendered text value contains the query string.
Data flows in one direction: from the consumer into the table, through the derivation pipeline, and out to the rendered rows. The consumer passes rows and column definitions in. The table derives sorted rows, then filtered rows, then the visible window, then the rendered cells.
Each step in the pipeline is a pure function over the previous step's output. This makes the component easy to reason about and test — you can unit test sorting, filtering, and windowing independently without rendering a single DOM element.
Tip
The pipeline architecture means you can easily inject or skip steps. If a consumer does not need filtering, the filter step is a no-op identity function. If they need server-side sorting, they can disable client sorting and pass pre-sorted rows.
7. Performance Optimization
Performance is not an afterthought for a data table — it is the whole point. Here is how we ensure smooth scrolling even with 10,000 rows and dozens of columns.
Virtualization
The biggest win is row virtualization. With fixed row height, the visible window math runs in O(1). For a dataset of 10,000 rows with a viewport that shows 20 rows, we mount ~26 rows (20 visible + 6 overscan) instead of 10,000. That is a 385x reduction in DOM nodes.
Memoization
Every step in the data pipeline is wrapped in useMemo or useCallback. Sorted and filtered rows only recompute when their dependencies change. The visible window only recomputes on scroll. Cell renderers use React.memo with shallow comparison so they do not re-render when parent components update.
Column sizing is one of the hardest parts of this problem. The component supports two modes: natural width (unconstrained) and fixed width (bounded viewport). The sizing algorithm:
1. Start with explicit width values
2. For columns without explicit widths, estimate from header text + sample
3. Clamp every preferred width by minWidth / maxWidth
4. Sum to get natural table width
5. Compare natural width vs viewport width:
a. Viewport larger → distribute extra space to flexible columns
b. Viewport smaller → shrink flexible columns proportionally
c. Still too wide → keep horizontal scrolling
table-layout: fixed
Once the component computes explicit column widths, table-layout: fixed makes rendering O(columns) per row instead of letting the browser scan content to decide widths. This keeps sticky-header alignment, virtual row insertion, and truncation behavior consistent at scale.
Key Insight
Always pair computed column widths with table-layout: fixed. Auto layout can silently diverge from the shared width map as new rows mount, especially after virtualization swaps rows in and out.
CDN Caching
The table component itself is static — it changes only between deploys. The JavaScript bundle gets Cache-Control: public, max-age=31536000, immutable. Row data fetched from the API uses a shorter cache with stale-while-revalidate, so users see previously cached data immediately while fresh data loads in the background.
8. Security Considerations
Data tables display user-generated content, which means they are a prime target for XSS attacks. Here is how we defend against the most common threats.
XSS in Cell Data
By default, cell data is rendered as text with String(value). React's JSX auto-escapes text content, so plain strings are safe. The risk comes from custom renderers — if a consumer writes a renderer that uses dangerouslySetInnerHTML or injects unsanitized HTML, that is a problem. We document this in the API contract: renderers receive raw values and should sanitize them using a library like DOMPurify before rendering HTML.
// Unsafe — never do this
renderCell: (val) => <div dangerouslySetInnerHTML={{ __html: val }} />
// Safe — React escapes text by default
renderCell: (val) => <span>{val}</span>
// Safe — sanitize before injecting HTML
import DOMPurify from "dompurify";
renderCell: (val) => (
<div dangerouslySetInnerHTML={{ __html: DOMPurify.sanitize(val) }} />
);
CSRF Protection for Server Operations
When the table triggers server-side actions (e.g., batch delete, status update), we require CSRF tokens. The API endpoints check for a valid X-CSRF-Token header. The token is generated server-side, embedded in the page, and included in every mutating request.
Input Validation
The filter input prevents SQL injection-style attacks by treating the query as a plain string comparison — no eval, no regular expression injection, no server-side query building from user input. The component never sends raw filter text to a database; it stays entirely on the client.
Warning
Never trust cell data from unknown sources. Even if React escapes text by default, custom renderers bypass that protection. Validate that renderers do not use dangerouslySetInnerHTML unless they also sanitize their input.
9. Testing Strategy
Testing a data table means testing three layers: the pure data pipeline, the component rendering, and the scroll interactions.
Unit Tests — Pure Functions
The sorting, filtering, and windowing functions are pure — they take inputs and return outputs with no side effects. These are the easiest things to test and catch the most bugs.
describe("sortRows", () => {
it("sorts ascending by name", () => {
const result = sortRows(USERS, "name", "asc", COLUMNS);
expect(result[0].name).toBe("Alice");
expect(result[result.length - 1].name).toBe("Charlie");
});
it("handles null values", () => {
const result = sortRows(USERS_WITH_NULL, "email", "asc", COLUMNS);
expect(result[0].email).toBeNull(); // nulls go last
});
it("returns same array when sortKey is null", () => {
const result = sortRows(USERS, null, null, COLUMNS);
expect(result).toBe(USERS);
});
});
describe("computeVisibleWindow", () => {
it("computes correct window for top of list", () => {
expect(computeVisibleWindow(0, 600, 48, 1000, 3))
.toEqual({ visibleStart: 0, visibleEnd: 15 });
});
it("clamps to row count at bottom", () => {
const scrollTop = 48 * 997;
expect(computeVisibleWindow(scrollTop, 600, 48, 1000, 3))
.toEqual({ visibleStart: 994, visibleEnd: 999 });
});
});
Integration Tests — Component Rendering
Integration tests render the DataTable with mock data and verify the correct number of rows appear, sorting updates the DOM, and filtering hides unmatched rows.
I run axe-core audits on every render of the table. The test fails if any WCAG violation is found — missing ARIA attributes, insufficient color contrast, or missing focus indicators.
Tip
Test the virtualized scroll behavior. Create a dataset with 100+ rows, scroll to the bottom, and verify that the correct rows are rendered. Also test that spacer rows are not focusable via Tab — keyboard users should never land on an invisible spacer.
10. Accessibility
A data table that is not accessible is a table that excludes people. Here is how we make sure everyone can use it.
Semantic HTML: We use <table>, <thead>, <th scope='col'>, and <tbody>. Screen readers get header-to-cell relationships for free — no ARIA needed for the basic structure.
aria-sort: Each sortable header sets aria-sort="ascending", "descending", or "none". Screen readers announce the current sort direction.
Keyboard Navigation: Tab moves between interactive elements (sort headers, resize handles). The filter input is first in tab order. Column headers are reachable via Tab and activate with Enter.
aria-rowcount / aria-colcount: When virtualization is active, these attributes tell screen readers the total logical row and column count, not just the mounted window.
aria-busy: When loading is true, the table container gets aria-busy="true" so assistive technologies know content is updating.
Focus Management: After sorting, focus stays on the activated header. After filtering, focus stays in the filter input. The user never gets unexpectedly moved.
Empty/Error State: These are rendered as full-width rows with colSpan equal to the total column count, preserving the table context.
Spacer Rows: Top and bottom spacer rows have aria-hidden="true" and no focusable content. They are a pure layout artifact.
Accessibility is not a feature — it is a baseline. I test every table by navigating with the keyboard alone. Tab through headers, activate sort, tab to the filter input, type a query. If I can complete every action without a mouse, it is accessible enough.
Live Demo
Alright, enough theory. Here is the data table running live in your browser. Scroll through thousands of rows, click a header to sort, type in the filter box, drag column edges to resize. Everything we talked about is running right here.
Keyboard shortcut: Tab to focus the filter input, Tab to move to column headers, Enter to toggle sort. Try it without touching your mouse.
Editable example loads when this section enters view.
11. Key Takeaways
If you take away nothing else from this article, remember these seven things:
Native table semantics, not div soup
For a read-heavy surface, <table> gives correct accessibility for free. Switch to div + ARIA only when you need spreadsheet-level interactivity.
One scroll container to rule them all
Shared scroll surface with sticky <thead>. Never split header and body into separate scrollers — you will regret the scroll-sync bugs.
Fixed row height is a superpower
It makes virtual window math O(1), simplifies scrollbar calculation, and keeps cell truncation predictable. Variable heights are an expensive extension.
table-layout: fixed is your friend
Once you own the width map, fixed layout makes rendering O(columns) and keeps header and body perfectly aligned.
Derive, do not store
Sorted rows, filtered rows, visible window, column widths — all derived from source data + interaction state. Less duplication, fewer bugs.
Columns are first-class citizens
A single array of ColumnDef objects makes reordering, adding, and removing columns trivial. Avoid APIs that separate header from cell definitions.
Always test the unstable states
Empty dataset, loading state, error state, 1-row result, 10,000-row dataset. These edge cases are where most table bugs live.