Kendo UI for Angular2-网格如何动态添加列 [英] Kendo UI for Angular2 - Grid How to Add Columns Dynamically

查看:226
本文介绍了Kendo UI for Angular2-网格如何动态添加列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于Grid compomemet,如果我已经在html中预定义了几列,但结果集可以在预定义的列之上有许多其他列,那么我该如何动态添加这些列?

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?

在检索数据之后,才知道这些多余的列是什么?在使用ViewChild指令获取数据后,我能够访问网格组件,但是查看网格列的数组就像对象一样,我看不到一种以编程方式实时添加列的方法.

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.

推荐答案

您可以使用ngFor生成可变数量的列:

You can use ngFor to make a variable number of columns:

    <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 UI for Angular2-网格如何动态添加列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆