简体   繁体   English

AngularJS ng-Grid启动最小化了吗?

[英]AngularJS ng-Grid starts minimized?

I'm using ng-Grid v2.0.7, and the problem is that the first time that ng-grid shows, it is minimized. 我正在使用ng-Grid v2.0.7,问题是ng-grid第一次显示时,它已被最小化。 Here is a picture of what I mean: 这是我的意思的图片:

在此处输入图片说明

Only after clicking on the minimized table (the top picture), the full table displays normally (the bottom picture).. Here is the code I'm using: 仅在单击最小化表(顶部图片)后,整个表才能正常显示(底部图片)。这是我正在使用的代码:

$scope.gridOptions = {
    data: 'jsonData.value',
    multiSelect: false
};

Why is this happening? 为什么会这样呢?

EDIT: Here is the definition in the html file: 编辑:这是html文件中的定义:

<div class="gridStyle" ng-show="(dataViewType == 'table')" ng-grid="gridOptions"></div>

Try to use the ng-cloak directive on your grid element. 尝试在网格元素上使用ng-cloak指令。

For example on a simple div : 例如在一个简单的div上:

<div ng-cloak></div> 

"The ngCloak directive is used to prevent the Angular html template from being briefly displayed by the browser in its raw (uncompiled) form while your application is loading. Use this directive to avoid the undesirable flicker effect caused by the html template display." “ ngCloak指令用于防止在加载应用程序时浏览器以原始(未编译)形式简短地显示Angular html模板。使用此指令可避免html模板显示引起的不希望的闪烁效果。”

Docs : http://docs.angularjs.org/api/ng.directive:ngCloak 文件: http : //docs.angularjs.org/api/ng.directive : ngCloak

I had a similar problem and it was caused by CSS properties. 我有一个类似的问题,它是由CSS属性引起的。

It was because I set height & width as percentages, rather than a fixed number of pixels. 这是因为我将高度和宽度设置为百分比,而不是固定的像素数。

Changing them to a fixed number of pixels removed the problem (leaving me only with the problem of what values to choose to accommodate my dynamic JSON data). 将它们更改为固定数量的像素可以解决此问题(仅让我留意要选择哪些值来容纳我的动态JSON数据的问题)。

I ended up with this in my controller: 我最终在控制器中得到了这个:

    $scope.getTableStyle= function() {
       var rowHeight=30;
       var headerHeight=45;
       return {
          height: (gridHeaderHeight + 1 + 
                  ($scope.myGrid.length * (gridRowHieght + 1))) + "px"
       };
    };  

and this in my HTML 这在我的HTML中

   <div ng-show="myGrid" class="gridStyle" ng-grid="gridOptions" 
        ng-style="getTableStyle()" ng-cloak></div>

In order to calculate the grid size whenever I periodically fetch new JSON data from the server. 为了计算网格大小,每当我定期从服务器获取新的JSON数据时。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM