Flex Grid Detail
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.chart.min.js"></script>
<script src="http://cdn.wijmo.com/5.latest/controls/wijmo.grid.detail.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">
<h1>Wijmo 5 FlexGrid Row Detail</h1>
<p>This is a <b>FlexGrid</b> control:</p>
<button ng-click="toggle()">Toggle Grid</button>
<div ng-hide="hidden">
<wj-flex-grid items-source="data" style="height: auto;margin-top:10px" control="flex">
<wj-flex-grid-column header="Country" binding="country" width="*"></wj-flex-grid-column>
<wj-flex-grid-detail max-height="250" detail-visibility-mode="{{detailMode}}">
<wj-flex-grid items-source="getDetail($item.country)" height="1000px" headers-visibility="Column">
<wj-flex-grid-column header="Brand" binding="car" width="*"></wj-flex-grid-column>
<wj-flex-grid-column header="Year Founded" binding="founded"></wj-flex-grid-column>
<wj-flex-grid-column header="Revenue" binding="revenue"></wj-flex-grid-column>
</wj-flex-grid>
</wj-flex-grid-detail>
</wj-flex-grid>
</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,Japan,UK'.split(','),
data = [], innerData = [];
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);
$scope.detailMode = wijmo.grid.detail.DetailVisibilityMode.ExpandSingle;
// show grid and restore scroll position
$scope.toggle = function () {
var flex = $scope.flex;
// save scroll position before hiding grid
if (flex && !$scope.hidden) {
$scope.sp = flex.scrollPosition;
}
// toggle visibility
$scope.hidden = !$scope.hidden;
// restore scroll position after showing grid
// (this is required only in IE...)
if (flex && !$scope.hidden) {
setTimeout(function () {
flex.scrollPosition = $scope.sp;
}, 0);
}
}
var viewCollection = {};
$scope.getDetail = function (country) {
var detail = [], cars, founded, revenue;
if(country === 'US'){
cars = 'Chrysler,Ford,General Motors,Tesla'.split(',');
founded = '1925,1903,1908,2003'.split(',');
revenue = '147.5b,156.78b,157.31b,11.8b'.split(',');
for(var j = 0; j <...