Learning object 51 of 100
Search and filter interface
Type a query, choose a category and a sort order on a sample catalogue, and see the result of each step: all items, searched, filtered, sorted and paged.
Loading…
What it shows
Search, filtering, sorting and pagination are small pure functions applied in order: search, then filter, then sort a copy, then slice one page. Keeping the query, filters and page in state, resetting to page 1 when they change, and showing a result count and an empty state make the interface predictable.
Guided experiment
- Type "lamp" in the preview and watch the counts for each step.
- Choose the lighting category and sort by price.
- Search for something that does not exist. What does the page show?
Predict
Why reset to page 1 when the query changes?
Related
Lessons: Lesson 74: Filtering, searching and pagination
Projects: Project 9: Shopping Cart Price Calculator
Source: web/assets/js/objects/object-051.js in the companion repository.