11

我正在尝试使用 Angular ng-grid 来显示一些动态内容。网格将有 0 - 25 行。我想要一个最小尺寸,然后让 ng-grid 自动调整高度,因为项目被添加到数组中。由于某种原因,添加 6-7 个项目后自动大小停止(它甚至似乎取决于您的分辨率)。

任何人都可以帮忙吗?我错过了什么?我在下面有一个显示问题的 Plunker。

http://plnkr.co/edit/frHbLTQ68GjMgzC59eSZ?p=preview

4

3 回答 3

1

If you are still having issues I would suggestion not using the ng-grid and create your layout directly in html (Use DIVs, column width formatting, styles, etc...). Then populate your new layout using your $scope. Between variables, models and ng-repeat you should be able to do everything you need.

于 2015-03-25T22:25:31.267 回答
0

下面的代码是对插件的修改。它通过检查网格数据中的项目数并据此计算高度来工作。传递给插件的选项是行高和标题高度。

ngGridCustomFlexibleHeightPlugin = function (opts) {
    var self = this;
    self.grid = null;
    self.scope = null;
    self.init = function (scope, grid, services) {
        self.domUtilityService = services.DomUtilityService;
        self.grid = grid;
        self.scope = scope;
        var recalcHeightForData = function () { setTimeout(innerRecalcForData, 1); };
        var innerRecalcForData = function () {
            var gridId = self.grid.gridId;
            var footerPanelSel = '.' + gridId + ' .ngFooterPanel';
            var extraHeight = self.grid.$topPanel.height() + $(footerPanelSel).height();
            var naturalHeight = (grid.data.length - 1) * opts.rowHeight + opts.headerRowHeight;
            self.grid.$viewport.css('height', (naturalHeight + 2) + 'px');
            self.grid.$root.css('height', (naturalHeight + extraHeight + 2) + 'px');
           // self.grid.refreshDomSizes();
            if (!self.scope.$$phase) {
                self.scope.$apply(function () {
                    self.domUtilityService.RebuildGrid(self.scope, self.grid);
                });
            }
            else {
                // $digest or $apply already in progress
                self.domUtilityService.RebuildGrid(self.scope, self.grid);
            }
        };
        scope.$watch(grid.config.data, recalcHeightForData);

    };
};
于 2014-03-03T17:37:30.183 回答
0

我发现在样式表上使用这段代码解决了我的问题。我禁用了插件,但无论哪种方式都可以。

 .ngViewport.ng-scope{
    height: auto !important;
    overflow-y: hidden;
}

.ngTopPanel.ng-scope, .ngHeaderContainer{
    width: auto !important;
}
.ngGrid{
    background-color: transparent!important;
}

我希望它可以帮助某人

于 2016-04-08T19:27:20.167 回答