我正在尝试让angular ui-grid自动调整高度,这样所有行都可以显示,而不需要滚动条,但如果网格中只有几行,就不会浪费空间。有人问过类似的问题(Angular ui-grid dynamically calculate height of the grid),但该问题的前提是行高是恒定的。如果行高不同(例如,因为您启用了自动换行),则问题的公认解决方案(https://stackoverflow.com/a/28706349/877570)将不起作用,因为问题的解决方案假定行高不变。如果我有一个包含大量文本的单元格,并且文本换行到下一行,那么行的高度就不同了。
我在这里找到了一个可能的解决方案:(https://github.com/angular-ui/ui-grid/issues/1735)
.ui-grid, .ui-grid-viewport {
height: auto !important;
}“当然,minRowsToShow和virtualizationThreshold应该设置为列表的大小。”
然而,当我部署他的解决方案时,网格的渲染时间要长得多。
有没有人知道如何解决这个问题,或者有其他解决方案?
发布于 2016-10-29 03:51:44
$scope._minRows = 10;
$scope._maxRows = 10;
// Lots of Grid Options, plus data setting going on here.
$scope.agendaItemsGridOptions.onRegisterApi = function(gridApi) {
//set gridApi on scope
$scope.gridApi = gridApi;
});
var setMinRowsLogic = function() {
$scope.gridApi.grid.options.minRowsToShow = $scope._minRows;
if (!_.isUndefined($scope.agendaItemsGridOptions.data)) {
var len = $scope.agendaItemsGridOptions.data.length;
if (len > $scope._maxRows) {
$scope.gridApi.grid.options.minRowsToShow = $scope._maxRows;
} else
if (len < $scope._minRows) {
$scope.gridApi.grid.options.minRowsToShow = $scope._minRows;
} else {
$scope.gridApi.grid.options.minRowsToShow = len;
}
}
};https://stackoverflow.com/questions/40311664
复制相似问题