Wijmo 5 - AddNew and sorting
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.chart.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">
<h1>Grid Sorting</h1>
<wj-flex-grid items-source="data" control="flex" initialized="init(flex)">
<wj-flex-grid-column binding="country.name" header="Country" data-type="Object" width="150">
<wj-flex-grid-cell-template cell-type="Cell">
<div>
{{$item.country.name}}
</div>
</wj-flex-grid-cell-template>
</wj-flex-grid-column>
<wj-flex-grid-column binding="country2" header="Country2">
<wj-flex-grid-cell-template cell-type="Cell">
<div>
{{$item.country2.name}}
</div>
</wj-flex-grid-cell-template>
</wj-flex-grid-column>
<wj-flex-grid-column binding="sales" header="Sales"></wj-flex-grid-column>
<wj-flex-grid-column binding="expenses" header="Expenses"></wj-flex-grid-column>
<wj-flex-grid-column binding="downloads" header="Downloads"></wj-flex-grid-column>
</wj-flex-grid>
<button type="button" class="btn btn-default" ng-click="sort()">
Sort Country
</button>
</div>
CSS
.wj-flexgrid {
max-height: 250px;
}
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 = [{
name: 'US',
state: 'abc'
},
{
name: 'Germany',
state: 'def'
}];
var data = [];
for (var i = 0; i < countries.length; i++) {
data.push({
country: countries[i],
country2: countries[countries.length -1 -i],
downloads: Math.round(Math.random() * 20000),
sales: Math.random() * 10000,
expenses: Math.random() * 5000
});
}
$scope.init = function(grid){
/* console.log(grid) */;
grid.collectionView.sortConverter = (sd, item, value)=>{
if(sd.property!="country2"){
return value;
}
return item.country2.name;
}
}
// expose data as a CollectionView to get events
$scope.data = new wijmo.collections.CollectionView(data);
$scope.data.sortDescriptions.push(new wijmo.collections.SortDescription('sales','true'));
$scope.sort = function() {
$scope.data.sortDescriptions.clear();
$scope.data.sortDescriptions.push(new wijmo.collections.SortDescription('country.name','true'));
}
});