Docs

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 but assigning a reference to your grid.

// 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 detail 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 Object's
ZGDataZGEventZGTarget
Information from ZingGrid internal components. Including cell, row, grid and other components.Points to any relevant built in event. ie. 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 till 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>

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

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