【发布时间】:2019-03-01 07:11:27
【问题描述】:
我需要在 2 种情况下向我的 Ag-grid 添加一些列。其他情况我只需要基列。
所以在构造函数中我这样声明我的网格:
this.gridOption.columnDefs = [
{
headerName: 'Admission date',
field: 'admissionPlannedDate',
cellRendererFramework: DateCellRendererComponent,
cellRendererParams: (params) => {
return (params.data.admissionPlannedDate ? {dateFormat: 'dd.MM.yyyy - HH:mm'} : {dateFormat: ' '});
},
cellStyle: function (params) {
return (params.data.admissionPlannedDate < new Date() ? {color: 'red'} : {});
}
},
{
headerName: 'Lastname',
field: 'lastName',
cellStyle: function (params) {
return (params.data.edsId === null ? {color: 'orange'} : {});
}
},
},
{
headerName: 'Sex',
field: 'sex',
},
{
headerName: 'Birthdate',
field: 'birthDate',
cellRendererFramework: DateCellRendererComponent,
cellRendererParams: (params) => {
return (params.data.birthDate ? {dateFormat: 'dd.MM.yyyy'} : {dateFormat: ' '});
},
},
{
headerName: 'Localisation',
field: 'localisation',
}
];
然后在我的 ngOnInit 中,在某些情况下我需要将列添加到我的 ag-grid。
我尝试了以下方法:
this.gridOption.columnDefs.push(
{
headerName: 'Block',
field: 'block',
}, {
headerName: 'SDS/Hosp',
field: 'sdsOrHosp'
}
);
console.log(this.gridOption); //I see the new columns here so the add worked but i don't see them visual in my grid
也试过了
this.gridOption.columnDefs.push({ headerName: 'Bloc', field:'block'});
this.gridOption.columnDefs.push({ headerName: 'SDS/Hosp', field:'SDSorHosp'});
有人有想法吗? 谢谢
【问题讨论】: