This is a migrated thread and some comments may be shown as answers.

How to create dynamic columns from kendogriddetailtemplate

1 Answer 231 Views
Grid
This is a migrated thread and some comments may be shown as answers.
alex
Top achievements
Rank 1
Iron
Veteran
alex asked on 12 Apr 2021, 12:49 PM

Hello,
how can i create dynamic columns in a detail template?

I want to create as many columns as there are elements within 'data' as shown in the attached image

 

great regards, 

Alex

 

 

 

 

 

 

 

1 Answer, 1 is accepted

Sort by
0
Paul
Top achievements
Rank 2
Iron
Veteran
Iron
answered on 13 Jul 2021, 05:08 PM
You use an ngFor to loop the properties or columns of the object and put the template inside of that loop.
<ng-container *ngFor="let column of gridColumns">
      <kendo-grid-column
        field="{{column.field}}"
        title="{{column.title}}"
        width="{{column.width}}"
        [minResizableWidth]="column.minResizableWidth"
        [resizable]="column.resizable"
        [sortable]="column.sortable ? { mode: 'single', allowUnsort: false } : false"
        [filterable]="column.filterable"
        [hidden]="column.hidden"
        [lockable]="column.lockable"
        [locked]="column.locked"
        [columnMenu]="column.columnMenu"
        kendoGridSelectBy="nameId"
        [selectedKeys]="selectedKeys">

<ng-template kendoGridCellTemplate let-dataItem="dataItem" let-rowIndex="rowIndex">
In the above sample I am loading a list of columns to be displayed in the grid. You can put ngif in the cell template if you need to control how the data is displayed for an individual column.
Tags
Grid
Asked by
alex
Top achievements
Rank 1
Iron
Veteran
Answers by
Paul
Top achievements
Rank 2
Iron
Veteran
Iron
Share this question
or