Wijmo 5 - Multi-Filter

HTML

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

    <p>
        This sample shows how you can combine filters by using
        the result set of one filter as the source for other
        collections (which in turn have their own filters):
<p>Main filter: <input ng-model="filter"></p>     
<div id="flexGrid"></div>
</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(','),
        data = [];
    for (var i = 0; i < 100; i++) {
        data.push({
            country: countries[i % countries.length],
            downloads: Math.round(Math.random() * 20000),
            sales: Math.random() * 10000,
            expenses: Math.random() * 5000
        });
    }

    // data is the main collection view:
    $scope.data = new wijmo.collections.CollectionView(data);
    $scope.flexGrid = new wijmo.grid.FlexGrid( '#flexGrid' );    
    $scope.flexGridFilter = new wijmo.grid.filter.FlexGridFilter( $scope.flexGrid );
    $scope.flexGrid.initialize( { itemsSource: $scope.data } );
    
    
    // custom filter function based on the "filter" string
    $scope.data.filter = function(item) {
        if ($scope.filter) {
            var country = item.country.toLowerCase();
            var test = $scope.filter.toLowerCase();
            return country.indexOf(test) > -1;
        }
        return true;
    }
    
    // when the "filter" string changes, apply the filter and update 
    // the 'filteredData' collection used as the grid's itemsSource:
    $scope.$watch('filter', function() {
        $scope.data.refresh();
        $scope.flexGrid.itemsSource = $scope.data;
    });

});