Skip to content

messages

Every text the grid shows or says — « No rows », the sort announcements, a menu’s items — in one language.

TypeGridMessages
RequiredYes
Live update (update())Yes
Angularthe [messages] input
<dz-grid>the messages property
Declared inpackages/dom/src/settings.ts

The grid carries no language of its own: you give it one bundle, { locale, text }. Ready ones come with the package, one import per language and per feature, so a page loads only the texts it uses: EN, FR and AR from @dzgrid/dom/locales/en (fr, ar) for the base, and each feature’s from its own, as EN_FILTERS from @dzgrid/dom/locales/en-filters. Put a feature’s texts into the base’s text.

The bundle’s locale gives the grammar of its sentences (one row, two rows) and, unless locale is set, the formatting of numbers and dates. A bundle missing one of the base’s texts is refused at once: createGrid (or update()) throws a TypeError naming the missing keys; a feature whose texts are missing makes createGrid throw too, naming itself and its keys. Your own bundle can change any text, as grid.label or a boolean column’s cell.yes and cell.no.

Changing the bundle with update() redraws every text, and the cells when the language or its yes and no change.

import { createGrid } from '@dzgrid/dom';
import { filters } from '@dzgrid/dom/filters';
import { EN } from '@dzgrid/dom/locales/en';
import { EN_FILTERS } from '@dzgrid/dom/locales/en-filters';
import { FR } from '@dzgrid/dom/locales/fr';
import { FR_FILTERS } from '@dzgrid/dom/locales/fr-filters';
type Book = { id: string; title: string; pages: number };
const texts = { ...EN, text: { ...EN.text, ...EN_FILTERS.text, 'grid.noRows': 'No books yet' } };
const grid = createGrid<Book>(document.getElementById('books')!, {
rows: [],
columns: [{ id: 'title', header: 'Title' }, { id: 'pages', header: 'Pages', type: 'number' }],
getRowId: (b) => b.id,
messages: texts,
features: [filters()],
});
grid.update({ messages: { ...FR, text: { ...FR.text, ...FR_FILTERS.text } } });