Wijmo 5 - PivotPanel Custom Layout
by runninghare
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.filter.min.js"></script>
<script src="http://cdn.wijmo.com/5.latest/controls/wijmo.olap.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>PivotPanel with Custom Layout</h1>
<p>
This is a <b>PivotPanel</b> control with a custom layout. The layout
was created by changing the <b>PivotPanel.controlTemplate</b>
property.
</p>
<wj-pivot-panel id="panel" items-source="data" control="thePanel">
</wj-pivot-panel>
<wj-pivot-grid items-source="thePanel">
</wj-pivot-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 = [
{country: "Australia", downloads: 0, sales: 1000},
{country: "Australia", downloads: 0, sales: 2000},
{country: "US", downloads: 200, sales: 50},
{country: "US", downloads: 100, sales: null},
]
var width;
$scope.$watch(function(){
var panel= $scope.thePanel;
if(panel){
window.onresize=function(){
setTimeout(function(){
updatePanel(panel);
},10);
}
document.querySelector('[wj-part="d-fields"]').style.maxWidth="95%";
setTimeout(function(){
width= document.querySelector('[wj-part="cells"]').style.width;
updatePanel(panel);
},50);
panel.updatedView.addHandler(function(s,e){
updatePanel(panel);
});
}
})
function updatePanel(panel){
var rows= panel.hostElement.querySelectorAll(".wj-row");
rows.forEach(function(row){
var label= row.querySelector("label");
if(label){
var _txt=label.innerText,
_fChild=label.querySelector("input");
if(_fChild){
label.parentElement.innerHTML="<label class='custom'><input type='checkbox' "+(_fChild.checked ? "checked >" : ">")+_txt+"<span class='checkmark'></span></label>";
}
}
});
}
// expose data as a CollectionView to get events
$scope.data = new wijmo.collections.CollectionView(data);
});