Wijmo 5 - Editing Events
by Manas
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>Editing Events</h1>
<p>This is a <b>FlexGrid</b> control:</p>
<wj-flex-grid
items-source="data"
cell-edit-ending="cellEditEnding(s,e)"
cell-edit-ended="cellEditEnded(s,e)">
<wj-flex-grid-column header="Country" binding="country"></wj-flex-grid-column>
<wj-flex-grid-column header="Sales" binding="sales"></wj-flex-grid-column>
<wj-flex-grid-column header="Expenses" binding="expenses"></wj-flex-grid-column>
</wj-flex-grid>
<button ng-click="changeCell()">
Change the data in the first cell (with events)
</button>
<p>
Open the console to see the editing events firing.
</p>
</div>
CSS
.wj-flexgrid {
height: 150px;
margin-top:10px;
}
.wj-flexchart {
height: 300px;
}
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 = [];
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);
// change the data in the first cell as if it was being edited
$scope.changeCell = function() {
var g = wijmo.Control.getControl(document.querySelector('.wj-flexgrid'));
var value = 'Bruno'; // valor a colocar na celula
if (g.startEditing(false, 0, 0)) {
g.activeEditor.value = value.toString();
g.finishEditing();
}
}
// show old and new values BEFORE ending edits
$scope.cellEditEnding = function(s, e) {
console.log('ENDING: changing from ' +
s.getCellData(e.row, e.col) +
' to ' +
s.activeEditor.value);
}
// show old and new values AFTER edits
$scope.cellEditEnded = function(s, e) {
console.log('ENDED: changed from ' +
e.data + // << value before edits
' to ' +
s.getCellData(e.row, e.col));
}
});