Wijmo 5 - FlexGrid CustomFilter Popup
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" class="container">
<wj-flex-grid control="grid" items-source="data" allow-resizing="Both">
</wj-flex-grid>
<wj-popup control="customFilter" show-trigger=0 >
<h1>
Custom Filter
</h1>
<button class="wj-hide-ok" ng-click="applyFilter()">
Apply
</button>
<button class="wj-hide-ok" ng-click='removeFilter()'>
Remove
</button>
<button class="wj-hide-ok">
Close
</button>
</wj-popup>
</div>
CSS
.wj-flexgrid {
height: 150px;
margin-top:10px;
}
.activeFocus{
color:red;
}
.wj-flexchart {
height: 300px;
}
JavaScript
// define app, include Wijmo 5 directives
var app = angular.module('app', ['wj']);
// controller
app.controller('appCtrl', function($scope) {
var filterItem;
$scope.cols=[];
// 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
});
}
$scope.applyFilter=function(){
var colNum=filterItem.parentNode.parentNode['wj-cell-index'].col;
var binding=$scope.grid.columns[colNum].binding;
if($scope.cols.indexOf(binding)<0){
$scope.cols.push(binding);
}
console.log('filter applied');
$scope.grid.refresh();
}
$scope.removeFilter=function(){
var colNum=filterItem.parentNode.parentNode['wj-cell-index'].col;
var binding=$scope.grid.columns[colNum].binding;
if($scope.cols.indexOf(binding)>-1){
$scope.cols.splice($scope.cols.indexOf(binding),1);
}
console.log('filter removed');
$scope.grid.refresh();
}
// expose data as a CollectionView to get events
$scope.data = new wijmo.collections.CollectionView(data);
$scope.$watch("grid",function(){
var grid= $scope.grid;
if(grid){
grid.columnHeaders.rows.defaultSize=40;
//add tooltip and highlight the filter icon
grid.updatedLayout.addHandler((s,e)=>{
//get filter icons
var elemList=s.hostElement.querySelectorAll('.wj-glyph-filter');
elemList.forEach((el)=>{
//get binding accociated with column
var cell=el.parentNode.parentNode;
var colNum=cell['wj-cell-index'].col;
var binding=s.columns[colNum].binding;
var lineBR=document.createElement('br');
cell.style.height="100px";
cell.insertBefore(lineBR,cell.firstChild);
var...