@@ -35,13 +35,15 @@ while still allowing the right arrow to be handled by the grid.
3535 <file name="app.js">
3636 var app = angular.module('app', ['ngTouch', 'ui.grid', 'ui.grid.cellNav', 'ui.grid.pinning']);
3737
38- app.controller('MainCtrl', ['$scope', '$http', '$log', function ($scope, $http, $log) {
39- $scope.gridOptions = {
38+ app.controller('MainCtrl', function ($scope, $http, $log) {
39+ var vm = this;
40+
41+ vm.gridOptions = {
4042 modifierKeysToMultiSelectCells: true,
41- keyDownOverrides: [ { keyCode: 39, ctrlKey: true }],
43+ keyDownOverrides: [{ keyCode: 39, ctrlKey: true }],
4244 showGridFooter: true
4345 };
44- $scope .gridOptions.columnDefs = [
46+ vm .gridOptions.columnDefs = [
4547 { name: 'id', width:'150' },
4648 { name: 'name', width:'200' },
4749 { name: 'age', displayName: 'Age (not focusable)', allowCellFocus : false, width:'100' },
@@ -55,70 +57,78 @@ while still allowing the right arrow to be handled by the grid.
5557
5658 $http.get('/data/500_complex.json')
5759 .then(function(response) {
58- $scope .gridOptions.data = response.data;
60+ vm .gridOptions.data = response.data;
5961 });
6062
61- $scope.info = {};
63+ vm.info = {};
64+
65+ vm.currentFocused = '';
6266
63- $scope.currentFocused = "";
67+ vm.getCurrentFocus = function(){
68+ var rowCol = vm.gridApi.cellNav.getFocusedCell();
6469
65- $scope.getCurrentFocus = function(){
66- var rowCol = $scope.gridApi.cellNav.getFocusedCell();
6770 if(rowCol !== null) {
68- $scope .currentFocused = 'Row Id:' + rowCol.row.entity.id + ' col:' + rowCol.col.colDef.name;
71+ vm .currentFocused = 'Row Id:' + rowCol.row.entity.id + ' col:' + rowCol.col.colDef.name;
6972 }
7073 };
7174
72- $scope.getCurrentSelection = function() {
73- var values = [];
74- var currentSelection = $scope.gridApi.cellNav.getCurrentSelection();
75+ vm.getCurrentSelection = function() {
76+ var values = [],
77+ currentSelection = vm.gridApi.cellNav.getCurrentSelection();
78+
7579 for (var i = 0; i < currentSelection.length; i++) {
7680 values.push(currentSelection[i].row.entity[currentSelection[i].col.name])
7781 }
78- $scope .printSelection = values.toString();
82+ vm .printSelection = values.toString();
7983 };
8084
81- $scope .scrollTo = function( rowIndex, colIndex ) {
82- $scope .gridApi.core.scrollTo( $scope .gridOptions.data[rowIndex], $scope .gridOptions.columnDefs[colIndex]);
85+ vm .scrollTo = function( rowIndex, colIndex ) {
86+ vm .gridApi.core.scrollTo( vm .gridOptions.data[rowIndex], vm .gridOptions.columnDefs[colIndex]);
8387 };
8488
85- $scope .scrollToFocus = function( rowIndex, colIndex ) {
86- $scope .gridApi.cellNav.scrollToFocus( $scope .gridOptions.data[rowIndex], $scope .gridOptions.columnDefs[colIndex]);
89+ vm .scrollToFocus = function( rowIndex, colIndex ) {
90+ vm .gridApi.cellNav.scrollToFocus( vm .gridOptions.data[rowIndex], vm .gridOptions.columnDefs[colIndex]);
8791 };
8892
89- $scope.gridOptions.onRegisterApi = function(gridApi){
90- $scope.gridApi = gridApi;
91- gridApi.cellNav.on.navigate($scope,function(newRowCol, oldRowCol){
92- // var rowCol = {row: newRowCol.row.index, col:newRowCol.col.colDef.name};
93- // var msg = 'New RowCol is ' + angular.toJson(rowCol);
94- // if(oldRowCol){
95- // rowCol = {row: oldRowCol.row.index, col:oldRowCol.col.colDef.name};
96- // msg += ' Old RowCol is ' + angular.toJson(rowCol);
97- // }
98- $log.log('navigation event');
99- });
100- gridApi.cellNav.on.viewPortKeyDown($scope,function(event, newRowCol){
101- var row = newRowCol.row;
102- var col = newRowCol.col
103- if (event.keyCode === 39) {
104- $scope.gridApi.cellNav.scrollToFocus(row.entity, $scope.gridApi.grid.columns[$scope.gridApi.grid.columns.length - 1]);
105- }
106- });
93+ vm.gridOptions.onRegisterApi = function(gridApi){
94+ vm.gridApi = gridApi;
95+ gridApi.cellNav.on.navigate($scope, function(newRowCol, oldRowCol) {
96+ // var rowCol = {row: newRowCol.row.index, col:newRowCol.col.colDef.name};
97+ // var msg = 'New RowCol is ' + angular.toJson(rowCol);
98+ // if(oldRowCol){
99+ // rowCol = {row: oldRowCol.row.index, col:oldRowCol.col.colDef.name};
100+ // msg += ' Old RowCol is ' + angular.toJson(rowCol);
101+ // }
102+ $log.log('navigation event');
103+ });
104+ gridApi.cellNav.on.viewPortKeyDown($scope, function(event, newRowCol) {
105+ var row = newRowCol.row,
106+ col = newRowCol.col;
107+
108+ if (event.keyCode === 39) {
109+ vm.gridApi.cellNav.scrollToFocus(row.entity, vm.gridApi.grid.columns[vm.gridApi.grid.columns.length - 1]);
110+ }
111+ });
107112 };
108- }] );
113+ });
109114 </file>
110115 <file name="index.html">
111- <div ng-controller="MainCtrl">
112- <button type="button" class="btn btn-success" ng-click="scrollTo(20,0)">Scroll To Row 20</button>
113- <button type="button" class="btn btn-success" ng-click="scrollTo(0,7)">Scroll To Balance</button>
114- <button type="button" class="btn btn-success" ng-click="scrollTo(50,7)">Scroll To Row 50, Balance</button>
115- <button type="button" class="btn btn-success" ng-click="scrollToFocus(50,7)">Focus Row 50, Balance</button>
116- <button type="button" class="btn btn-success" ng-click="getCurrentFocus()">Get Current focused cell</button> <span ng-bind="currentFocused"></span>
117- <button type="button" class="btn btn-success" ng-click="getCurrentSelection()">Get Current focused cell values</button>
118- <input type="text" ng-model="printSelection" placeholder="Click the 'Get current focused cell values' button to print cell values of selection here" class="printSelection">
116+ <div ng-controller="MainCtrl as $ctrl">
117+ <button type="button" class="btn btn-success" ng-click="$ctrl.scrollTo(20,0)">Scroll To Row 20</button>
118+ <button type="button" class="btn btn-success" ng-click="$ctrl.scrollTo(0,7)">Scroll To Balance</button>
119+ <button type="button" class="btn btn-success" ng-click="$ctrl.scrollTo(50,7)">Scroll To Row 50, Balance</button>
120+ <button type="button" class="btn btn-success" ng-click="$ctrl.scrollToFocus(50,7)">Focus Row 50, Balance</button>
121+ <br>
122+ <br>
123+ <button type="button" class="btn btn-success" ng-click="$ctrl.getCurrentFocus()">Get Current focused cell</button> <span ng-bind="$ctrl.currentFocused"></span>
124+ <br>
125+ <br>
126+ <button type="button" class="btn btn-success" ng-click="$ctrl.getCurrentSelection()">Get Current focused cell values</button>
127+ <br>
128+ <input type="text" ng-model="$ctrl.printSelection" placeholder="Click the 'Get current focused cell values' button to print cell values of selection here" class="printSelection">
119129 <br>
120130 <br>
121- <div ui-grid="gridOptions" ui-grid-cellNav ui-grid-pinning class="grid"></div>
131+ <div ui-grid="$ctrl. gridOptions" ui-grid-cellNav ui-grid-pinning class="grid"></div>
122132 </div>
123133 </file>
124134 <file name="main.css">
@@ -127,7 +137,7 @@ while still allowing the right arrow to be handled by the grid.
127137 height: 400px;
128138 }
129139 .printSelection {
130- width: 600px ;
140+ width: 500px ;
131141 margin-top: 10px;
132142 }
133143 </file>
0 commit comments