liveBook · Manning

Filtering

As explained in Build a Website with ChatGPT

Filtering is the operation of selecting and displaying only data records that satisfy a specified criterion.

Filtering selects and displays only the records that match a chosen criterion. On a web page, a drop-down list commonly lets users choose a value from a particular data field. section 13.4.2

For a course catalog, Department and Instructor lists can be populated with unique values from the JSON data. Selecting a value causes JavaScript to replace the displayed records with matching records only. An initial option such as “Department (All)” restores the complete dataset. section 13.4.2

Course catalog filter

Ask for a Department drop-down populated from unique Department values, then request JavaScript that displays only courses matching the selected department. Include an “All” option to show every course again. section 13.4.2 section 13.5

A drop-down list with the ID "Department" and the initial value "Department (All)".
A drop-down list with the ID "Instructor" and the initial value "Instructor (All)".

Use the two drop-down controls as the visible filtering interface, with IDs and all-record initial values. section 13.4.2

Extract all the unique "Department" values and use them to populate the "Department" drop-down list.

Populate a filter control by extracting unique values from its corresponding JSON field. section 13.4.2

When the user selects an item from the "Department" list, repopulate the article element with just the records that match the selected department. If the user selects the first item in the list, repopulate the article element with every record imported from the JSON file.

Handle a selection by repopulating the page with matching records, or with all imported records when the first option is selected. section 13.4.2

How Build a Website with ChatGPT covers it

How deep it goes
Explains unique-value lists, selection handling, and an all-record reset, while deferring advanced implementation details.
Examples
Demonstrates Department and Instructor drop-downs filtering course records from a JSON-backed catalog.
What it assumes
Assumes a JSON dataset with named fields and a basic web-page plan, while supplying generated code for a beginner.
What you can do after
Build it from scratch by prompting for HTML, CSS, and JavaScript that filter JSON records through drop-down selections.
How it connects
Connects filtering with JSON, JavaScript, HTML, searching, and sorting.

Also explained in

Compare how 33 books explain filtering →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Build a Website with ChatGPT. The section links point to the parts of the book it draws on.