Skip to content

Commit 076df71

Browse files
Portugal, Marcelomportuga
Portugal, Marcelo
authored andcommitted
fix(core/ui-grid): Updating to .
Improving performance by updating some timeout instances to .
1 parent be18d09 commit 076df71

File tree

4 files changed

+17
-26
lines changed

4 files changed

+17
-26
lines changed

Diff for: misc/tutorial/121_grid_menu.ngdoc

+12-10
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,9 @@ In the meantime, you can override the height to fit with your application in you
4646
<file name="app.js">
4747
var app = angular.module('app', ['ngTouch', 'ui.grid', 'ui.grid.exporter', 'ui.grid.selection']);
4848

49-
app.controller('MainCtrl', ['$scope', '$http', '$interval', '$q', function ($scope, $http, $interval, $q) {
49+
app.controller('MainCtrl', function ($scope, $http, $interval, $q) {
50+
var vm = this;
51+
5052
function fakeI18n(title){
5153
return $q(function(resolve) {
5254
$interval(function() {
@@ -55,7 +57,7 @@ In the meantime, you can override the height to fit with your application in you
5557
});
5658
}
5759

58-
$scope.gridOptions = {
60+
vm.gridOptions = {
5961
exporterMenuCsv: false,
6062
enableGridMenu: true,
6163
gridMenuTitleFilter: fakeI18n,
@@ -74,30 +76,30 @@ In the meantime, you can override the height to fit with your application in you
7476
}
7577
],
7678
onRegisterApi: function( gridApi ){
77-
$scope.gridApi = gridApi;
79+
vm.gridApi = gridApi;
7880

7981
// interval of zero just to allow the directive to have initialized
8082
$interval( function() {
8183
gridApi.core.addToGridMenu( gridApi.grid, [{ title: 'Dynamic item', order: 100}]);
8284
}, 0, 1);
8385

8486
gridApi.core.on.columnVisibilityChanged( $scope, function( changedColumn ){
85-
$scope.columnChanged = { name: changedColumn.colDef.name, visible: changedColumn.colDef.visible };
87+
vm.columnChanged = { name: changedColumn.colDef.name, visible: changedColumn.colDef.visible };
8688
});
8789
}
8890
};
8991

9092
$http.get('/data/100.json')
9193
.then(function(response) {
92-
$scope.gridOptions.data = response.data;
94+
vm.gridOptions.data = response.data;
9395
});
94-
}]);
96+
});
9597
</file>
9698
<file name="index.html">
97-
<div ng-controller="MainCtrl">
98-
<div id="grid1" ui-grid="gridOptions" ui-grid-exporter ui-grid-selection class="grid"></div>
99-
<div ng-if='columnChanged'>
100-
Column Visibility Changed - name: {{ columnChanged.name }} visible: {{ columnChanged.visible }}
99+
<div ng-controller="MainCtrl as $ctrl">
100+
<div id="grid1" ui-grid="$ctrl.gridOptions" ui-grid-exporter ui-grid-selection class="grid"></div>
101+
<div ng-if="$ctrl.columnChanged">
102+
Column Visibility Changed - name: {{ $ctrl.columnChanged.name }} visible: {{ $ctrl.columnChanged.visible }}
101103
</div>
102104
</div>
103105
</file>

Diff for: src/js/core/directives/ui-grid-column-menu.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,7 @@ function ($timeout, gridUtil, uiGridConstants, uiGridColumnMenuService, $documen
438438

439439
//Since we are hiding this column the default hide action will fail so we need to focus somewhere else.
440440
var setFocusOnHideColumn = function(){
441-
$timeout(function(){
441+
$scope.$applyAsync(function() {
442442
// Get the UID of the first
443443
var focusToGridMenu = function(){
444444
return gridUtil.focus.byId('grid-menu', $scope.grid);

Diff for: src/js/core/directives/ui-grid-header-cell.js

+3-13
Original file line numberDiff line numberDiff line change
@@ -245,27 +245,17 @@
245245
}
246246
contents.addClass(classAdded);
247247

248-
$timeout(function (){
248+
$scope.$applyAsync(function() {
249249
var rightMostContainer = $scope.grid.renderContainers['right'] ? $scope.grid.renderContainers['right'] : $scope.grid.renderContainers['body'];
250250
$scope.isLastCol = ( $scope.col === rightMostContainer.visibleColumnCache[ rightMostContainer.visibleColumnCache.length - 1 ] );
251251
});
252252

253253
// Figure out whether this column is sortable or not
254-
if ($scope.col.enableSorting) {
255-
$scope.sortable = true;
256-
}
257-
else {
258-
$scope.sortable = false;
259-
}
254+
$scope.sortable = Boolean($scope.col.enableSorting);
260255

261256
// Figure out whether this column is filterable or not
262257
var oldFilterable = $scope.filterable;
263-
if (uiGridCtrl.grid.options.enableFiltering && $scope.col.enableFiltering) {
264-
$scope.filterable = true;
265-
}
266-
else {
267-
$scope.filterable = false;
268-
}
258+
$scope.filterable = Boolean(uiGridCtrl.grid.options.enableFiltering && $scope.col.enableFiltering);
269259

270260
if ( oldFilterable !== $scope.filterable){
271261
if ( typeof($scope.col.updateFilters) !== 'undefined' ){

Diff for: src/js/core/directives/ui-grid-menu.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ function ($compile, $timeout, $window, $document, gridUtil, uiGridConstants, i18
9393
*/
9494
$scope.shown = true;
9595

96-
$timeout( function() {
96+
$scope.$applyAsync(function() {
9797
$scope.shownMid = true;
9898
$scope.$emit('menu-shown');
9999
});
@@ -118,7 +118,6 @@ function ($compile, $timeout, $window, $document, gridUtil, uiGridConstants, i18
118118
angular.element(document).on(docEventType, applyHideMenu);
119119
$elm.on('keyup', checkKeyUp);
120120
$elm.on('keydown', checkKeyDown);
121-
122121
});
123122
//automatically set the focus to the first button element in the now open menu.
124123
gridUtil.focus.bySelector($elm, 'button[type=button]', true);

0 commit comments

Comments
 (0)