- <!DOCTYPE html>
- <html>
-
- <head>
- <meta charset="utf-8">
- <title>ZingGrid: Blank Grid</title>
- <script nonce="undefined" src="https://cdn.zinggrid.com/dev/zinggrid-dev.min.js"></script>
- <style>
- body {
- background: #e6e6e6;
- }
-
- zing-grid[loading] {
- height: 172px;
- }
- </style>
- </head>
-
- <body>
-
- <zing-grid caption="Dynamic Data" layout="row" layout-controls>
- </zing-grid>
-
- <script>
- ZingGrid.setLicense(['26ccbfec16b8be9ee98c7d57bee6e498']); // function to mimic data changing
- function shuffleData(arr) {
- const newArr = arr.slice()
- for (let i = newArr.length - 1; i > 0; i--) {
- const rand = Math.floor(Math.random() * (i + 1));
- [newArr[i], newArr[rand]] = [newArr[rand], newArr[i]];
- }
- return newArr
- };
-
- // window:load event for Javascript to run after HTML
- // because this Javascript is injected into the document head
- window.addEventListener('load', () => {
- // Javascript code to execute after DOM content
- const zgRef = document.querySelector('zing-grid');
- let intervalTimeoutId = setInterval(() => {
- fetch('https://cdn.zinggrid.com/datasets/remote-data-recordpath.json')
- .then(res => res.json())
- .then(data => {
- // in this use case our endpoint is not updating so
- // we fake an endpoint update by manipulating the data
- const newData = shuffleData(data.company.employees);
- // update data
- zgRef.setData(newData);
- })
- .catch(err => console.error('--- Error In Fetch Occurred ---', err));
- }, 1000);
-
- });
- </script>
- </body>
-
- </html>
- <!DOCTYPE html>
- <html>
-
- <head>
- <meta charset="utf-8">
- <title>ZingGrid: Blank Grid</title>
- <script src="https://cdn.zinggrid.com/dev/zinggrid-dev.min.js"></script>
- </head>
-
- <body>
-
- <zing-grid caption="Dynamic Data" layout="row" layout-controls>
- </zing-grid>
-
- </body>
-
- </html>
- body {
- background: #e6e6e6;
- }
- // function to mimic data changing
- function shuffleData(arr) {
- const newArr = arr.slice()
- for (let i = newArr.length - 1; i > 0; i--) {
- const rand = Math.floor(Math.random() * (i + 1));
- [newArr[i], newArr[rand]] = [newArr[rand], newArr[i]];
- }
- return newArr
- };
-
- // window:load event for Javascript to run after HTML
- // because this Javascript is injected into the document head
- window.addEventListener('load', () => {
- // Javascript code to execute after DOM content
- const zgRef = document.querySelector('zing-grid');
- let intervalTimeoutId = setInterval(() => {
- fetch('https://cdn.zinggrid.com/datasets/remote-data-recordpath.json')
- .then(res => res.json())
- .then(data => {
- // in this use case our endpoint is not updating so
- // we fake an endpoint update by manipulating the data
- const newData = shuffleData(data.company.employees);
- // update data
- zgRef.setData(newData);
- })
- .catch(err => console.error('--- Error In Fetch Occurred ---', err));
- }, 1000);
-
- });