-
Notifications
You must be signed in to change notification settings - Fork 77
/
ui-grid.empty-base-layer.js
178 lines (158 loc) · 6.46 KB
/
ui-grid.empty-base-layer.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
/*!
* 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.emptyBaseLayer
* @description
*
* # ui.grid.emptyBaseLayer
*
* <div class="alert alert-warning" role="alert"><strong>Alpha</strong> This feature is in development. There will almost certainly be breaking api changes, or there are major outstanding bugs.</div>
*
* This module provides the ability to have the background of the ui-grid be empty rows, this would be displayed in the case were
* the grid height is greater then the amount of rows displayed.
*
* <div doc-module-components="ui.grid.emptyBaseLayer"></div>
*/
var module = angular.module('ui.grid.emptyBaseLayer', ['ui.grid']);
/**
* @ngdoc service
* @name ui.grid.emptyBaseLayer.service:uiGridBaseLayerService
*
* @description Services for the empty base layer grid
*/
module.service('uiGridBaseLayerService', ['gridUtil', '$compile', function (gridUtil, $compile) {
return {
initializeGrid: function (grid, disableEmptyBaseLayer) {
/**
* @ngdoc object
* @name ui.grid.emptyBaseLayer.api:GridOptions
*
* @description GridOptions for emptyBaseLayer feature, these are available to be
* set using the ui-grid {@link ui.grid.class:GridOptions gridOptions}
*/
grid.baseLayer = {
emptyRows: []
};
/**
* @ngdoc object
* @name enableEmptyGridBaseLayer
* @propertyOf ui.grid.emptyBaseLayer.api:GridOptions
* @description Enable empty base layer, which shows empty rows as background on the entire grid
* <br/>Defaults to true, if the directive is used.
* <br/>Set to false either by setting this attribute or passing false to the directive.
*/
// default option to true unless it was explicitly set to false
if (grid.options.enableEmptyGridBaseLayer !== false) {
grid.options.enableEmptyGridBaseLayer = !disableEmptyBaseLayer;
}
},
setNumberOfEmptyRows: function(viewportHeight, grid) {
var rowHeight = grid.options.rowHeight,
rows = Math.ceil(viewportHeight / rowHeight);
if (rows > 0) {
grid.baseLayer.emptyRows = [];
for (var i = 0; i < rows; i++) {
grid.baseLayer.emptyRows.push({});
}
}
}
};
}]);
/**
* @ngdoc object
* @name ui.grid.emptyBaseLayer.directive:uiGridEmptyBaseLayer
* @description Shows empty rows in the background of the ui-grid, these span
* the full height of the ui-grid, so that there won't be blank space below the shown rows.
* @example
* <pre>
* <div ui-grid="gridOptions" class="grid" ui-grid-empty-base-layer></div>
* </pre>
* Or you can enable/disable it dynamically by passing in true or false. It doesn't
* the value, so it would only be set on initial render.
* <pre>
* <div ui-grid="gridOptions" class="grid" ui-grid-empty-base-layer="false"></div>
* </pre>
*/
module.directive('uiGridEmptyBaseLayer', ['gridUtil', 'uiGridBaseLayerService',
'$parse',
function (gridUtil, uiGridBaseLayerService, $parse) {
return {
require: '^uiGrid',
scope: false,
compile: function () {
return {
pre: function ($scope, $elm, $attrs, uiGridCtrl) {
var disableEmptyBaseLayer = $parse($attrs.uiGridEmptyBaseLayer)($scope) === false;
uiGridBaseLayerService.initializeGrid(uiGridCtrl.grid, disableEmptyBaseLayer);
},
post: function ($scope, $elm, $attrs, uiGridCtrl) {
if (!uiGridCtrl.grid.options.enableEmptyGridBaseLayer) {
return;
}
var renderBodyContainer = uiGridCtrl.grid.renderContainers.body,
viewportHeight = renderBodyContainer.getViewportHeight();
function heightHasChanged() {
var newViewPortHeight = renderBodyContainer.getViewportHeight();
if (newViewPortHeight !== viewportHeight) {
viewportHeight = newViewPortHeight;
return true;
}
return false;
}
function getEmptyBaseLayerCss(viewportHeight) {
// Set ui-grid-empty-base-layer height
return '.grid' + uiGridCtrl.grid.id +
' .ui-grid-render-container ' +
'.ui-grid-empty-base-layer-container.ui-grid-canvas ' +
'{ height: ' + viewportHeight + 'px; }';
}
uiGridCtrl.grid.registerStyleComputation({
func: function() {
if (heightHasChanged()) {
uiGridBaseLayerService.setNumberOfEmptyRows(viewportHeight, uiGridCtrl.grid);
}
return getEmptyBaseLayerCss(viewportHeight);
}
});
}
};
}
};
}]);
/**
* @ngdoc directive
* @name ui.grid.emptyBaseLayer.directive:uiGridViewport
* @description stacks on the uiGridViewport directive to append the empty grid base layer html elements to the
* default gridRow template
*/
module.directive('uiGridViewport',
['$compile', 'gridUtil', '$templateCache',
function ($compile, gridUtil, $templateCache) {
return {
priority: -200,
scope: false,
compile: function ($elm) {
var emptyBaseLayerContainer = $templateCache.get('ui-grid/emptyBaseLayerContainer');
$elm.prepend(emptyBaseLayerContainer);
return {
pre: function ($scope, $elm, $attrs, controllers) {
},
post: function ($scope, $elm, $attrs, controllers) {
}
};
}
};
}]);
})();
angular.module('ui.grid.emptyBaseLayer').run(['$templateCache', function($templateCache) {
'use strict';
$templateCache.put('ui-grid/emptyBaseLayerContainer',
"<div class=\"ui-grid-empty-base-layer-container ui-grid-canvas\"><div class=\"ui-grid-row\" ng-repeat=\"(rowRenderIndex, row) in grid.baseLayer.emptyRows track by $index\" ng-style=\"Viewport.rowStyle(rowRenderIndex)\"><div><div><div ng-repeat=\"(colRenderIndex, col) in colContainer.renderedColumns track by col.colDef.name\" class=\"ui-grid-cell {{ col.getColClass(false) }}\"></div></div></div></div></div>"
);
}]);