首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >angular ui-如果行的高度不恒定,则网格自动高度

angular ui-如果行的高度不恒定,则网格自动高度
EN

Stack Overflow用户
提问于 2016-10-29 03:03:16
回答 1查看 1.6K关注 0票数 2

我正在尝试让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)

代码语言:javascript
复制
.ui-grid, .ui-grid-viewport {
  height: auto !important;
}

“当然,minRowsToShow和virtualizationThreshold应该设置为列表的大小。”

然而,当我部署他的解决方案时,网格的渲染时间要长得多。

有没有人知道如何解决这个问题,或者有其他解决方案?

EN

回答 1

Stack Overflow用户

发布于 2016-10-29 03:51:44

代码语言:javascript
复制
    $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;
            }
        }
    };
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40311664

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档