Created
December 23, 2016 02:39
-
-
Save uicoded/7dc429a77df30cae1f4238c31320a285 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function() { | |
angular | |
.module('myApp') | |
.directive('myUiGridResize', myUiGridResizeDirective); | |
/* @ngInject */ | |
function myUiGridResizeDirective(gridUtil, uiGridConstants) { | |
return { | |
restrict: 'A', | |
require: 'uiGrid', | |
link: function($scope, $elm, $attrs, uiGridCtrl) { | |
$scope.$watch($attrs.uiGrid + '.minRowsToShow', function(val) { | |
var grid = uiGridCtrl.grid; | |
// Initialize scrollbars (TODO: move to controller??) | |
uiGridCtrl.scrollbars = []; | |
// Figure out the new height | |
var contentHeight = grid.options.minRowsToShow * grid.options.rowHeight; | |
var headerHeight = grid.options.hideHeader ? 0 : grid.options.headerRowHeight; | |
var footerHeight = grid.options.showFooter ? grid.options.footerRowHeight : 0; | |
var columnFooterHeight = grid.options.showColumnFooter ? grid.options.columnFooterHeight : 0; | |
var scrollbarHeight = grid.options.enableScrollbars ? gridUtil.getScrollbarWidth() : 0; | |
var pagerHeight = grid.options.enablePagination ? gridUtil.elementHeight($elm.children(".ui-grid-pager-panel").height('')) : 0; | |
var maxNumberOfFilters = 0; | |
// Calculates the maximum number of filters in the columns | |
angular.forEach(grid.options.columnDefs, function(col) { | |
if (col.hasOwnProperty('filter')) { | |
if (maxNumberOfFilters < 1) { | |
maxNumberOfFilters = 1; | |
} | |
} | |
else if (col.hasOwnProperty('filters')) { | |
if (maxNumberOfFilters < col.filters.length) { | |
maxNumberOfFilters = col.filters.length; | |
} | |
} | |
}); | |
var filterHeight = maxNumberOfFilters * headerHeight; | |
var newHeight = headerHeight + contentHeight + footerHeight + columnFooterHeight + scrollbarHeight + filterHeight + pagerHeight; | |
$elm.css('height', newHeight + 'px'); | |
grid.gridHeight = $scope.gridHeight = gridUtil.elementHeight($elm); | |
// Run initial canvas refresh | |
grid.refreshCanvas(); | |
}); | |
} | |
}; | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment