Wijmo 5 - FlexGrid with Dynamic Context Menu

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.20162.207/styles/wijmo.min.css">
<script src="http://cdn.wijmo.com/5.20162.207/controls/wijmo.min.js"></script>
<script src="http://cdn.wijmo.com/5.20162.207/controls/wijmo.input.min.js"></script>
<script src="http://cdn.wijmo.com/5.20162.207/controls/wijmo.grid.min.js"></script>
<script src="http://cdn.wijmo.com/5.20162.207/interop/angular/wijmo.angular.min.js"></script>
<div ng-app="app" ng-controller="appCtrl" >
        <button ng-click="change()">Change Item source</button>
        <wj-flex-grid style="height:500px;" 
                      items-source="data" 
                      control="flex" 
                      selection-mode="Row"
                      selection-changed="selectionChanged(s,e)"
                      items-source-changed="itemsSourceChanged(s,e)" >

        </wj-flex-grid>
        
        <label>Currently Selected Row:</label>
        <label>{{selectedRow}}</label>
    </div>

CSS

.wj-flexgrid {
  max-height: 300px;
}
.wj-dropdown-panel {
  min-width: 200px;
  background: #c0f0c0;
  padding: 12px;
}

JavaScript

function getData(value) {
            var countries = 'US,Germany,UK,Japan,Italy,Greece'.split(','),
             data = [];
            for (var i = 0; i < value; i++) {
                data.push({
                    country: countries[i % countries.length],
                    downloads: Math.round(Math.random() * 20000),
                    sales: Math.random() * 10000,
                    expenses: Math.random() * 5000
                });
            }
            return data;
        }
        var app = angular.module('app', ['wj']);

        app.controller('appCtrl', function ($scope,$timeout) {
            var sortDesc = new wijmo.collections.SortDescription('country', false);
            $scope.data = new wijmo.collections.CollectionView(getData(20));
            $scope.data.sortDescriptions.push(sortDesc);

            $scope.change = function () {
                $scope.flex.itemsSource = new wijmo.collections.CollectionView(getData(40));
                $scope.flex.itemsSource.sortDescriptions.push(sortDesc);
            };
            $scope.itemsSourceChanged = function (s, e) {
                s.select(-1, -1, -1, -1);
                // s.selection = new wijmo.grid.CellRange(-1, -1, -1, -1); // used to deselect auto selected row
            };
            $scope.selectedRow = null;
            $scope.selectionChanged = function (s, e) {
            $timeout(function(){
                if (!(e.row == -1 && e.col == -1)) {                   
                    
                    $scope.selectedRow = s.rows[e.row].dataItem;
                    }                    
                else
                {
                $scope.selectedRow = null;
                 }},0);                
            };
        });