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:

  1. Customers: every Northwind customer (91 rows).
  2. Orders of the selected customer.
  3. 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:

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);
});

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:

The toolbar's <vn-grid-toolbar-status-message> only shows a fetch error ("Error loading rows: ..."); the next fetch clears it.

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

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:

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