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
- The problem
- Clarifying questions
- The requirements menu
- Non-functional requirements
- Core entities
- The API
- The high-level design
- What breaks first
- The deep dives
- Entity fields
- The component other teams build on
- A hundred thousand rows
- Every language, every keyboard
- Variants
- What each level is expected to show
- The 30-second answer
- Quiz
- HubSpot
- Amazon
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
| Ask | Why it matters | A 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 |
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. |
Non-functional requirements
| Requirement | What 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
| Entity | What 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
| Endpoint | Notes |
|---|---|
| The configuration a team writes once. |
| 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. |
| 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 |
| 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 |
The high-level design
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.
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 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?
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: Sorting and formatting for the reader's language
Concepts this guide uses
- Designing a component API
- Where state lives
- List virtualization
- Pagination and infinite scroll
- Accessible widgets
- Sorting and formatting for the reader's language
Sources
- techinterview.org: Building a virtualized data table: sorting, filtering, selection
- W3C ARIA Authoring Practices Guide: Sortable table example
- W3C ARIA Authoring Practices Guide: Grid pattern
- MDN: aria-rowcount
- MDN: aria-rowindex
- MDN: Intl.Collator
- MDN: Intl.DateTimeFormat
- MDN: position (CSS)
- web.dev: Interaction to Next Paint (INP)
- React docs: Sharing state between components
- React docs: Rendering lists
- React docs: memo