Wijmo 5 - Custom Filter Icons
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.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/controls/wijmo.grid.filter.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">
<h2>Custom filter icons</h2>
<wj-flex-grid items-source="data" class="filterColor" initialized="initGrid(s,e)">
<wj-flex-grid-filter initialized="initFilter(s,e)"></wj-flex-grid-filter>
</wj-flex-grid>
<button onclick="filterLoad()">
Load Filter
</button>
<button onclick="filterSave()">
Save Filter
</button>
</div>
CSS
/* show images on filtered columns */
.filterImage .wj-glyph-filter {
background-image:url('http://icons.iconseeker.com/png/fullsize/aspnet/filter-1.png');
background-repeat: no-repeat;
background-position: bottom right;
margin-top: 4px;
width: 1em; height: 1em;
border: none;
}
.filterImage .wj-glyph-filter:after {
display: none;
}
/* make active filter images 25% larger */
.filterImage .wj-filter-on .wj-glyph-filter {
transform: scale(1.25)
}
/* change the color of the filter glyphs */
.filterColor .wj-glyph-filter {
color: red;
font-size: 125%;
}
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 < countries.length; i++) {
data.push({
country: countries[i],
downloads: Math.round(Math.random() * 20000),
sales: Math.random() * 10000,
expenses: Math.random() * 5000
});
}
// expose data as a CollectionView to get events
$scope.data = new wijmo.collections.CollectionView(data);
// cancel mousedown events if the button pressed was not the left one
$scope.init = function(s, args) {
s.hostElement.addEventListener('mousedown', function(e) {
var btn = e.button || e.which;
if ((btn & 1) == 0) {
e.preventDefault();
}
}, true); // attach on capture
s.hostElement.addEventListener('contextmenu', function(e) {
e.preventDefault();
alert('show context menu');
});
}
$scope.initGrid = function(s, e) {
//console.log(s);
}
$scope.initFilter = function(s, e) {
$scope.filter = s;
}
filterLoad = function() {
$scope.filter.filterDefinition = $scope.savedFilter;
}
filterSave = function() {
$scope.savedFilter = $scope.filter.filterDefinition;
}
});