Design a Data Table Component (Front End)
Design a reusable, client-rendered data table for a shared component library. It needs a header that stays visible while rows scroll, horizontal scrolling when the columns do not fit, declarative column definitions, cells that render strings, numbers, dates, images or a consumer's custom content, an optional overall width with sensible default column widths when none are given, and smooth behaviour on thousands of rows. It is for reading and scanning data — admin tools, billing pages, moderation queues — not for spreadsheet-style editing.
Cover the markup choice, the component and column API, the internal state and the layout derived from it, how column widths are resolved with and without a constrained width, how large datasets are rendered, and accessibility. Sorting, filtering, column resizing and frozen columns are extensions to acknowledge, not the core.
To build a paged and sorted table, see Data Table I.
Hints
Hint 1
A semantic <table> with <thead> and <tbody> gives header-to-cell relationships, screen-reader navigation and copy-paste for free; position: sticky on the header cells inside one scroll container keeps the header fixed without a second scroll surface that drifts out of alignment.
Hint 2
Resolve widths as a pipeline: an explicit width wins; otherwise measure a sample of content and clamp by min and max; then, if the container is constrained, shrink the flexible columns proportionally and truncate with an ellipsis. Write the result to <colgroup> with table-layout: fixed so the browser stops re-deciding.
Hint 3
Thousands of rows means virtualisation: a spacer for the total height, only the visible slice plus overscan in the DOM, rows keyed by a stable id rather than index, and the header in the same scroll container so it never scrolls out of step.
Asked at
Sign in to talk to the interviewer — ask what's in scope, what scale to design for, or for a nudge when you're stuck. Conversations save to your account.
Sign in to use the assistant — ask what the problem means, get a hint when you're stuck, or have your current work reviewed. Conversations save to your account.