简体   繁体   English

AngularJS - ng-grid数据不会显示在列大小调整上

[英]AngularJS - ng-grid data does not display on column resizing

I'm facing an issue where ng-grid data does not display on column resizing, when column names change. 我正面临一个问题,当列名称更改时,ng-grid数据不会显示在列大小调整上。

Created a plunkr at - http://plnkr.co/edit/eV9baoDOV9A46FZmKW8G?p=preview 在 - http://plnkr.co/edit/eV9baoDOV9A46FZmKW8G?p=preview创建了一个plunkr

Please note the below function in main.js to explicitly change the column names and corresponding data. 请注意main.js中的以下函数,以显式更改列名和相应的数据。

$scope.reload = function(){
  $scope.columnDefinitions = [
      {field: 'first_col'},
      {field: 'second_col'}
    ];

  $scope.myData = [{first_col: "colData1", second_col: "colData2"},
                  {first_col: "colData3", second_col: "colData4"},
                  {first_col: "colData5", second_col: "colData6"}
                ];  
}

Steps - 脚步 -

Scenario 1 (works) . 场景1(有效)

  1. Once the example fully loads including data from ng-grid, click on the "change" button. 一旦示例完全加载包括来自ng-grid的数据,请单击“更改”按钮。
  2. With that, the "name" and "age" columns will change to "first_col" and "second_col" along with corresponding data. 这样,“name”和“age”列将变为“first_col”和“second_col”以及相应的数据。

Scenario 2 (doesn't work) 场景2(不起作用)

  1. Rerun the example. 重新运行这个例子。
  2. Once the example fully loads including data from ng-grid, resize the columns a bit. 一旦示例完全加载包括来自ng-grid的数据,请稍微调整列的大小。
  3. After resizing, click the "change" button. 调整大小后,单击“更改”按钮。
  4. The grid now shows up as empty. 网格现在显示为空。

Really stuck with this issue. 真的坚持这个问题。 Any help will be much appreciated. 任何帮助都感激不尽。

It seems the width of the column is not getting picked up when you press change. 当你按下更改时,似乎没有拾取列的宽度。 If you manually define it , it will work : 如果您手动定义它 ,它将工作:

{field: 'first_col', width: 200},
{field: 'second_col', width: 200}

From the ng-grid documentation : 来自ng-grid文档

Width can also be defined in percentages (20%, 30%), in weighted *s, or "auto" (which sizes the column based on data length) (much like WPF/Silverlight)/ note: "auto" only works in single page apps currently because the re-size happens on "document.ready". 宽度也可以用百分比(20%,30%),加权* s或“自动”(根据数据长度调整列的大小)来定义(非常类似于WPF / Silverlight)/ 注意:“auto”仅适用于单页应用程序目前因为重新调整大小发生在“document.ready”上。 Still working on improving that . 仍在努力改善这一点

So I'm guessing it's defaulting on "auto" and that's why it's not working. 所以我猜它是默认的“自动”,这就是为什么它不起作用。 If you try putting "auto" (or anything %-based) as width, you'll also get the error. 如果你尝试将“auto”(或任何基于%的)作为宽度,你也会得到错误。 I suggest you use a workaround in the meantime. 我建议你在此期间使用解决方法。

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

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