简体   繁体   English

Angular2的Kendo UI - 网格如何动态添加列

[英]Kendo UI for Angular2 - Grid How to Add Columns Dynamically

For the Grid compomemet, if I already have a couple columns predefined in the html but the resultset can have a variety of additional columns on top of the predefined ones, how can I dynamically adds those columns? 对于Grid compomemet,如果我已经在html中预定义了几列但是结果集可以在预定义列之上添加各种其他列,那么如何动态添加这些列呢?

There is no way to know what those extra columns are until after I retrieve the data? 在检索数据之前,无法知道这些额外的列是什么? I am able to access the grid component after the data is fetched using the ViewChild directive, but looking over the grid's columns' array like object, I don't see a way to add columns programmatically on the fly. 我可以在使用ViewChild指令获取数据后访问网格组件,但查看网格的列的数组就像对象一样,我没有看到以动态编程方式添加列的方法。

You can use ngFor to make a variable number of columns: 您可以使用ngFor创建可变数量的列:

    <kendo-grid [data]="gridData">
      <ng-template ngFor [ngForOf]="columns" let-column>
        <kendo-grid-column field="{{column}}"></kendo-grid-column>
      </ng-template>
    </kendo-grid>

If you want to try this out, see the "showing and hiding columns" demo in the docs (scroll down in the columns examples ). 如果您想尝试这一点,请参阅文档中的“显示和隐藏列”演示(在列示例中向下滚动)。

  <kendo-grid [data]="gridData"> </kendo-grid> 

You can directly add "gridData" without column names. 您可以直接添加没有列名的“gridData”。

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

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