【发布时间】:2019-03-16 04:29:23
【问题描述】:
我在我的 Angular 6 应用程序中使用社区版的“AG Grid”。
我现在面临的挑战是:我有一个相当简单的数据结构,其中的列表绑定到网格以进行显示。根据它的值,我想在网格中添加一个“Actions”列,让用户可以访问某些操作,例如删除一个条目,“提升”它等等。
对于单独的数据绑定列,我得到每行绑定时的相应数据值,例如,我可以使用 单元格渲染器 格式化显示。我希望我能够用我的“动作”列(它不绑定到类的特定数据元素)做类似的事情——但似乎我的“动作单元渲染器”没有任何基础其决定。
我有一个类似这样的数据结构:
export interface Indicator {
Id: string;
Name: string;
IsGlobal: boolean;
}
这些Indicators 的数组被绑定到我的Angular 组件的OnInit 函数中的AG 网格。
我将 AG 网格的列定义为:
columnDefs = [
{ headerName: 'Name', field: 'Name', width: 200, editable: true },
{ headerName: 'Global', field: 'IsGlobal', editable: false, width: 100,
cellRenderer: (data) => {
// here, "data" refers to the "IsGlobal" value of the row being displayed
if (data.value === true) {
return 'Ja';
} else {
return 'Nein';
}
},
},
{ headerName: 'Actions', width: 125,
cellRenderer: (data) => {
// here, I was hoping the "data" would refer to the entire
// row / object being bound, so that I could check for
// certain conditions to be true (or false)
if (data.IsGlobal.value === true)
{
return '<span class="far fa-trash-alt mr-2" title="Delete entry"></span>' +
'<span class="fab fa-nintendo-switch" title="Promote entry"></span>';
}
else
{
return '<span class="far fa-trash-alt mr-2" title="Delete"></span>';
}
}
}
];
我希望能够在我的列定义中定义我的操作列显示一个“提升条目”按钮仅当当前有问题的行的数据具有IsGlobal = false。我希望传递给单元格渲染器的data 将是整个行数据对象(Indicator 类型) - 但情况似乎并非如此。
如何决定在我的列定义中的“操作”列中显示哪些图标?
【问题讨论】:
标签: typescript angular6 ag-grid