Skip to content

theme

The theme’s colours and sizes for one grid, from code, with a type that knows every key.

TypeGridTheme
Defaultnot set
Live update (update())Yes
Angularthe [theme] input
<dz-grid>the theme property
Declared inpackages/dom/src/settings.ts

Each key is one CSS variable, written on the grid’s root: the shared palette’s keys become --tz-* (bgRaised → --tz-bg-raised), the others --dzg-* (rowOddBg → --dzg-row-odd-bg). A value is a CSS value ('light-dark(#0f766e, #5eead4)', '0.5rem') or a number written as is (500). Written on the root, it wins over your stylesheets for that grid only; the other grids of the page keep theirs.

It needs the theming() feature from @dzgrid/dom/theme: without it the setting is told as a missing feature and nothing is written. A key the type does not know, or a value that could carry more than a value (a ;, a {, a url(…), is told as an invalid-setting warning and skipped; the other keys apply. Keys that the @dzgrid/theme/variables.css sheet reads need that sheet loaded.

Every key, what it changes and its default: the table of variables.

import { createGrid } from '@dzgrid/dom';
import { theming } from '@dzgrid/dom/theme';
import { EN } from '@dzgrid/dom/locales/en';
import '@dzgrid/theme/dzgrid.css';
import '@dzgrid/theme/variables.css';
type Boat = { id: string; name: string; berth: number };
const grid = createGrid<Boat>(document.getElementById('boats')!, {
rows: [{ id: 'b1', name: 'Sea Lark', berth: 12 }],
columns: [{ id: 'name', header: 'Boat' }, { id: 'berth', header: 'Berth', type: 'number' }],
getRowId: (b) => b.id,
messages: EN,
theme: { rowOddBg: 'color-mix(in srgb, var(--tz-accent) 8%, var(--tz-bg))', headerWeight: 500 },
features: [theming()],
});
grid.update({ theme: { headerCase: 'uppercase' } }); // the whole theme: rowOddBg and headerWeight go back

Alternate rows, lines between columns, a lighter header in capitals: four keys, this grid only.