Wijmo 5 - Handling the CellEditEnded event

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/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>
    RowEditEnded event</h1>
  <p>
    Click the checkboxes on the grid and see the output in the console:</p>
  <wj-flex-grid
      items-source="data"
      allow-add-new=true
      new-row-at-top="true"
			row-added="rowAdded(s, e)"
      cell-edit-ended="cellEditEnded(s, e)">
  </wj-flex-grid>
</div>

CSS

.wj-flexgrid {
  max-height: 300px;
}

JavaScript

// define app, include Wijmo 5 directives
var app = angular.module('app', ['wj']);

// controller
app.controller('appCtrl', function($scope) {

  $scope.cellEditEnded = function(s, e) {
		var flex = s, // FlexGrid is the event sender
    	row = flex.rows[e.row], // row that was edited
      col = flex.columns[e.col]; // column that was edited
      
     // do something with the data object that was changed
     if (col.dataType == wijmo.DataType.Boolean) {
       console.log('you changed the value of the "' + col.binding + '" property for this object: ');
       console.log(JSON.stringify(row.dataItem));
     }
  }
	$scope.rowAdded = function(s, e) {
		console.log('New Row Added');
		console.log(s.rows);
		console.log(s.rows[s.rows.length - 1].dataItem);
	}

  // 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,
      active: i % 3 == 0
    });
  }

  // expose data to view
  $scope.data = data;
});