Data Table II
The starter generalises Data Table I: a DataTable component takes data and a columns config, pages and sorts any dataset, and is rendered twice, over users and over houses. Add per-column filtering.
Requirements
- A column opts into a filter in its config:
filter: "text"renders a search input in its header cell,filter: "range"renders min and max inputs. - A text filter keeps the rows whose value contains the input, case-insensitively.
- A range filter keeps the rows whose value lies between min and max, inclusive. Either end may be left open.
- An empty or non-numeric input is ignored, and a row must pass every active filter.
- Filtering happens before sorting and paging, the page count follows the filtered rows, a filter change returns to the first page, and an empty result says "No matching rows".
DataTablestays generic: nothing in it mentions users or houses. Check both tables.
Hints
Hint 1
The column config already carries a type; let it also declare its filter. The table keeps every filter value in one object keyed by column key: { name: "al", price: { min: "", max: "400000" } }.
Hint 2
An inactive filter — empty text, or a min or max that is not a number — is no constraint at all, not "match nothing". Normalise each bound to a number or null before comparing.
Hint 3
Filter, then sort, then page: filtering changes the row count that paging depends on, and sorting fewer rows is cheaper. Resetting the page on every filter change keeps the user off a page that no longer exists.
Asked at
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.