Skip to content

Commit 40ec65c

Browse files
dlgskiDana Greenberg
authored and
Dana Greenberg
committed
fix: Introduce gridDimensionChanged event
Closes #5090
1 parent c61f680 commit 40ec65c

File tree

4 files changed

+41
-21
lines changed

4 files changed

+41
-21
lines changed

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

+1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
if (newGridHeight !== prevGridHeight || newGridWidth !== prevGridWidth) {
4242
uiGridCtrl.grid.gridHeight = newGridHeight;
4343
uiGridCtrl.grid.gridWidth = newGridWidth;
44+
uiGridCtrl.grid.api.core.raise.gridDimensionChanged(prevGridHeight, prevGridWidth, newGridHeight, newGridWidth);
4445

4546
$scope.$apply(function () {
4647
uiGridCtrl.grid.refresh()

src/js/core/directives/ui-grid-menu.js

+11-5
Original file line numberDiff line numberDiff line change
@@ -43,19 +43,25 @@ function ($compile, $timeout, $window, $document, gridUtil, uiGridConstants, i18
4343
templateUrl: 'ui-grid/uiGridMenu',
4444
replace: false,
4545
link: function ($scope, $elm, $attrs, uiGridCtrl) {
46-
var gridMenuMaxHeight;
4746

4847
$scope.dynamicStyles = '';
4948

50-
if (uiGridCtrl) {
49+
var setupHeightStyle = function(gridHeight) {
5150
// magic number of 30 because the grid menu displays somewhat below
5251
// the top of the grid. It is approximately 30px.
53-
gridMenuMaxHeight = uiGridCtrl.grid.gridHeight - 30;
54-
$scope.dynamicStyles = [
52+
var gridMenuMaxHeight = gridHeight - 30;
53+
$scope.dynamicStyles = [
5554
'.grid' + uiGridCtrl.grid.id + ' .ui-grid-menu-mid {',
56-
'max-height: ' + gridMenuMaxHeight + 'px;',
55+
'max-height: ' + gridMenuMaxHeight + 'px;',
5756
'}'
5857
].join(' ');
58+
};
59+
60+
if (uiGridCtrl) {
61+
setupHeightStyle(uiGridCtrl.grid.gridHeight);
62+
uiGridCtrl.grid.api.core.on.gridDimensionChanged($scope, function(oldGridHeight, oldGridWidth, newGridHeight, newGridWidth) {
63+
setupHeightStyle(newGridHeight);
64+
});
5965
}
6066

6167
$scope.i18n = {

src/js/core/factories/GridApi.js

+25-15
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
var GridApi = function GridApi(grid) {
2323
this.grid = grid;
2424
this.listeners = [];
25-
25+
2626
/**
2727
* @ngdoc function
2828
* @name renderingComplete
@@ -31,14 +31,14 @@
3131
* time as `onRegisterApi`, but provides a way to obtain
3232
* that same event within features without stopping end
3333
* users from getting at the onRegisterApi method.
34-
*
34+
*
3535
* Included in gridApi so that it's always there - otherwise
3636
* there is still a timing problem with when a feature can
37-
* call this.
38-
*
39-
* @param {GridApi} gridApi the grid api, as normally
37+
* call this.
38+
*
39+
* @param {GridApi} gridApi the grid api, as normally
4040
* returned in the onRegisterApi method
41-
*
41+
*
4242
* @example
4343
* <pre>
4444
* gridApi.core.on.renderingComplete( grid );
@@ -52,9 +52,9 @@
5252
* @eventOf ui.grid.core.api:PublicApi
5353
* @description is raised after the filter is changed. The nature
5454
* of the watch expression doesn't allow notification of what changed,
55-
* so the receiver of this event will need to re-extract the filter
55+
* so the receiver of this event will need to re-extract the filter
5656
* conditions from the columns.
57-
*
57+
*
5858
*/
5959
this.registerEvent( 'core', 'filterChanged' );
6060

@@ -63,26 +63,26 @@
6363
* @name setRowInvisible
6464
* @methodOf ui.grid.core.api:PublicApi
6565
* @description Sets an override on the row to make it always invisible,
66-
* which will override any filtering or other visibility calculations.
66+
* which will override any filtering or other visibility calculations.
6767
* If the row is currently visible then sets it to invisible and calls
6868
* both grid refresh and emits the rowsVisibleChanged event
6969
* @param {object} rowEntity gridOptions.data[] array instance
7070
*/
7171
this.registerMethod( 'core', 'setRowInvisible', GridRow.prototype.setRowInvisible );
72-
72+
7373
/**
7474
* @ngdoc function
7575
* @name clearRowInvisible
7676
* @methodOf ui.grid.core.api:PublicApi
77-
* @description Clears any override on visibility for the row so that it returns to
78-
* using normal filtering and other visibility calculations.
77+
* @description Clears any override on visibility for the row so that it returns to
78+
* using normal filtering and other visibility calculations.
7979
* If the row is currently invisible then sets it to visible and calls
8080
* both grid refresh and emits the rowsVisibleChanged event
8181
* TODO: if a filter is active then we can't just set it to visible?
8282
* @param {object} rowEntity gridOptions.data[] array instance
8383
*/
8484
this.registerMethod( 'core', 'clearRowInvisible', GridRow.prototype.clearRowInvisible );
85-
85+
8686
/**
8787
* @ngdoc function
8888
* @name getVisibleRows
@@ -92,7 +92,7 @@
9292
* @returns {array} an array of gridRow
9393
*/
9494
this.registerMethod( 'core', 'getVisibleRows', this.grid.getVisibleRows );
95-
95+
9696
/**
9797
* @ngdoc event
9898
* @name rowsVisibleChanged
@@ -142,6 +142,16 @@
142142
* arguments: oldHeight, newHeight
143143
*/
144144
this.registerEvent( 'core', 'canvasHeightChanged');
145+
146+
/**
147+
* @ngdoc event
148+
* @name gridDimensionChanged
149+
* @eventOf ui.grid.core.api:PublicApi
150+
* @description is raised when the grid dimensions have changed (when autoResize is on)
151+
* <br/>
152+
* arguments: oldGridHeight, oldGridWidth, newGridHeight, newGridWidth
153+
*/
154+
this.registerEvent( 'core', 'gridDimensionChanged');
145155
};
146156

147157
/**
@@ -365,7 +375,7 @@
365375
});
366376

367377
};
368-
378+
369379
return GridApi;
370380

371381
}]);

test/unit/core/directives/ui-grid-menu.spec.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,10 @@ describe('ui-grid-menu', function() {
9292
api: {
9393
core: {
9494
on: {
95-
scrollBegin: angular.noop
95+
scrollBegin: angular.noop,
96+
gridDimensionChanged: function($scope, fxn) {
97+
fxn(100, 100, 400, 200);
98+
}
9699
}
97100
}
98101
}

0 commit comments

Comments
 (0)