Wijmo 5 - Multi-Filter
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.latest/styles/wijmo.min.css">
<script src="http://cdn.wijmo.com/5.latest/controls/wijmo.min.js"></script>
<script src="http://cdn.wijmo.com/5.latest/controls/wijmo.input.min.js"></script>
<script src="http://cdn.wijmo.com/5.latest/controls/wijmo.grid.min.js"></script>
<script src="http://cdn.wijmo.com/5.latest/interop/angular/wijmo.angular.min.js"></script>
<script src="http://cdn.wijmo.com/5.latest/controls/wijmo.grid.filter.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>
<wj-flex-grid items-source="filteredData">
<wj-flex-grid-filter></wj-flex-grid-filter>
</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(','),
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);
// 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.filteredData = $scope.data.items;
});
// filtered data is the data shown on the grid
$scope.filteredData = $scope.data.items;
});