Skip to content

How to design a data table component (frontend)

The first sections are free. The deep dives, level expectations and quiz are part of Pro.

On this page
Asked at
Practice this question

The problem

A data table that other teams drop into their screens: they describe the columns, hand over rows or a way to fetch them, and get sorting, filtering, paging through far more rows than fit on screen, and selection, in any language and for keyboard and screen reader users. The answer turns on two decisions. Columns are configuration, so a team changes what a cell shows without forking the table. And each piece of state (sort, filters, selection, page) runs within the table unless the screen takes it over, in which case the screen receives a change event instead of a surprise. Size is the second half: the table holds a hundred thousand rows, far more than the browser can sort or draw itself, so it keeps a window of rows in the page and hands sort and filter work to the server once a table grows past roughly 10,000 rows.

Clarifying questions

AskWhy it mattersA typical answer

Where do the rows come from: an array already in the browser, or a server that pages them?

An in-memory array can be sorted and filtered on the spot. A server-paged source brings a round trip, a placeholder state, and a rule about where sorting may happen, which is most of the second deep dive.

Both. A team can pass rows, or a data source that fetches a window of rows. The default source calls GET /rows?sort&filters&cursor&limit and gets back rows, a cursor for the next window and the total count.

How big does a table get, in rows and columns?

It decides whether rows can all live in the page and where sorting runs. The thresholds shape the whole design, so get them on the table early.

Up to 100,000 rows and 50 columns. Assume the browser copes with about 10,000 rows on its own; past that the server sorts and filters.

How much do the teams need to change: just the cell content, or the behavior too?

Links in cells need a per-column render function. A team with its own filter panel or a sort kept in the URL needs to own that piece of state, which is a different kind of API than a look-and-feel setting.

All three show up: one team wants links in cells, one stores the sort in the URL so a shared link reopens the same view, one brings its own filter panel.

What does select all mean when the table shows a page of a filtered list: the rows on screen, or everything that matches?

The two meanings differ by orders of magnitude in a large table, and the choice changes what the table has to send to the server and what it announces.

Support both and say which one the person picked. Track an all-matching selection as a flag plus exceptions, not as a list of ids.

Who reads it: which languages, and does it have to work with a keyboard and a screen reader?

Language-aware comparison and formatting, real table markup, keyboard movement between cells and announcements are design decisions from the first step, not a layer added at the end.

Yes to all of it. The same table ships to a keyboard and screen reader user, a reader in Japan and a reader in Germany.

Is editing cells, resizing columns, exporting or charting in scope?

Each one roughly doubles the surface area. Confirming they are out keeps the round on the core: configuration, state ownership, size and access.

Out of scope for today. Editing in place may come up as a follow-up at the end, so keep cell rendering pluggable enough that an editor could sit in a cell later.

The requirements menu

RequirementScopeWhy

Show rows of data in columns that the team using the table configures, with their own cell content

Core

The reason a shared table exists. Without configurable columns and cells each team writes its own.

Sort by a column and filter rows

Core

The two operations people reach for first, and the ones that decide where the data lives, in the browser or on the server.

Page or scroll through far more rows than fit on screen

Core

A table of a hundred thousand rows is the stated size. How rows get into the page is the heart of the second deep dive.

Select one row, several, or all of them

Core

Selection is where redraw cost and the meaning of all show up, so it belongs in the design from the start.

Work in any language, and with a keyboard and a screen reader

Core

A shared component ships to everyone the app ships to. Retrofitting table semantics and keyboard movement later is harder than building them in.

Sort by more than one column at once

Optional

Take it if the account list needs sort by country then name; it adds a priority indicator and a modifier key. Leave it if the round is short: single-column sort shows the same ownership and server questions.

Pin the first column while the rest scroll sideways

Optional

Take it for the 50-column case, where a dense table otherwise loses its row labels. Leave it for tables that fit in the viewport.

Select all rows matching the filter, not just the rows on screen

Optional

Take it if bulk actions matter, and say plainly which meaning the person chose. Leave it if actions are per row, where selecting the visible rows is enough.

Shift-click to select a range of rows

Optional

Take it if people select dozens of rows at a time; it needs an anchor row and works on ids, not positions. Leave it when selection is one or a few rows.

Hide and show columns

Optional

Take it with the dense-table case: fewer columns is the simplest way to fit. Leave it unless column settings also need to persist, which is its own question.

Editing cells in place

Out of scope

Changes the table from a view into a form: validation, undo and conflicting edits. Mention how the cell render hook would host an editor, then move on.

Resizing and reordering columns

Out of scope

Drag handling and remembered widths are their own design. Say where the widths would live and leave it.

Exporting to a file

Out of scope

For a server-paged table the export is better run on the server, which already holds the filtered set; the table would trigger it and show progress. A backend job, not a table feature.

Charts built from the table

Out of scope

A different component that reads the same filtered data. The table should expose the current filters so a chart could use them, nothing more.

Non-functional requirements

RequirementWhat it forces

The table first draws in under 100 milliseconds

The first paint can include just the rows in and around the viewport, so the number of cells built before the first frame stays bounded no matter how many rows exist. For a server-backed source the first draw is the header and a placeholder, not the data. Column render functions run for each visible cell, so a heavy one eats this budget directly.

Scrolling stays at 60 frames a second, even with 100,000 rows

The count of row elements in the page stays roughly constant while scrolling, and the scroll handler does arithmetic, not layout. With fixed row heights, the position of any row is a multiplication; varied heights have to be measured as they appear, which is slower and harder to keep stable.

A sort or filter answers within 200 milliseconds, with a placeholder while the server works

Below roughly 10,000 rows, sorting and filtering run synchronously in the browser and the window redraws. Above that the request goes to the server and the placeholder has to paint within the budget, because the budget is about the response to the click, not the round trip. web.dev's Interaction to Next Paint treats at or below 200 milliseconds as good, and measures from the click to the next frame on screen.

Dates, numbers and text sort and show the way the reader's language expects

A locale prop that feeds a language-aware comparer for text and formatters for dates and numbers. When sorting moves to the server, the server's collation has to agree with what the header claims, or the arrows lie.

Core entities

EntityWhat it holds

Column definition

What a team writes to describe one column: what it shows, whether it sorts and filters, and how to draw its cells.

Row

One record with a stable id; the id is what selection and element keys refer to.

Table state

The pieces a screen may take over one at a time; each works inside the table until a prop for it is passed.

Data source

Either the rows themselves or a function that fetches a window of them for a given sort, filters and cursor.

Row window

The rows currently in memory, keyed by id, with the index range each fetched page covers.

The API

EndpointNotes

Props: columns, rows or a data source, row id key, page size, locale

The configuration a team writes once. columns is the list of column definitions above; rows or a data source decides in-memory versus server mode; the row id key names the stable id; pageSize is how many rows one fetch asks for; locale feeds the comparer and the formatters.

Props for state the parent may own: sort, filters, selection, page; each with its change event

Each prop is optional on its own. Left out, the table keeps that piece in its own state. Passed in, the table renders whatever the parent gives it and reports changes through the matching event, so there is one owner per piece and no second copy to drift.

Events: onSortChange, onFilterChange, onSelectionChange, onPageChange

Our choice: fire these in both modes, whether the table or the parent holds the state, so a screen can mirror the sort into the URL without taking it over. We'd also have onSelectionChange carry the id set and the all-matching flag, so a bulk action knows which meaning the person chose.

Server: GET /rows?sort&filters&cursor&limit → { rows, next_cursor, total_count }

The default data source. The server applies the sort and the filters and returns a window in a stable order; the table shows the rows as they arrive and asks for the next window with next_cursor. total_count sizes the scrollbar and feeds the row total announced to screen readers, adjusted for the header row where the markup counts it.

The high-level design

columns, stateall rowsScreen using tableTableSort headerVisible rows

Step 1 of 4

Columns in, rows drawn

Start with the smallest table that other teams can configure: the screen passes a list of column definitions and an array of rows; the table draws a header from the columns and a body row per record, calling each column's cell renderer. This already gives the first team its links in cells. It breaks in two ways that the next steps answer: it draws all rows, and it keeps sort, filters and selection locked inside, so a screen that wants the sort in the URL has no way in.

columns, localestate it ownschange eventsaria-sortsort, filters,cursorin memoryGET /rowswindow, totalnearby rowssort, selectionScreen using tableTableSort headerScreen readerData sourceBrowser sort andfilterServerRow window by idVisible rowsArrow keys,SpaceColumn renderCellLive region
The whole design

What breaks first

The deep dives

The component other teams build on. Three teams adopt your table: one wants links in cells, one needs the sort mirrored into the URL so that a shared link opens the same view, and one brings its own filter panel. What does your table hand each of them, and who owns the sort when both the table and the screen can change it?

A concept that helps here: Designing a component APIA concept that helps here: Where state lives

A hundred thousand rows. A team points the table at an account list of a hundred thousand rows, sorted by name with a filter on country. What loads, what gets drawn, and where does the sorting happen?

A concept that helps here: List virtualizationA concept that helps here: Pagination and infinite scroll

Every language, every keyboard. The same table ships to someone who uses a keyboard and a screen reader, to a reader in Japan and to a reader in Germany. What changes in how it is built, how it sorts and how it reads out?

A concept that helps here: Accessible widgets

Concepts this guide uses

Sources

  1. techinterview.org: Building a virtualized data table: sorting, filtering, selection
  2. W3C ARIA Authoring Practices Guide: Sortable table example
  3. W3C ARIA Authoring Practices Guide: Grid pattern
  4. MDN: aria-rowcount
  5. MDN: aria-rowindex
  6. MDN: Intl.Collator
  7. MDN: Intl.DateTimeFormat
  8. MDN: position (CSS)
  9. web.dev: Interaction to Next Paint (INP)
  10. React docs: Sharing state between components
  11. React docs: Rendering lists
  12. React docs: memo
Sign in to report a mistake