API Events Usage

ZingGrid comes with its own set of events that work similarly to modern event handlers. Many of these events help signal when the grid or its components are rendered, or when an interaction occurs.

Events Usage

ZingGrid events have to be added after ZingGrid is available in the DOM. You can do this by assigning a reference to your grid, like so:

// Grab reference to grid        
  const zgRef = document.querySelector('zing-grid');

These events are added like native events and the best practice is to use addEventListener. In the example below, we attach the record:click event to demonstrate how to properly add an event in ZingGrid.

const zgRef = document.querySelector('zing-grid');
zgRef.addEventListener('record:click', (e) => {
  // destruct e.detail object for ZingGrid information
  const { ZGData, ZGEvent, ZGTarget } = e.detail;
  console.log('--- Event Details ---\n', ZGData, ZGEvent, ZGTarget);

All event details can be accessed through e.detail. Most events will return the following object structure:

e.detail: {
    // Information from ZingGrid internal components. 
    ZGData: {...},
    // Points to any relevant built in event. 
    ZGEvent: {...},
    // Points the DOM element the event actually happened on. 
    ZGTarget: {...},
e.detail Objects
Information from ZingGrid internal components, including cell, row, grid, and other components.Points to any relevant built-in event (i.e., the actual click event in the case of cell:click).A reference to the DOM object relative to that action (e.g., cell, row, grid).

If you need to wait until everything in the grid is ready (typically when running set methods on the grid), you will use zgRef.executeOnLoad() to determine synchronous actions on the grid.

Note that ZingGrid events are not compatible with on-tag event attributes or direct bound events. Therefore, the following examples will not work:

Adding an event handler as an attribute:

<zing-grid onclick="click"></zing-grid>

<script> function click() { alert('Click!'); } </script>

Binding events directly (as opposed to using a modern event listener):

document.querySelector('zing-grid').onrender = function click() { 
On This Page