Loading animation in EJ2 JavaScript Treegrid control

27 Apr 20234 minutes to read

The Tree Grid displays a loading indicator while the data is being fetched and bound to the tree grid during initial rendering, refreshing, and after performing any tree grid actions like sorting, paging and more.

The tree grid supports two indicator types, which can be enabled by setting the loadingIndicator.indicatorType property to Spinner or Shimmer. The default value of the indicator type is Spinner.

In the following sample, the Shimmer indicator is displayed while the tree grid is loading and refreshing when using the remote data.

ej.treegrid.TreeGrid.Inject(ej.treegrid.Page, ej.treegrid.Sort);

var data = new ej.data.DataManager({
  url: 'https://ej2services.syncfusion.com/production/web-services/api/SelfReferenceData',
  adaptor: new ej.data.WebApiAdaptor(),
  crossDomain: true
});
var treeGridObj = new ej.treegrid.TreeGrid({
  dataSource: data,
  hasChildMapping: 'isParent',
  idMapping: 'TaskID',
  parentIdMapping: 'ParentItem',
  treeColumnIndex: 1,
  height: 400,
  allowPaging: true,
  allowSorting: true,
  loadingIndicator: { indicatorType: 'Shimmer' },
  columns: [
      { field: 'TaskID', headerText: 'Task ID', width: 120, textAlign: 'Right' },
      { field: 'TaskName', headerText: 'Task Name', width: 240, textAlign: 'Left' },
      { field: 'StartDate', headerText: 'Start Date', width: 140, textAlign: 'Right', type: 'date', format: 'yMd' },
      { field: 'Duration', headerText: 'Duration', width: 130, textAlign: 'Right' },
      { field: 'Progress', headerText: 'Progress', width: 130 }
  ],
  pageSettings: { pageCount: 3 }
});
treeGridObj.appendTo('#TreeGrid');
<!DOCTYPE html><html lang="en"><head>
    <title>EJ2 Tree Grid</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="Typescript Tree Grid Control">
    <meta name="author" content="Syncfusion">
     <!-- Syncfusion Essential JS 2 Styles -->
    <link rel="stylesheet" href="https://cdn.syncfusion.com/ej2/material.css">
    
    
<style>
    #container {
    visibility: hidden;
}

#loader {
  color: #008cff;
  font-family: 'Helvetica Neue','calibiri';
  font-size: 14px;
  height: 40px;
  left: 45%;
  position: absolute;
  top: 45%;
  width: 30%;
}
</style><script src="https://cdn.syncfusion.com/ej2/25.1.35/dist/ej2.min.js" type="text/javascript"></script>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>

<body>
    
    <div id="container">
        <div id="TreeGrid"></div>        
    </div>

<script>
var ele = document.getElementById('container');
if(ele) {
  ele.style.visibility = "visible";
}   
      </script>
<script src="index.js" type="text/javascript"></script>
</body></html>