Docs

Vanilla JS Example

In this article, we provide an outline of the web component (markup) version implementation of the library and how to manipulate that markup with Vanilla JavaScript. We will be building up to a grid that changes data at a set interval.

Usage

  1. Include the following dependencies in your HTML file:
<html>
  <head>
    <script src="path/to/zinggrid.min.js" defer></script>
  </head>
</html>
  1. Create a <zing-grid> component:
<zing-grid></zing-grid>
  1. Configure your grid through attributes:
<zing-grid
  id="example-grid"
  data='[
    {
      "firstName": "John",
      "lastName": "Doe",
      "age": 45
    },
    {
      "firstName": "Jane",
      "lastName": "Doe",
      "age": 44
    },
  ]'
  theme="default"
  caption="Meet the Doe Family">
</zing-grid>
  1. Use JavaScript to change your grid data every second:
const zingGridRef = document.querySelector('#example-grid');
zingGridRef.executeOnLoad(function() {
  setInterval(function() {
    const newData = [
      {
        firstName: 'John Jr.',
        lastName: 'Doe',
        age: Math.floor(15 * Math.random())
      },
      {
        firstName: 'Jane Jr.',
        lastName: 'Doe',
        age: Math.floor(13 * Math.random())
      }
    ];
    zingGridRef.setAttribute('data', JSON.stringify(newData));
  }, 1000);
});

Example

Top

On This Page