Skip to content

onEvent

What the grid tells the application: a click, a new sort, a selection, a problem.

Type(e: GridEvent<T>) => void
Defaultnot set
Live update (update())Yes
Angularno input of its own: onEvent is the component’s outputs
<dz-grid>the settings property: el.settings = { onEvent: … }
Declared inpackages/dom/src/settings.ts

A function given every event the grid sends; switch on type. Each event says who caused it (source: the user, your code, the server) and carries what it is about. The main ones:

Event When
rowClicked, cellClicked A row or a cell is clicked.
selectionChanged The selection changes: the selection, its count.
sortChanged, filterChanged, quickChanged, pageChanged The sort, the filters, the search, the page.
columnsChanged, columnResized, pinnedChanged Columns moved, resized, shown, hidden, pinned.
focusChanged The focus moves to another cell.
cellEdited, saveFailed A value is edited; a save failed.
fetchFailed A server’s request failed.
problems Something given to the grid was refused: a bad column, a bad filter, an answer it cannot read.

The full list is the GridEvent type, in the API reference. In Angular each event is an output of <dz-grid> of the same name, (selectionChanged); the Web Component sends it as a DOM event, dzg- and the name in kebab case (dzg-selection-changed). Log problems while you develop: it is where every refusal is told.

import { createGrid } from '@dzgrid/dom';
import { EN } from '@dzgrid/dom/locales/en';
type Tea = { id: string; name: string };
createGrid<Tea>(document.getElementById('teas')!, {
rows: [{ id: 't1', name: 'Smoked oolong' }],
columns: [{ id: 'name', header: 'Tea' }],
getRowId: (t) => t.id,
messages: EN,
onEvent: (e) => {
if (e.type === 'rowClicked' && e.row.kind === 'data') console.log('clicked', e.row.data.name);
if (e.type === 'sortChanged') console.log('sorted by', e.sort);
if (e.type === 'problems') for (const p of e.problems) console.warn('dzgrid', p.code, p.path, p.detail);
},
});