On a B2B admin console's orders grid, should sort, filters and row selection be owned by the grid, by the page, or by the URL?
answer
- map each value, not the component
- view identity versus session intent
- who reads it, how long it lives
- the grid never writes the address
- selection rules on filter change
basics
~20 sDecide per value: sort and filters go in the URL because links, reload and Back must reproduce the view; the page holds the selection that the bulk-actions bar reads; open menus and focus stay inside the grid.
solid answer
~50 sI'd decide per value, not per component. Sort, filters and the page are the view's identity: agents paste links to 'unpaid orders, oldest first', so the page reads them from the URL and writes changes back, and the grid and filter bar receive them and report changes. The selection is shared with the bulk-actions bar and the side panel but means nothing in a colleague's browser, so the page keeps it in memory. Open menus, the focused cell and resize drags stay private to the grid. The grid's contract becomes `rows`, `sort`, `selectedIds` plus change callbacks, and it never touches the address, so it can be embedded elsewhere unchanged. Then one policy out loud: when filters change, clear or prune the selection and show the count, so a bulk action never hits rows the user cannot see.
go deeper
Recall the three homes for a screen's values: inside one component, with the parent that several children share, and in the URL when the view must survive reload or a link.
Build the state map aloud: each value, its readers, its lifetime, its home. Derive the grid's inputs and change callbacks from it rather than starting from the grid.
Show the policies around the map: selection on filter change, what select-all means, history entries while typing, and why the grid must never own the address if it is reused.
Set the rule teams follow across the console: view identity in the address, owned by pages; shared session intent with the nearest owner; and a review check that reusable grids stay free of routing.
## Decide per value, not per component "Should the grid be controlled or uncontrolled?" is the wrong first question. On the orders screen of a B2B web admin console the grid carries several kinds of state, and each kind has different readers and a different lifetime. The design answer is a **state map**: list each value, who reads it, whether it must survive a reload or travel in a link, and give it a home. The grid's contract then falls out of the map. ## The state map for the orders grid | Value | Who reads it | Survive reload or link? | Home | |---|---|---|---| | Filters (status, date range, customer) | filter bar, list query, result count | yes: agents share "unpaid, last 30 days" | URL, read by the page | | Sort column and direction | grid headers, list query | yes | URL, read by the page | | Page or cursor | list query, pager | usually yes | URL, read by the page | | Selected order IDs | grid checkboxes, bulk-actions bar, count | no | page memory | | The one order open in the side panel | side panel, row highlight | yes: a link to one order is useful | URL path or parameter | | Column widths and hidden columns | grid | across sessions, per user | persisted preference | | Open row menu, focused cell, resize drag | grid only | no | inside the grid | Three homes do most of the work: - **The URL** for anything that defines *which view* the user is looking at. A support agent pasting a link, a reload, and the Back button all reproduce the view. The page — not the grid — reads these values from the address and writes changes back. - **The page's memory** for shared values that are session intent rather than view identity. The selection is read by three siblings, so it sits with their common owner, but it would be meaningless in someone else's browser and stale after a refresh. - **Inside the grid** for everything nobody else reads. ## What the grid's contract becomes The grid receives `rows`, `sort`, `selectedIds` and reports `onSortChange` and `onSelectionChange`; it keeps focus, menus and drag state private. Crucially, **the grid never touches the URL itself**. That keeps routing knowledge in the page, so the same grid can be embedded on a customer's orders tab or inside a dialog where its sort and selection live in memory and nothing changes in the grid. ## Selection policies to state out loud Interviewers like candidates who notice that selection has rules, not just a home: 1. **When filters change**, clear the selection or prune it to rows still matching, and show the new count before any bulk action. Silently keeping rows the user can no longer see is how a bulk cancel hits the wrong orders. 2. **"Select all"** must say what it selects: the visible page, or every order matching the filter. The second is better modelled as *the filter plus a list of exclusions*, not thousands of IDs, and the bulk request then carries the filter. 3. **Across pages**, decide whether selection persists and show it in the bar ("12 selected across 3 pages"). ## Why the alternatives fail here - **Everything inside the grid:** the list query cannot see the sort, the bulk bar cannot see the selection, and nothing survives a reload. - **Everything in the URL:** a link carrying dozens of selected IDs selects rows for a colleague who never chose them, and IDs go stale. - **Everything in an app-wide store:** links still do not carry the view, and the selection outlives the screen it belongs to unless someone remembers to clear it. - **Filters in session storage:** each tab restores its own last view, but a pasted link carries nothing, so the sharing requirement is lost. ## Writing the address Typing in a free-text filter should not create a history entry per keystroke. Writing filter edits with a replace of the current history entry, and a new entry for deliberate changes such as switching status tabs, keeps the Back button meaningful. That is a policy choice for the page; how routing writes the address is a mechanism question owned elsewhere.
- The user clicks 'select all'. What exactly is selected?Decide and show it. Either the visible page, which is a list of IDs, or every order matching the filter, which is better held as the filter plus exclusions than as thousands of IDs. The bar says which ('All 4,312 matching orders') and the bulk request carries the filter, so the server applies it to the same set the user saw.
- Should the order shown in the side panel be in the URL, given that the selection is not?Yes. One open order is view identity: a link to it is useful, and reload should reopen it. A multi-row selection is session intent that would be meaningless or stale in someone else's browser. The two look alike on screen but have different readers and lifetimes, so they get different homes.
- A second screen embeds the same grid with no URL-driven filters. Does the grid change?No, if the grid only receives values and reports changes. The embedding screen keeps sort and selection in its own memory. That is the payoff of keeping URL reading in the page: routing knowledge never leaks into the shared grid.
- The grid should read and write the URL itself so every screen gets shareable filters.
- Put the whole selection set in the URL so a refresh keeps it.
- Sort can stay private to the grid even when rows are paged from the server.
- Keep filtered-out rows selected without telling the user they are still selected.
- Session storage makes filtered views shareable between support agents.