Wijmo 5 (Angular) - CollapseGroupsToLevel

by Joel Parks

HTML

<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
<script src="http://cdn.wijmo.com/5.latest/controls/wijmo.min.js"></script>
<link rel="stylesheet" href="http://cdn.wijmo.com/5.latest/styles/wijmo.min.css">
<script src="http://cdn.wijmo.com/5.latest/controls/wijmo.grid.min.js"></script>
<script src="http://cdn.wijmo.com/5.latest/controls/wijmo.chart.min.js"></script>
<script src="http://cdn.wijmo.com/5.latest/interop/angular/wijmo.angular.min.js"></script>
<!-- mark this as an Angular application and give it a controller -->
<div ng-app="app" ng-controller="appCtrl">
    
<h1>CollapseGroupsToLevel</h1>

    <p>use the buttons to collapse/expand the tree:</p>
    <div class="btn-group" role="group" aria-label="...">
      <button type="button" class="btn btn-default" ng-click="flex.collapseGroupsToLevel(0)">0</button>
      <button type="button" class="btn btn-default" ng-click="flex.collapseGroupsToLevel(1)">1</button>
      <button type="button" class="btn btn-default" ng-click="flex.collapseGroupsToLevel(2)">2</button>
    </div>    
    
    <wj-flex-grid items-source="data" 
        selection-mode="Row" 
        control="flex"
        initialized="flex.collapseGroupsToLevel(0)"
        loading-rows="loadingData(s,e)"
        format-item="formatItem(s,e)">
    </wj-flex-grid>
    
</div>

JavaScript

// define app, include Wijmo 5 directives
var app = angular.module('app', ['wj']);

// controller
app.controller('appCtrl', function ($scope) {

    // create some random data
    var countries = 'US,Germany,UK,Japan,Italy,Greece'.split(','),
        names = 'Paul,George,Ringo,John'.split(','),
        data = [];
    for (var i = 0; i < 8000; i++) {
        data.push({
            country: countries[i % countries.length],
            name: names[i % names.length],
            downloads: Math.round(Math.random() * 20000),
            sales: Math.random() * 10000,
            expenses: Math.random() * 5000
        });
    }
    
    $scope.formatItem = function(s,e){
    		console.log(e.row);
        console.log(s.collectionView.items[e.row]);
    }

    // expose data as a CollectionView to get events
    var cv = new wijmo.collections.CollectionView(data);
    cv.groupDescriptions.push(new wijmo.collections.PropertyGroupDescription('country'));
    cv.groupDescriptions.push(new wijmo.collections.PropertyGroupDescription('name'));
    $scope.data = cv;
  
  	$scope.loadingData = function(s,e){
    		console.log("The script has started...");
        console.log("Sleeping before row load...")
        
        var start = new Date().getTime();
        var end = start;
        while(end < start + 4000){
        		end = new Date().getTime();
        }
        
        console.log("Rows are loading...")
    }
});