【发布时间】:2020-09-12 22:42:22
【问题描述】:
我有一个按钮,它基本上可以导入一些数据。需要将此导入的数据与已加载的 ag-grid 中的数据进行比较,如果匹配,则将该特定行节点的 cehckbox 设置为 true。
这是检查条件的按钮:
enableCheck() {
alert('works');
if (this.DataService.isNotBlank(this.rowDataImport)) {
for (let i = 0; i < this.rowDataImport.length; i++) {
if (this.DataService.isNotBlank(this.rowData)) {
for (let j = 0; j < this.rowData.length; j++) {
if (this.DataService.isNotBlank(this.rowData[j].calDate)) {
for (const calDates of this.rowData[j].calDate) {
if (
this.rowDataImport[i].isin === calDates.isin ||
this.rowDataImport[i].portfolioName === calDates.portfolioName ||
this.rowDataImport[i].valuationDate === calDates.valuationDate
)
{
// alert('true')
this.checkValue = true;
} else {
this.checkValue = false;
}
}
}
}
}
}
}
}
this.checkValue 是一个标志,如果找到匹配则为真。
public gridColumnDefs = [
{
headerName: 'Portfolio Name',
field: 'portfolioName',
cellRenderer: 'agGroupCellRenderer',
headerCheckboxSelection: true,
headerCheckboxSelectionFilteredOnly: true,
checkboxSelection: true,
pinned: 'left',
filter: true,
cellRendererParams:(params) => {
console.log(params);
if (this.checkValue) {
params.node.selected = true;
}
}
},
]
这里我使用了 cellRendererParams。但这仅适用于负载我猜。如果我想从外部的值(即上面给出的导入检查)更新 ag-grid 行该怎么办?
【问题讨论】:
-
导入完成后您是否尝试过 api.refreshCells()?并添加您需要 else 条件来发送 params.node.selected = false
-
是的,我尝试了 setRowData 方法。它没有工作