Skip to content

Commit 2d40955

Browse files
Portugal, Marcelomportuga
Portugal, Marcelo
authored andcommitted
fix(edit): Replacing with .
This will help with performance.
1 parent 076df71 commit 2d40955

File tree

2 files changed

+36
-34
lines changed

2 files changed

+36
-34
lines changed

misc/tutorial/201_editable.ngdoc

+28-26
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,12 @@ $scope.gridOptions.columnDefs = [
9494
};
9595
});
9696

97-
app.controller('MainCtrl', ['$scope', '$http', '$timeout', function ($scope, $http, $timeout) {
98-
$scope.gridOptions = { };
97+
app.controller('MainCtrl', function ($scope, $http, $timeout) {
98+
var vm = this;
9999

100-
$scope.storeFile = function( gridRow, gridCol, files ) {
100+
vm.gridOptions = { };
101+
102+
vm.storeFile = function( gridRow, gridCol, files ) {
101103
// ignore all but the first file, it can only select one anyway
102104
// set the filename into this column
103105
gridRow.entity.filename = files[0].name;
@@ -106,15 +108,15 @@ $scope.gridOptions.columnDefs = [
106108
var setFile = function(fileContent){
107109
gridRow.entity.file = fileContent.currentTarget.result;
108110
// put it on scope so we can display it - you'd probably do something else with it
109-
$scope.lastFile = fileContent.currentTarget.result;
111+
vm.lastFile = fileContent.currentTarget.result;
110112
$scope.$apply();
111113
};
112114
var reader = new FileReader();
113115
reader.onload = setFile;
114116
reader.readAsText( files[0] );
115117
};
116118

117-
$scope.gridOptions.columnDefs = [
119+
vm.gridOptions.columnDefs = [
118120
{ name: 'id', enableCellEdit: false, width: '10%' },
119121
{ name: 'name', displayName: 'Name (editable)', width: '20%' },
120122
{ name: 'age', displayName: 'Age' , type: 'number', width: '10%' },
@@ -126,9 +128,9 @@ $scope.gridOptions.columnDefs = [
126128
{ name: 'registered', displayName: 'Registered' , type: 'date', cellFilter: 'date:"yyyy-MM-dd"', width: '20%' },
127129
{ name: 'address', displayName: 'Address', type: 'object', cellFilter: 'address', width: '30%' },
128130
{ name: 'address.city', displayName: 'Address (even rows editable)', width: '20%',
129-
cellEditableCondition: function($scope){
130-
return $scope.rowRenderIndex%2
131-
}
131+
cellEditableCondition: function(scope){
132+
return scope.rowRenderIndex%2;
133+
}
132134
},
133135
{ name: 'isActive', displayName: 'Active', type: 'boolean', width: '10%' },
134136
{ name: 'pet', displayName: 'Pet', width: '20%', editableCellTemplate: 'ui-grid/dropdownEditor',
@@ -151,19 +153,19 @@ $scope.gridOptions.columnDefs = [
151153
}
152154
},
153155
{ name: 'filename', displayName: 'File', width: '20%', editableCellTemplate: 'ui-grid/fileChooserEditor',
154-
editFileChooserCallback: $scope.storeFile }
155-
];
156+
editFileChooserCallback: vm.storeFile }
157+
];
156158

157-
$scope.msg = {};
159+
vm.msg = {};
158160

159-
$scope.gridOptions.onRegisterApi = function(gridApi){
160-
//set gridApi on scope
161-
$scope.gridApi = gridApi;
162-
gridApi.edit.on.afterCellEdit($scope,function(rowEntity, colDef, newValue, oldValue){
163-
$scope.msg.lastCellEdited = 'edited row id:' + rowEntity.id + ' Column:' + colDef.name + ' newValue:' + newValue + ' oldValue:' + oldValue ;
164-
$scope.$apply();
165-
});
166-
};
161+
vm.gridOptions.onRegisterApi = function(gridApi) {
162+
//set gridApi on scope
163+
vm.gridApi = gridApi;
164+
gridApi.edit.on.afterCellEdit($scope, function(rowEntity, colDef, newValue, oldValue) {
165+
vm.msg.lastCellEdited = 'edited row id:' + rowEntity.id + ' Column:' + colDef.name + ' newValue:' + newValue + ' oldValue:' + oldValue ;
166+
$scope.$apply();
167+
});
168+
};
167169

168170
$http.get('/data/500_complex.json')
169171
.then(function(response) {
@@ -181,9 +183,9 @@ $scope.gridOptions.columnDefs = [
181183
data[i].foo = {bar: [{baz: 2, options: [{value: 'dog'}, {value: 'cat'}]}]}
182184
}
183185
}
184-
$scope.gridOptions.data = data;
186+
vm.gridOptions.data = data;
185187
});
186-
}])
188+
})
187189

188190
.filter('mapGender', function() {
189191
var genderHash = {
@@ -218,15 +220,15 @@ $scope.gridOptions.columnDefs = [
218220
});
219221
</file>
220222
<file name="index.html">
221-
<div ng-controller="MainCtrl">
222-
<strong>Data Length:</strong> {{ gridOptions.data.length | number }}
223+
<div ng-controller="MainCtrl as $ctrl">
224+
<strong>Data Length:</strong> {{ $ctrl.gridOptions.data.length | number }}
223225
<br>
224-
<strong>Last Cell Edited:</strong> {{msg.lastCellEdited}}
226+
<strong>Last Cell Edited:</strong> {{$ctrl.msg.lastCellEdited}}
225227
<br>
226-
<div ui-grid="gridOptions" ui-grid-edit class="grid"></div>
228+
<div ui-grid="$ctrl.gridOptions" ui-grid-edit class="grid"></div>
227229
<br>
228230
<div><strong>Last file uploaded:</strong></div>
229-
<div>{{lastFile}}</div>
231+
<div>{{$ctrl.lastFile}}</div>
230232
</div>
231233
</file>
232234
<file name="main.css">

src/features/edit/js/gridEdit.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,7 @@
535535
cellNavNavigateDereg = uiGridCtrl.grid.api.cellNav.on.navigate($scope, function (newRowCol, oldRowCol, evt) {
536536
if ($scope.col.colDef.enableCellEditOnFocus) {
537537
if (newRowCol.row === $scope.row && newRowCol.col === $scope.col && evt && (evt.type === 'click' || evt.type === 'keydown')) {
538-
$timeout(function () {
538+
$scope.$applyAsync(function () {
539539
beginEdit(evt);
540540
});
541541
}
@@ -834,8 +834,8 @@
834834
});
835835

836836
$scope.$broadcast(uiGridEditConstants.events.BEGIN_CELL_EDIT, triggerEvent);
837-
$timeout(function () {
838-
//execute in a timeout to give any complex editor templates a cycle to completely render
837+
$scope.$applyAsync(function () {
838+
// execute in a apply async to give any complex editor templates a cycle to completely render
839839
$scope.grid.api.edit.raise.beginCellEdit($scope.row.entity, $scope.col.colDef, triggerEvent);
840840
});
841841
}
@@ -935,7 +935,7 @@
935935

936936
//set focus at start of edit
937937
$scope.$on(uiGridEditConstants.events.BEGIN_CELL_EDIT, function (evt,triggerEvent) {
938-
$timeout(function () {
938+
$scope.$applyAsync(function () {
939939
$elm[0].focus();
940940
//only select text if it is not being replaced below in the cellNav viewPortKeyPress
941941
if ($elm[0].select && ($scope.col.colDef.enableCellEditOnFocus || !(uiGridCtrl && uiGridCtrl.grid.api.cellNav))) {
@@ -1005,7 +1005,7 @@
10051005
$elm.on('click', function (evt) {
10061006
if ($elm[0].type !== 'checkbox') {
10071007
$scope.deepEdit = true;
1008-
$timeout(function () {
1008+
$scope.$applyAsync(function () {
10091009
$scope.grid.disableScrolling = true;
10101010
});
10111011
}
@@ -1136,8 +1136,8 @@
11361136
*
11371137
*/
11381138
module.directive('uiGridEditDropdown',
1139-
['uiGridConstants', 'uiGridEditConstants', '$timeout',
1140-
function (uiGridConstants, uiGridEditConstants, $timeout) {
1139+
['uiGridConstants', 'uiGridEditConstants',
1140+
function (uiGridConstants, uiGridEditConstants) {
11411141
return {
11421142
require: ['?^uiGrid', '?^uiGridRenderContainer'],
11431143
scope: true,
@@ -1152,7 +1152,7 @@
11521152

11531153
//set focus at start of edit
11541154
$scope.$on(uiGridEditConstants.events.BEGIN_CELL_EDIT, function () {
1155-
$timeout(function(){
1155+
$scope.$applyAsync(function(){
11561156
$elm[0].focus();
11571157
});
11581158

0 commit comments

Comments
 (0)