Question presented to candidate: "Our admin panel lists 20,000 employees. Build the table: Name, Age, Role, Status and Joined columns, click a header to sort (ascending, descending, then back to the original order), a name search plus Role and Status filters, and it has to stay fast, so only render the rows that are on screen. The header should stay put while the rows scroll."
Requirements:
- 20,000 generated rows, 40px each, in a 440px scroll area with a sticky 40px header row.
- Header buttons cycle a column through ascending, descending and unsorted;
aria-sortreflects the state. - A case-insensitive name search and two select filters that combine; show "N of 20,000 employees" and an empty state.
- Only the visible rows plus 4 of overscan are mounted, whatever the filter or sort.
- Changing a filter or sort scrolls back to the top.
- Table semantics for assistive technology:
role="table",aria-rowcount,aria-rowindexon the rows that exist.
What a strong answer should cover:
- The data pipeline: source rows -> filter -> sort -> window -> DOM, with every stage derived (memoised), not stored.
- Filtering before sorting, sorting a copy, a deterministic tie-break, and the asc/desc/none cycle.
- Typed comparisons (numbers numerically, ISO dates as strings), and pre-lowercased search keys.
- Virtualizing the body while the header stays outside the windowing maths (sticky inside the scroller so horizontal scroll stays aligned), with the header height subtracted from the visible body height.
- Resetting scroll on a new result set and why stale scroll offsets are a bug.
- ARIA for a virtualized table:
aria-rowcountfor the full filtered count andaria-rowindexper rendered row;aria-sorton column headers.
Clarifying questions expected:
- "Is the data all on the client, or do sort and filter happen on the server?"
- "Do we need row selection, column resizing or horizontal scrolling on small screens?"
- "Should sort and filter state survive a reload (for example in the URL)?"
Code / implementation expected: Yes. A table component with derived filtered and sorted views, header sort buttons, filter inputs and a virtualized body. Library names (TanStack Table plus a virtualizer) are worth mentioning but not required.