Wijmo 5 - Edits on Server

HTML

<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.grid.filter.min.js"></script>
<script src="http://cdn.wijmo.com/5.latest/interop/angular/wijmo.angular.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
<!-- mark this as an Angular application and give it a controller -->
<body ng-app="app" ng-controller="appCtrl" class="container">

    <h1>Apply edits on server</h1>
    <p>
        This app overrides the CollectionView.commitEdit method
        to cancel local edits and apply them to the server
        (in this case the server is represented by a 2s delay).</p>
    <wj-flex-grid items-source="data">
      <wj-flex-grid-filter></wj-flex-grid-filter>
    </wj-flex-grid>
   
</body>

JavaScript

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

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

    // override commitEdit to submit changes to server
    wijmo.collections.CollectionView.prototype.commitEdit = function () {
        var item = this.currentEditItem;
        if (item) {

            // save a copy of the changes
            var self = this,
                index = self.sourceCollection.indexOf(item),
                changedItem = JSON.stringify(item);

            // undo the changes
            self.cancelEdit();

            // send the changes to the server
            setTimeout(function () {
                self.sourceCollection[index] = JSON.parse(changedItem);
                self.refresh();
            }, 2000);
        }
    };

    // 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);
});