northwind-customers-js — Northwind Customers (master-detail)
A demo of three vanilla-grid web components where one grid drives the next,
against the same public Northwind OData V4 endpoint as
northwind-orders-js. The grids are stacked in a
chain:
- Customers: every Northwind customer (91 rows).
- Orders of the selected customer.
- Order lines (
Order_Details) of the selected order.
Selecting a row loads the related rows into the next grid. Deselecting it, or selecting another row one level up, empties every grid below it. Everything else each grid does (sort, column filters, search, grouping, persistence) stays its own.
Also:
- Theme switching (14 themes: default / Default Dark / Material / Material Dark / Fiori / Fiori Dark / Carbon / Carbon Dark / Fluent / Fluent Dark / Glow / Glow Dark / Apple / Apple Dark), applied to all three grids and toolbars
- Localization (English / Italian)
- Every grid loads all its matching rows at once (no infinite scroll), so
grouping and group aggregates are available on all three from the
header menu ("Group by this column", "Aggregate ▸"), and a grouping survives
a reload. Northwind answers 20 customers or 200 orders per response with an
@odata.nextLink; the shippedODataDataManagerfollows that chain to the last row (91 customers take 5 requests). For a progressively loaded grid, where grouping is not offered, seenorthwind-orders-js.
No library code is specific to this app: the chain is about 30 lines of
selection-to-filter wiring in modules/master-detail.js
over the shipped ODataDataManager.
The wiring
Each detail grid has its own ODataDataManager with auto-reload on
(setAutoReloadOnConfigChange(true)). A master's vn-grid-selection-changed
event sets the detail's base $filter with setFilter():
customersGrid.addEventListener('vn-grid-selection-changed', (e) => {
customer = e.detail.selectedRows[0] || null;
ordersGrid.clearSelection();
ordersDm.setFilter(ordersFilter(customer, shippingStatus));
});
ordersGrid.addEventListener('vn-grid-selection-changed', (e) => {
const order = e.detail.selectedRows[0];
linesDm.setFilter(order ? `OrderID eq ${order.OrderID}` : NO_ROWS_FILTER);
});
- Last click wins.
setFilter()fires a config change. The detail grid reloads and aborts the load still in flight for the previous selection, so fast clicking always ends on the rows of the last click. - No selection.
NO_ROWS_FILTERis$filter=false, which matches no row. Both detail grids start on it, so on page load they show 0 rows without ever asking for every order or every line. It reloads like a key filter does, so deselecting also aborts an in-flight load. - Cascade reset. A customer change first clears the order selection.
An explicit selection survives a reload, so without it the previous
customer's selected order would keep its lines on screen.
clearSelection()emits only when an order was selected, and that event empties the lines grid through the second listener. - Each detail keeps its own query.
setFilter()replaces only the base$filter. A search term or column filter set on the orders grid stays applied when you pick another customer, and AND-composes with the new key filter for both the rows and the count:(CustomerID eq 'ALFKI') and (contains(ShipName,'berlin') or …). - The shipping status joins the orders' key filter.
ordersFilter()builds the orders' base$filterfrom the customer and the Orders toolbar's All / On time / Late choice (see the Shipped Date notes under Columns):CustomerID eq 'HUNGO'for "All", else(CustomerID eq 'HUNGO') and (<status clause>). With no customer it staysNO_ROWS_FILTER, and a status picked then applies to the next customer without a request. A status change clears the order selection first, like a customer change, since the selected order may not pass the new status. - Only selections drive the next grid. Sorting, filtering or searching the customers grid never reloads the orders. The selection survives those reloads, so if a search hides the selected customer, the orders grid still shows that customer's orders and its toolbar still names them.
CustomerID is a 5-letter string, but the literal still gets the OData
single-quote doubling, so the code stays correct as a copy-paste pattern.
OrderID is an integer and goes without quotes.
Titles and toolbars
Each grid has a title row above its toolbar (.grid-pane__title). The title
of each detail grid names the selection it shows, or asks for one
(modules/master-detail.js):
| Grid | No selection above | Selection above |
|---|---|---|
| Customers | "Customers" | |
| Orders | "Orders: select a customer" | "Orders for {CompanyName}" |
| Lines | "Order lines: select an order" | "Lines of order {OrderID}" |
The grid's own empty-message can't carry this: the grid reads that
attribute once, when it builds its markup. A title too long for its column
(a long company name) is cut with an ellipsis.
Each grid also has its own src/vanilla-grid-toolbar/
with the autonomous row-count <vn-grid-toolbar-status>, a
<vn-grid-toolbar-search> box, and the standard auto-fit / reset /
clear-filters / reload commands, dispatched straight to the grid with no host
wiring.
The Orders toolbar also has a "Shipped [All / On time / Late]" dropdown,
<northwind-shipping-status-filter> (shipping-status-filter.js),
right after the search. Its visible "Shipped" label is a <label> around the
select, so it also names the select. The toolbar ships no dropdown item, so
this is a small custom one, following large-dataset-js's
rows-selector.js:
- A classic script loaded before
vanilla-grid-toolbar.js, so it is defined when the toolbar first clones its template. For the same reason it duck-types thetoolbarContextitem contract instead of extendingwindow.VanillaGridToolbarItem. - A pure emitter: a change dispatches the bubbling
northwind-customers-js:shippingstatuschangeevent (detail: { status: 'all' | 'on-time' | 'late' }), whichmodules/master-detail.jsturns into the orders'$filter. - Disabled while the grid loads or exports (
state.busy || state.isExporting). - The choice lives in the script, not the element, so the fresh instance the toolbar clones on a re-render (new messages, a language push) keeps it. It is not saved: every page load, a language change included, starts at "All".
- Its labels stay in
modules/i18n.js:localizeStaticUiTexts()hands them to the element class (labelsstatic setter), which relabels every instance. English is the fallback. - Independent of the "Clear filters" command, which leaves it as it is.
The toolbar's <vn-grid-toolbar-status-message> only shows a fetch error
("Error loading rows: ..."); the next fetch clears it.
Search
The public Northwind V4 service does not implement OData $search (it
returns HTTP 400), so every manager uses searchMode: 'filter': a contains()
disjunction across these fields, AND-ed with the grid's other filters.
| Grid | Searched fields |
|---|---|
| Customers | CustomerID, CompanyName, ContactName, City, Country |
| Orders | OrderID, Employee.FirstName, Employee.LastName |
| Lines | Product.ProductName, Product.QuantityPerUnit |
OrderID is a number, and the service accepts contains() only on text (it
also rejects cast to a string), so the orders grid passes
buildSearchFieldFilter: an all-digit term matches the Order IDs that start
with it, as a range (1107 → OrderID ge 11070 and OrderID le 11079, every
Northwind Order ID having 5 digits), and any other term leaves OrderID out.
The employee's first and last name are searched as separate fields, so
Anne or Dodsworth matches, Anne Dodsworth does not. The search box's
tooltip labels the two name fields through the grid's i18n map
(colEmployeeFirstName, colEmployeeLastName), since neither has a column.
Each grid carries highlight-search-matches, so the active term is marked in
the matching cells. The grid never highlights inside a renderCell column, so
every renderer that writes text (the Product and Employee names next to their
picture, through renderPictureCell in modules/odata-grid.js, the Shipped
Date badge and the currency and percent columns) writes it with
<vn-grid>.setSearchHighlightedText(), and the term is marked there too.
Data source
Public Northwind OData service, one entity set per grid:
https://services.odata.org/V4/Northwind/Northwind.svc/Customers
https://services.odata.org/V4/Northwind/Northwind.svc/Orders?$filter=CustomerID eq 'ALFKI'&$expand=Employee($select=FirstName,LastName),Shipper,Order_Details
https://services.odata.org/V4/Northwind/Northwind.svc/Order_Details?$filter=OrderID eq 10643&$expand=Product
Each total count comes from the entity set's $count with the same
$filter. The Employee expansion asks for the name only. The public
service ignores $select inside $expand, though, and returns the whole
employee, photo included (about 29 KB of base64 per order); the app does not
read that photo, it shows the ones modules/employee-photos.js fetches once
(see Columns). The Order_Details expansion on the orders feeds
the Order Total and Lines columns.
Page layout
The page has two columns (.layout-column in styles.css): customers above
orders on the left, the order lines alone on the right, the full height of
the page. Unlike the other samples, the page width is not capped at 1680px:
on a wide window it uses the full width, less a 16px gutter on each side, so
the three grids get as much room as possible. Below a 1080px-wide window the two columns no longer fit side by
side, so the three grids stack in a single column instead.
In a half-width column a fetch error in a toolbar can be longer than the room left beside the search box and commands. It is then cut with an ellipsis rather than pushing the commands onto a second toolbar row.
Resizing the grids
Each toolbar and grid pair sits in a .grid-pane. Two splitters
(modules/splitter.js) share the space between the
panes either side of them:
| Splitter | Wide window | Below 1080px |
|---|---|---|
#mastersSplitter |
Customers height against orders height | Same |
#columnsSplitter |
Left column width against lines width | Orders height against lines height |
- Drag a splitter, or focus it (Tab) and press the arrow keys (16px a step, 64px with Shift). Double-click it to split the space evenly again.
- Minimum size. A move stops at each pane's CSS minimum: 480px wide per column, 230px tall per pane, room for the title, the toolbar, the column headers and a few rows. On a window too short for every minimum, the page area scrolls.
- Proportions, not pixels. A split is kept as the two panes'
flex-growratio, so it scales with the window. A move only changes the two panes either side of the splitter. - Persisted. After every move the grow factors of the resized panes are
saved to
localStorageundernorthwind-customers-js:splitterSizes, keyed by paneid(customersPane,ordersPane,linesPane,mastersColumn,linesColumn), and restored on the next page load. Double-click saves the even split too. A grid's reset command (clearPersistedSettings) does not reset them; double-click a splitter instead. - Accessibility. Each splitter is a focusable
role="separator"; the module keeps itsaria-orientationin step with the layout and itsaria-valuenowat the first pane's share, in percent.
Each splitter is a 20px gap with a thin line along its middle and a grip of
two short (16px) parallel bars at its center. Line and grip take the accent of the
active app theme (--splitter-active-color in the themes/app-*.css overlays) on hover,
focus and drag.
Product panel
Click the lens at the start of an order line, or double-click the line, to
open a side panel about its product
(modules/product-panel.js). The lens is a
kind="command" column of the lines grid: its click (or Enter/Space on the
focused lens) fires vn-grid-command, which the module answers for the
productDetails command. The panel shows:
- Card: the category picture, the product name, its category and its ID.
- On this order: unit price, quantity, discount and line total of the line.
- Product: quantity per unit, list price, units in stock and on order, reorder level, discontinued.
- Category: name and description, from the category cache
(
modules/category-pictures.js). - Supplier: company, contact, city, country and phone, fetched when the
panel opens (
Products(<id>)?$expand=Supplier). Opening another line or closing the panel aborts that request. The supplier'sHomePageis left out: Northwind stores Access hyperlink text there (#CAJUN.HTM#), not a URL.
Everything but the supplier comes from the line row itself (its $expand
Product carries every product field), so the panel opens filled. Close it
with the × button, a click on the backdrop or Escape; focus moves to the ×
button on open and back where it was on close (the lens, when the lens opened
it). A backdrop click within 400 ms of opening is ignored, so a double-click
on the lens doesn't close the panel its first click opened. Each app theme sets the
panel's surface and text color (.product-panel in the themes/app-*.css overlays).
The overlays hold only this app's rules and load after the shared app theme,
../_common/themes/app-*.css (see samples/_common/README.md).
Layout
northwind-customers-js/
├── index.html # Three title + toolbar + vn-grid panes in two columns, two splitters, product side panel
├── app.js # Bootstrap, listeners, locale/theme wiring, first loads
├── shipping-status-filter.js # <northwind-shipping-status-filter>: the Orders toolbar's "Shipped [All / On time / Late]" dropdown (classic script)
├── styles.css # Layout: two columns, panes, splitters, product panel (base reused from northwind-orders-js)
├── themes/ # App theme overlays: this app's rules, loaded after ../_common/themes/app-<name>.css
│ ├── app-default.css (.splitter, .grid-pane__title, .product-panel)
│ ├── app-default-dark.css
│ ├── app-material.css
│ ├── app-material-dark.css
│ ├── app-fiori.css
│ ├── app-fiori-dark.css
│ ├── app-carbon.css
│ ├── app-carbon-dark.css
│ ├── app-fluent.css
│ ├── app-fluent-dark.css
│ ├── app-glow.css
│ ├── app-glow-dark.css
│ ├── app-apple.css
│ ├── app-apple-dark.css
│ └── TEMPLATE-app-theme.css # Starting point for a new overlay
├── modules/
│ ├── index.js # Re-exports (barrel, consumed by app.js only)
│ ├── dom-refs.js # data-ref → element map + setTextById
│ ├── i18n.js # Strings + Intl helpers (en-US, it-IT), shared grid formatting
│ ├── theme.js # Theme switcher (all three grids)
│ ├── odata-grid.js # Shared ODataDataManager + grid setup, currency helpers
│ ├── master-detail.js # Selection-to-filter wiring (+ shipping status) + detail titles
│ ├── customers-grid.js # Customers grid
│ ├── orders-grid.js # Orders grid (Employee name, Shipped Date badge, Order Total renderers)
│ ├── shipping-status.js # Shipping status of an order + the matching OData clause (DOM-free)
│ ├── lines-grid.js # Order lines grid (product picture, price, discount, line total renderers)
│ ├── northwind-picture.js # Northwind image (OLE-wrapped BMP) → resampled PNG URL
│ ├── category-pictures.js # The eight categories (name, description, picture), fetched once
│ ├── employee-photos.js # The nine employee photos, fetched once
│ ├── product-panel.js # Product side panel on the lens command or an order-line double-click
│ └── splitter.js # Draggable splitters between the grid panes, positions kept in localStorage
└── README.md
Run
Serve the repository root with any static server (CORS-friendly), then open:
http://localhost:<port>/samples/northwind-customers-js/
The grids connect directly to services.odata.org from the browser; no
backend is required.
Columns
Customers (selection-mode="single", row-key-field="CustomerID")
| Field | Type | Notes |
|---|---|---|
CustomerID |
uid | Row key, hidden (show it from the header menu) |
CompanyName |
string | |
Country |
string | |
City |
string | |
ContactName |
string | |
ContactTitle |
string | |
Address |
string | |
PostalCode |
string | |
Phone |
string | Not sortable |
Orders (selection-mode="single", row-key-field="OrderID")
| Field | Type | Notes |
|---|---|---|
OrderID |
uid | Row key |
OrderDate |
date | Default sort, descending (sort-by="OrderDate:desc") |
ShippedDate |
date | renderCell: the date on a green / yellow / red badge by how it compares with RequiredDate; "Not shipped" when empty, colored against today (see below) |
OrderTotal |
number | renderCell: Σ(UnitPrice × Qty × (1 − Discount)) as USD; not sortable/filterable |
Freight |
number | renderCell: USD |
EmployeeID |
string | renderCell: round photo, then "FirstName LastName" (see below); sorts and filters on the name fields; grouped, its captions read the name too (see below) |
RequiredDate |
date | Hidden (show it from the header menu) |
Shipper.CompanyName |
string | Carrier |
Order_Details.length |
number | Line count; not sortable/filterable |
ShipName |
string | |
ShipAddress |
string | |
ShipCity |
string | |
ShipCountry |
string |
Order lines (selection-mode="noselection", row key
`${OrderID}::${ProductID}` through selection.rowKeyGetter)
| Field | Type | Notes |
|---|---|---|
productDetails (key) |
command | The lens: a leading icon command (command="productDetails") that opens the product panel. Its tooltip command-tooltip="productDetailsCommand" is an i18n key, translated by getCommandTooltip in modules/i18n.js |
ProductID |
uid | Hidden (show it from the header menu) |
Product.ProductName |
string | renderCell: the picture of the product's category, then the name (see below) |
Product.QuantityPerUnit |
string | Hidden (show it from the header menu); still searched |
Quantity |
number | Header "Q.ty" (colQuantityShort), to fit a narrow column |
UnitPrice |
number | renderCell: USD |
Discount |
number | renderCell: percent (the service stores a fraction) |
LineTotal |
number | renderCell: UnitPrice × Qty × (1 − Discount) as USD; not sortable/filterable |
Category pictures. Northwind has no product pictures; each product has a
category (Product.CategoryID, already in the $expand), and each of the
eight categories has a 172x120 Picture. modules/category-pictures.js
fetches them once at startup
(Categories?$select=CategoryID,CategoryName,Description,Picture, about
115 KB); modules/northwind-picture.js strips the 78-byte OLE Object header
Northwind keeps in front of each BMP and resamples the picture once, with a
Lanczos-3 filter, into two PNG blob URLs per category: 102x71 for the 34x24
Product column and 129x90 for the 86x60 product panel picture. Northwind's
BMPs are 4-bit dithered images: Chromium's <img> downscaler leaves the
dither visible as coloured speckles, and on a 2x display the panel would
show the 172x120 BMP unscaled, so every browser would show it. The Product
column shows the picture next to the
name, with the category name as its tooltip. Lines drawn before the pictures
arrive get them through a refresh(); if the fetch fails, the column shows
names only and the error is logged to the console.
Employee photos. The orders grid's Employee column shows the employee's
photo, in a 26px circle, before the name. modules/employee-photos.js
fetches the nine photos once at startup (Employees?$select=EmployeeID,Photo,
about 260 KB) and keeps a blob URL per EmployeeID, decoded and resampled
the same way as the category pictures, to 78x91 (aspect kept; the circle
crops it from the top). A photo that fails to decode is skipped, and that
employee's name shows alone. Orders drawn before the photos arrive get them through
a refresh(); if the fetch fails, the column shows names only.
Employee group captions. Grouping the orders by Employee groups them by
EmployeeID, but each caption names the employee ("Employee: Nancy Davolio —
3 items"): modules/orders-grid.js passes a formatting.formatGroupValue
that reads the name from the group's first row, through
initializeODataGrid({ formatGroupValue }), and leaves every other grouped
column to the grid's own text. Given at construction, it also covers a
grouping restored from storage on reload.
Renderers and grouped columns. setColumnRenderer()
(modules/odata-grid.js) attaches each renderCell after initializeGrid()
through grid.getColumn(key), which also finds a column that is grouped and
therefore not in grid.columns. So after a reload with a saved grouping,
ungrouping brings the Employee column (or any other renderer column) back
with its renderer.
Shipping status. The orders grid's Shipped Date shows on a colored
badge, comparing ShippedDate with RequiredDate (calendar days, from
getShippingStatus() in modules/shipping-status.js). An order not shipped yet
reads "Not shipped" and is measured the same way, with today's date in place
of the Shipped Date:
| Badge | Shipped | Not shipped yet (today) |
|---|---|---|
| Green | On or before the Required Date | Required Date not passed yet |
| Yellow | 1 to 5 days after it (SLIGHTLY_LATE_MAX_DAYS) |
1 to 5 days past it |
| Red | More than 5 days after it | More than 5 days past it |
An order with no Required Date has no badge. The badge's tooltip repeats the status in words ("Shipped 3 days late", "Not shipped, 2 days overdue"), so the color is not the only cue. Customers of the live Northwind service that show each case:
| Customer (ID) | Orders to look at |
|---|---|
Hungry Owl All-Night Grocers (HUNGO) |
10687 yellow (2 days late); 10380 and 10309 red (7 and 6 days late); the rest green |
Berglunds snabbköp (BERGS) |
10280 yellow (1 day late); 10924 red (7 days late); the rest green |
White Clover Markets (WHITC) |
10483 and 10596 yellow (4 days late each); the rest green |
Gourmet Lanchonetes (GOURL) |
10777, 10709 and 10423 red (23, 6 and 18 days late); the rest green |
Ernst Handel (ERNSH) |
11008 and 11072 not shipped: red (Required Dates 1998-05-06 and 1998-06-02) |
Great Lakes Food Market (GREAL) |
11040 and 11061 not shipped: red; 10816 shipped 1 day late: yellow |
LILA-Supermercado (LILAS) |
11065 and 11071 not shipped: red |
Northwind's data ends in 1998, so all 21 of its unshipped orders are long overdue today and show red; a green or yellow "Not shipped" badge never appears against the live service (the Playwright suite covers those cases with a fixed clock).
The Orders toolbar's dropdown filters by the same rule, on the server:
"Late" lists the yellow and red orders, "On time" the green ones, "All"
every order. shippingStatusFilter() in modules/shipping-status.js builds
the clause, with today (T, UTC midnight) for an unshipped order:
| Choice | OData clause |
|---|---|
| Late | (ShippedDate ne null and ShippedDate gt RequiredDate) or (ShippedDate eq null and RequiredDate lt T) |
| On time | (ShippedDate ne null and ShippedDate le RequiredDate) or (ShippedDate eq null and RequiredDate ge T) |
Every Northwind date is at UTC midnight, so "at least one day late" is a
plain gt. A comparison with null is false in OData, so an order with no
Required Date (no badge) is in neither. T is read on each customer or
status change; the toolbar's reload reuses the last filter, so a page left
open past midnight keeps the previous day until the next change.
Notes
- Selection is by pointer or checkbox: the grid has no keyboard shortcut that selects a row. A double-click on a row does not change its selection, so it never reloads the grid below; on an order line it opens the product panel.
- Selections are not restored after a page reload. Each grid's column layout,
sort and column filters are persisted to
localStorage(storage-mode="local") under its ownid, so the three keep separate settings. - Locale changes trigger a full page reload, preserved across reloads via
localStorage. Theme changes apply live, no reload; every page load starts from the code-configured default theme (material). styles.csssetsoverscroll-behavior-y: noneonhtml/body(the host-owed half of the grid's mobile touch contract; seedocs/vanilla-grid/00-index.md, "Mobile / touch integration").