-
Notifications
You must be signed in to change notification settings - Fork 77
/
Copy pathui-grid.auto-resize.js
69 lines (63 loc) · 2.04 KB
/
ui-grid.auto-resize.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/*!
* ui-grid - v4.12.7 - 2024-04-12
* http://ui-grid.info/
* Copyright (c) 2024 ; License: MIT
*/
(function() {
'use strict';
/**
* @ngdoc overview
* @name ui.grid.autoResize
*
* @description
*
* #ui.grid.autoResize
*
* <div class="alert alert-warning" role="alert"><strong>Beta</strong> This feature is ready for testing, but it either hasn't seen a lot of use or has some known bugs.</div>
*
* This module provides auto-resizing functionality to UI-Grid.
*/
var module = angular.module('ui.grid.autoResize', ['ui.grid']);
/**
* @ngdoc directive
* @name ui.grid.autoResize.directive:uiGridAutoResize
* @element div
* @restrict A
*
* @description Stacks on top of the ui-grid directive and
* adds the a watch to the grid's height and width which refreshes
* the grid content whenever its dimensions change.
*
*/
module.directive('uiGridAutoResize', ['gridUtil', function(gridUtil) {
return {
require: 'uiGrid',
scope: false,
link: function($scope, $elm, $attrs, uiGridCtrl) {
var debouncedRefresh;
function getDimensions() {
return {
width: gridUtil.elementWidth($elm),
height: gridUtil.elementHeight($elm)
};
}
function refreshGrid(prevWidth, prevHeight, width, height) {
if ($elm[0].offsetParent !== null) {
uiGridCtrl.grid.gridWidth = width;
uiGridCtrl.grid.gridHeight = height;
uiGridCtrl.grid.queueGridRefresh()
.then(function() {
uiGridCtrl.grid.api.core.raise.gridDimensionChanged(prevHeight, prevWidth, height, width);
});
}
}
debouncedRefresh = gridUtil.debounce(refreshGrid, 400);
$scope.$watchCollection(getDimensions, function(newValues, oldValues) {
if (!angular.equals(newValues, oldValues)) {
debouncedRefresh(oldValues.width, oldValues.height, newValues.width, newValues.height);
}
});
}
};
}]);
})();