Skip to content

Commit fef9552

Browse files
tfilomportuga
authored andcommitted
fix(uiGridAutoResize): Changed [0].clientHeight to gridUtil.elementHe… (#6490)
* fix(uiGridAutoResize): Changed [0].clientHeight to gridUtil.elementHeight() etc. * fix(uiGridAutoResize): Changed comparisom of arrays to angular.equals * fix(uiGridAutoResize): changes after considering lot of comments on my original implementation
1 parent a2f2fd5 commit fef9552

File tree

1 file changed

+21
-14
lines changed

1 file changed

+21
-14
lines changed

src/features/auto-resize-grid/js/auto-resize.js

+21-14
Original file line numberDiff line numberDiff line change
@@ -19,25 +19,32 @@
1919
require: 'uiGrid',
2020
scope: false,
2121
link: function($scope, $elm, $attrs, uiGridCtrl) {
22+
var timeout = null;
2223

23-
$scope.$watch(function() {
24-
return $elm[0].clientWidth;
25-
}, function(newVal, oldVal) {
26-
if (newVal !== oldVal) {
27-
uiGridCtrl.grid.gridWidth = newVal;
28-
uiGridCtrl.grid.refresh();
24+
var debounce = function(width, height) {
25+
if (timeout !== null) {
26+
clearTimeout(timeout);
2927
}
30-
});
31-
32-
$scope.$watch(function() {
33-
return $elm[0].clientHeight;
34-
}, function(newVal, oldVal) {
35-
if (newVal !== oldVal) {
36-
uiGridCtrl.grid.gridHeight = newVal;
28+
timeout = setTimeout(function() {
29+
uiGridCtrl.grid.gridWidth = width;
30+
uiGridCtrl.grid.gridHeight = height;
3731
uiGridCtrl.grid.refresh();
32+
timeout = null;
33+
}, 400);
34+
};
35+
36+
$scope.$watchGroup([
37+
function() {
38+
return gridUtil.elementWidth($elm);
39+
},
40+
function() {
41+
return gridUtil.elementHeight($elm);
42+
}
43+
], function(newValues, oldValues, scope) {
44+
if (!angular.equals(newValues, oldValues)) {
45+
debounce(newValues[0], newValues[1]);
3846
}
3947
});
40-
4148
}
4249
};
4350
}]);

0 commit comments

Comments
 (0)