Skip to the page

Search, lists and data · mid

Data table with sort, filter and pagination

A data table is driven by a column config, keeps sort, filter, page and selection as state, and derives the visible rows in a pipeline—filter, then a stable typed sort on a copy, then paginate—with aria-sort on headers and selection stored as a set of ids.

The notes

What you must know

  • Column config: { key, header, sortable, type ('string' | 'number' | 'date'), render?, width? } — the table is generic, not hard-coded.
  • State: sort { key, dir } | null, query/filters, page, pageSize, selected ids (Set).
  • Pipeline (memoised): filter → sort a copy (never sort props in place) → paginate. Numbers compare numerically, strings with localeCompare (numeric: true), nulls last; sort is stable so ties keep their order.
  • Header click cycles asc → desc → none; the header has a button inside <th> and aria-sort='ascending' | 'descending' | 'none'.
  • Selection: a Set of row ids (not indexes); 'select all on this page' with an indeterminate checkbox (checkbox.indeterminate = true is set via a ref).
  • Reset to page 1 when the filter changes; show an empty state with the active filters.
  • Big data: server-side sort/filter/pagination; virtualise rows; sticky header; resizable columns as a stretch.

The red pen

Common traps: mistake → fix

  • Mistake: data.sort(...) on props

    Fix: mutates the parent's array and causes odd bugs.

  • Mistake: Sort numbers as strings

    Fix: '10' before '9'.

  • Mistake: Store selected row indexes

    Fix: wrong rows after sorting or filtering.

  • Mistake: Filter after paginating

    Fix: results hide on other pages.

Easy to hard

Questions interviewers ask, easy to hard

  1. Build a table with sort by any column, a search box and pagination.
  2. Make it config-driven for any dataset.
  3. Add row selection with 'select all'.
  4. 10,000 rows: client or server? Then variable-height virtualisation (Meesho asked this).

Explain it out loud

Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.

Practise by voice

Your first interview is free

Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.

Start your free interview