|
// Button click function
onClick() {
if (this.flag) {
// Each new column is pushed directly to the Grid columns
this.newColumns.forEach(column=> {
this.gridObj.columns.push(column);
});
// Grid columns are refreshed
this.gridObj.refreshColumns();
this.flag = false;
}
} |
|
export class AppComponent {
// Template is accessed using its selector id
@ViewChild('template') template: TemplateRef<{}>;
ngOnInit(): void {
this.newColumns = [
{
field: 'ShipCountry',
headerText: 'Ship Country',
width: '120'
},
{
field: 'ShipName',
headerText: 'Ship Name',
width: '140'
}
]
}
onClick() {
if (this.flag) {
this.newColumns.forEach(column=> {
// Template reference accessed is set to the Grid columns template property
column.template = this.template;
this.gridObj.columns.push(column);
});
this.gridObj.refreshColumns();
this.flag = false;
}
}
} |