Wijmo 5 [Flex Sheet]
Cross Sheet Formulas
HTML
<link rel="stylesheet" href="http://cdn.wijmo.com/5.20162.198/styles/wijmo.min.css">
<script src="http://cdn.wijmo.com/5.20162.198/controls/wijmo.min.js"></script>
<script src="http://cdn.wijmo.com/5.20162.198/controls/wijmo.input.min.js"></script>
<script src="http://cdn.wijmo.com/5.20162.198/controls/wijmo.grid.min.js"></script>
<script src="http://cdn.wijmo.com/5.20162.198/controls/wijmo.grid.filter.min.js"></script>
<script src="http://cdn.wijmo.com/5.20162.198/controls/wijmo.grid.sheet.min.js"></script>
<script src="http://cdn.wijmo.com/5.20162.198/interop/angular/wijmo.angular.min.js"></script>
<div ng-app="app" ng-controller="appCtrl">
<wj-flex-sheet control="flex" selected-sheet-index="0" style="height:400px;">
<wj-sheet name="Country" items-source="data"></wj-sheet>
<wj-sheet name="Empty Sheet"></wj-sheet>
</wj-flex-sheet>
Click on the Button to apply cross sheet formula on sheet 2 <button ng-click="formula()">Cross Sheet Fromula</button>
</div>
JavaScript
function getData(value) {
var countries = 'US,Germany,UK,Japan,Italy,Greece'.split(','),
data = [];
for (var i = 0; i < value; i++) {
data.push({
id: i,
country: countries[i%countries.length],
sales: Math.random() * 1000,
expenses: Math.random() * 10000,
downloads: Math.random() * 100
});
}
return data;
}
var app = angular.module('app', ['wj']);
app.controller('appCtrl', function ($scope) {
$scope.data = new wijmo.collections.CollectionView(getData(50));
$scope.formula = function () {
var sheet1 = $scope.flex.sheets[0],
sheet2 = $scope.flex.sheets[1];
sheet2.grid.setCellData(0, 0, 'Field', true);
sheet2.grid.setCellData(0, 1, 'Sum', true);
sheet2.grid.setCellData(1, 0, 'Sales', true);
sheet2.grid.setCellData(1, 1, '=Sum(' + sheet1.name + '!C2:C51)', true);
sheet2.grid.setCellData(2, 0, 'Expenses', true);
sheet2.grid.setCellData(2, 1, '=Sum(' + sheet1.name + '!D2:D51)', true);
sheet2.grid.setCellData(3, 0, 'Download', true);
sheet2.grid.setCellData(3, 1, '=Sum(' + sheet1.name + '!E2:E51)', true);
sheet2.grid.setCellData(4, 0, 'Total', true);
sheet2.grid.setCellData(4, 1, '=Sum(B2:B4)', true);
$scope.flex.selectedSheetIndex=1;// if want to visible sheet 2 on value change
$scope.flex.refresh();
debugger
console.log($scope.flex.sheets[1]);
};
});