Wijmo 5 (Angular) - GroupPanel and Group Collapse - JSFiddle

by Joel Parks

HTML

<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
<link rel="stylesheet" href="http://cdn.wijmo.com/5.20153.109/styles/wijmo.min.css">
<script src="http://cdn.wijmo.com/5.20153.109/controls/wijmo.min.js"></script>
<script src="http://cdn.wijmo.com/5.20153.109/controls/wijmo.input.min.js"></script>
<script src="http://cdn.wijmo.com/5.20153.109/controls/wijmo.grid.min.js"></script>
<script src="http://cdn.wijmo.com/5.20153.109/controls/wijmo.grid.grouppanel.min.js"></script>
<script src="http://cdn.wijmo.com/5.20153.109/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">

  <h2>GroupPanel and Filtering</h2>

  Filter: <input ng-model="filter">

  <wj-group-panel grid="ctx.flex" placeholder="Drag columns here to create Groups" max-groups="4">
  </wj-group-panel>
  <wj-flex-grid control="ctx.flex" items-source="ctx.cv" updated-view="updatedView(s,e)">
  </wj-flex-grid>

</div>

CSS

/* CSS for multi-column listBox (note: FlexBox is not supported by IE9) */

.multi-column {
  display: flex;
  flex-wrap: wrap;
  max-width: 430px;
}

.multi-column .wj-listbox-item {
  min-width: 140px;
}

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(','),
        data = [];
    for (var i = 0; i < 10; i++) {
        data.push({
            id: i,
            name: countries[i % countries.length],
            date: new Date(2015, i % 12, i % 25 + 1),
            time: new Date(2015, i % 12, i % 25 + 1, i % 24, i % 60, i % 60),
            country: countries[i % countries.length],
            downloads: Math.round(Math.random() * 20000),
            sales: Math.random() * 10000,
            expenses: Math.random() * 5000,
            checked: i % 9 == 0
        });
    }

		// expose data
		var view = new wijmo.collections.CollectionView(data);
    
    // variables used to check group add / remove
    var descLength = view.groupDescriptions.length;
    $scope.ctx = {
    	flex: null,
      cv: view
    }
    
    // function to collapse / expand the groups
    $scope.updatedView = function(s, e) {
      // check that there are groups
      if( s.collectionView.groupDescriptions.length >= 1){
      	// has a groupDescription been added?
        if((descLength +1) == s.collectionView.groupDescriptions.length){
        	// if so, collapse to level
          $scope.ctx.flex.collapseGroupsToLevel(descLength);
          // update descLength
          descLength = s.collectionView.groupDescriptions.length;
        }
        // if group is removed, collapse to smaller group
        else if((descLength-1) == s.collectionView.groupDescriptions.length){
        	descLength = descLength - 1;
        	$scope.ctx.flex.collapseGroupsToLevel(descLength - 1);
        }
      }
    }
    
    view.filter = function(item) {
    	var f = $scope.filter;
    	if (f && item) {
        f = f.toLowerCase();
      	for (var k in item) {
        	if (wijmo.isString(item[k]) &&...