LIDOR SYSTEMS

Advanced User Interface Controls and Components

IntegralUI Web

Native Angular and AngularJS UI Components


TreeGrid / Loading Animations

Animation Type:


Max columns:
Max rows:
Levels:

When you want to load large data into the TreeGrid, it may take some time during which some notification that loading is in the process is required. This sample shows how to add a loading animation during this process.

There are two types of loading animation presented above: circular and linear, with several different speed levels.

Note   You can change the appearance of loader using CSS. Circular animation uses an image that rotates, and linear animation uses a progress bar. All of these are customizable using CSS styles.

Using controls in right panel, you can add maximum of 100 columns, 100,000 rows with maximum depth of 100 tree levels.

<!DOCTYPE html>

<html>

<head>

<link rel="stylesheet" href="css/integralui.css" />

<link rel="stylesheet" href="css/integralui.treegrid.css" />

<link rel="stylesheet" href="css/themes/theme-flat-blue.css" />

<script type="text/javascript" src="external/angular.min.js"></script>

<script type="text/javascript" src="js/angular.integralui.min.js"></script>

<script type="text/javascript" src="js/angular.integralui.lists.min.js"></script>

<script type="text/javascript" src="js/angular.integralui.treegrid.min.js"></script>

</head>

<body>

<div ng-app="appModule" ng-controller="appCtrl">

<iui-treegrid name="{{gridName}}" class="directive" columns="columns" rows="rows" load-complete="onLoadComplete()"></iui-treegrid>

<div>

<label>Animation Speed: </label>

<select ng-model="animationSpeed" ng-options="speed as speed for speed in speedLevels"></select>

<p class="animation-type">Animation Type:</p>

<label class="animation-type-val"><input type="radio" ng-model="animationType" value="linear" />Linear</label>

<label class="animation-type-val"><input type="radio" ng-model="animationType" value="circular" />Circular</label>

<label class="animation-type-val"><input type="radio" ng-model="animationType" value="none" />None</label><br />

<div style="margin-top:20px" align="center">

<table>

<tr>

<td>Max columns: </td>

<td class="align-left"><input type="number" ng-model="numColumns" min="1" max="100" style="width:75px" integer /></td>

</tr>

<tr>

<td>Max rows: </td>

<td class="align-left"><input type="number" ng-model="numRows" min="1" max="100000" style="width:75px" integer /></td>

</tr>

<tr>

<td>Levels: </td>

<td class="align-left"><input type="number" ng-model="numLevels" min="0" max="100" style="width:75px" integer /></td>

</tr>

</table>

<div align="center" style="margin-top:20px">

<button ng-click="add()" style="width:65px; margin-right:10px">Add</button>

<button ng-click="clear()" style="width:65px">Clear</button>

</div>

<div align="center" style="margin-top:20px">

<button ng-click="expandAll()" style="margin-bottom:5px;width:140px">Expand All</button>

<button ng-click="collapseAll()" style="width:140px">Collapse All</button>

</div>

</div>

</div>

</div>

</body>

</html>

angular

.module("appModule", ["integralui"])

.controller("appCtrl", ["$scope", "IntegralUITreeGridService", "$timeout", function($scope, $gridService, $timeout){

$scope.gridName = "gridSample";

$scope.columns = [];

$scope.rows = [];

 

$scope.speedLevels = [ 'veryfast', 'fast', 'normal', 'slow', 'veryslow' ];

$scope.animationSpeed = $scope.speedLevels[2];

$scope.animationType = 'linear';

 

$scope.numColumns = 25;

$scope.numRows = 10000;

$scope.numLevels = 3;

 

$scope.$watch("animationType", function(newValue, oldValue){

if (newValue != oldValue){

switch (newValue){

case 'linear':

$scope.panelType = 1;

break;

case 'circular':

$scope.panelType = 2;

break;

default:

$scope.panelType = 0;

break;

}

}

});

 

var rowCount = 0;

 

// Make sure each node has a random set of child rows

var getRandomNumber = function(level){

var nCount = 1 + Math.floor(Math.random() * 10);

 

if (level === 0)

{

if ($scope.numLevels == 0)

nCount = $scope.numRows;

else

{

var derivative = 1;

for (var k = 1; k <= $scope.numLevels; k++)

derivative = (derivative * nCount) + 1;

 

nCount = $scope.numRows / derivative + 1;

if (nCount < 1000)

nCount = 1000;

}

}

 

return nCount;

}

 

var addColumns = function(){

for (var j = 0; j < $scope.numColumns; j++){

var column = {

headerText : 'Header ' + (j+1).toString(),

footerText : 'Footer ' + (j+1).toString(),

id: j,

width: 150

};

 

$gridService.addColumn($scope.gridName, column);

}

}

 

// Recursive function for adding root and child rows to the TreeGrid

var addRows = function(parentRow, level){

if (level > $scope.numLevels)

return;

 

var numChilds = getRandomNumber(level);

for (var i = 0; i < numChilds; i++){

if (rowCount < $scope.numRows){

var row = {

text : 'Row ' + (rowCount+1).toString(),

id: rowCount,

expanded : false,

cells: []

};

 

for (var j = 0; j < $scope.columns.length; j++){

row.cells.push({ text: "Item" + (rowCount+1).toString() + j });

}

 

$gridService.addRow($scope.gridName, row, parentRow);

rowCount++;

 

addRows(row, level + 1);

}

}

};

 

// Clear the content of TreeGrid

var clearList = function(){

$gridService.clearColumns($scope.gridName);

$gridService.clearRows($scope.gridName);

rowCount = 0;

}

 

var loadCircular = function(){

var loadTimer = $timeout(function(){

$gridService.suspendLayout($scope.gridName);

 

clearList();

 

// Populate the TreeGrid with data

addColumns();

addRows(null, 0);

 

$gridService.resumeLayout($scope.gridName);

 

$timeout.cancel(loadTimer);

}, 1000);

}

 

$scope.add = function(){

$gridService.beginLoad($scope.gridName, null, { type: $scope.animationType, speed: $scope.animationSpeed, opacity: 0.25 });

 

if ($scope.animationType == 'circular')

loadCircular();

else {

$gridService.suspendLayout($scope.gridName);

 

clearList();

 

// Populate the TreeGrid with data

addColumns();

addRows(null, 0);

 

$gridService.resumeLayout($scope.gridName);

}

}

 

$scope.clear = function(){

$gridService.suspendLayout($scope.gridName);

 

clearList();

 

$gridService.resumeLayout($scope.gridName);

}

 

$scope.expandAll = function(){

$gridService.expand($scope.gridName);

}

 

$scope.collapseAll = function(){

$gridService.collapse($scope.gridName);

}

 

$scope.$watch("numColumns", function(newValue, oldValue){

if (isNaN(newValue))

$scope.numColumns = oldValue;

});

 

$scope.$watch("numRows", function(newValue, oldValue){

if (isNaN(newValue))

$scope.numRows = oldValue;

});

 

$scope.$watch("numLevels", function(newValue, oldValue){

if (isNaN(newValue))

$scope.numLevels = oldValue;

});

 

$scope.onLoadComplete = function(){

$gridService.endLoad($scope.gridName);

}

}]);

.directive

{

border: thin solid #dadada;

width: 600px;

height: 350px;

}

.animation-type

{

margin: 10px 0 10px 0;

padding: 0;

}

.animation-type-val

{

margin: 0 5px;

}

select

{

margin: 5px 0 0 0;

width: 100px;

}

label

{

vertical-align: middle;

}