Skip to content

Commit

Permalink
fix: Introduce gridDimensionChanged event
Browse files Browse the repository at this point in the history
Closes #5090
  • Loading branch information
dlgski authored and Dana Greenberg committed Feb 11, 2016
1 parent c61f680 commit 40ec65c
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 21 deletions.
1 change: 1 addition & 0 deletions src/features/auto-resize-grid/js/auto-resize.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
if (newGridHeight !== prevGridHeight || newGridWidth !== prevGridWidth) {
uiGridCtrl.grid.gridHeight = newGridHeight;
uiGridCtrl.grid.gridWidth = newGridWidth;
uiGridCtrl.grid.api.core.raise.gridDimensionChanged(prevGridHeight, prevGridWidth, newGridHeight, newGridWidth);

$scope.$apply(function () {
uiGridCtrl.grid.refresh()
Expand Down
16 changes: 11 additions & 5 deletions src/js/core/directives/ui-grid-menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,25 @@ function ($compile, $timeout, $window, $document, gridUtil, uiGridConstants, i18
templateUrl: 'ui-grid/uiGridMenu',
replace: false,
link: function ($scope, $elm, $attrs, uiGridCtrl) {
var gridMenuMaxHeight;

$scope.dynamicStyles = '';

if (uiGridCtrl) {
var setupHeightStyle = function(gridHeight) {
// magic number of 30 because the grid menu displays somewhat below
// the top of the grid. It is approximately 30px.
gridMenuMaxHeight = uiGridCtrl.grid.gridHeight - 30;
$scope.dynamicStyles = [
var gridMenuMaxHeight = gridHeight - 30;
$scope.dynamicStyles = [
'.grid' + uiGridCtrl.grid.id + ' .ui-grid-menu-mid {',
'max-height: ' + gridMenuMaxHeight + 'px;',
'max-height: ' + gridMenuMaxHeight + 'px;',
'}'
].join(' ');
};

if (uiGridCtrl) {
setupHeightStyle(uiGridCtrl.grid.gridHeight);
uiGridCtrl.grid.api.core.on.gridDimensionChanged($scope, function(oldGridHeight, oldGridWidth, newGridHeight, newGridWidth) {
setupHeightStyle(newGridHeight);
});
}

$scope.i18n = {
Expand Down
40 changes: 25 additions & 15 deletions src/js/core/factories/GridApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
var GridApi = function GridApi(grid) {
this.grid = grid;
this.listeners = [];

/**
* @ngdoc function
* @name renderingComplete
Expand All @@ -31,14 +31,14 @@
* time as `onRegisterApi`, but provides a way to obtain
* that same event within features without stopping end
* users from getting at the onRegisterApi method.
*
*
* Included in gridApi so that it's always there - otherwise
* there is still a timing problem with when a feature can
* call this.
*
* @param {GridApi} gridApi the grid api, as normally
* call this.
*
* @param {GridApi} gridApi the grid api, as normally
* returned in the onRegisterApi method
*
*
* @example
* <pre>
* gridApi.core.on.renderingComplete( grid );
Expand All @@ -52,9 +52,9 @@
* @eventOf ui.grid.core.api:PublicApi
* @description is raised after the filter is changed. The nature
* of the watch expression doesn't allow notification of what changed,
* so the receiver of this event will need to re-extract the filter
* so the receiver of this event will need to re-extract the filter
* conditions from the columns.
*
*
*/
this.registerEvent( 'core', 'filterChanged' );

Expand All @@ -63,26 +63,26 @@
* @name setRowInvisible
* @methodOf ui.grid.core.api:PublicApi
* @description Sets an override on the row to make it always invisible,
* which will override any filtering or other visibility calculations.
* which will override any filtering or other visibility calculations.
* If the row is currently visible then sets it to invisible and calls
* both grid refresh and emits the rowsVisibleChanged event
* @param {object} rowEntity gridOptions.data[] array instance
*/
this.registerMethod( 'core', 'setRowInvisible', GridRow.prototype.setRowInvisible );

/**
* @ngdoc function
* @name clearRowInvisible
* @methodOf ui.grid.core.api:PublicApi
* @description Clears any override on visibility for the row so that it returns to
* using normal filtering and other visibility calculations.
* @description Clears any override on visibility for the row so that it returns to
* using normal filtering and other visibility calculations.
* If the row is currently invisible then sets it to visible and calls
* both grid refresh and emits the rowsVisibleChanged event
* TODO: if a filter is active then we can't just set it to visible?
* @param {object} rowEntity gridOptions.data[] array instance
*/
this.registerMethod( 'core', 'clearRowInvisible', GridRow.prototype.clearRowInvisible );

/**
* @ngdoc function
* @name getVisibleRows
Expand All @@ -92,7 +92,7 @@
* @returns {array} an array of gridRow
*/
this.registerMethod( 'core', 'getVisibleRows', this.grid.getVisibleRows );

/**
* @ngdoc event
* @name rowsVisibleChanged
Expand Down Expand Up @@ -142,6 +142,16 @@
* arguments: oldHeight, newHeight
*/
this.registerEvent( 'core', 'canvasHeightChanged');

/**
* @ngdoc event
* @name gridDimensionChanged
* @eventOf ui.grid.core.api:PublicApi
* @description is raised when the grid dimensions have changed (when autoResize is on)
* <br/>
* arguments: oldGridHeight, oldGridWidth, newGridHeight, newGridWidth
*/
this.registerEvent( 'core', 'gridDimensionChanged');
};

/**
Expand Down Expand Up @@ -365,7 +375,7 @@
});

};

return GridApi;

}]);
Expand Down
5 changes: 4 additions & 1 deletion test/unit/core/directives/ui-grid-menu.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,10 @@ describe('ui-grid-menu', function() {
api: {
core: {
on: {
scrollBegin: angular.noop
scrollBegin: angular.noop,
gridDimensionChanged: function($scope, fxn) {
fxn(100, 100, 400, 200);
}
}
}
}
Expand Down

0 comments on commit 40ec65c

Please sign in to comment.