【发布时间】:2019-10-13 21:58:00
【问题描述】:
{
headerName: "Generic/Specific",
field: "genericspecific",
id: "6",
cellRenderer:'genericSpecificCellRenderersComponent',
cellStyle: params => {
const colors: string[] = ["red", "orange"];
const genericSpecific: string[] = ["Generic", "Specific"];
return {
"background-color": colors[genericSpecific.indexOf(this.selectedOptions[params.node.id])]
};
}
}
如您所见,它有一个自定义的 Cell Renderer。这是它的定义:
@Component({
selector: "app-generic-specific-renderers",
template: `
<hr />
<select class="form-control" id='0' (change)="updateChosenValue($event.target); refresh(params)">
<option >{{ selectedOptions[params.node.id] }}</option>
<option >Specific</option>
<option >Generic</option>
</select>
<hr />
`
})
export class GenericSpecificCellRenderersComponent implements OnInit {
updateChosenValue(event) {
if (event.value==='Specific'){
this.selectedOptions[this.params.node.id]='Specific'
}
else if (event.value==='Generic'){
this.selectedOptions[this.params.node.id]='Generic'
}
}
selectedOptions:string[]=[];
constructor(private controlAssessmentData: ControlAssessmentService) {
this.controlAssessmentData.currentSelectedOptions.subscribe(
receivedSelectedOptions =>
(this.selectedOptions = receivedSelectedOptions)
);
}
ngOnInit() {}
public params: any;
public gridApi:any;
// called on init
agInit(params: any): void {
this.params = params;
this.gridApi= params.api;
}
// called when the cell is refreshed
refresh(params: any): boolean {
this.params = params;
this.gridApi.refreshCells()
console.log('this.params: ', this.params);
return true;
}
}
我想在用户每次从下拉列表中选择一个选项时刷新网格。
我认为我的代码应该可以工作,因为我在刷新定义网格时使用了相同的逻辑。
但是,它没有。
知道为什么吗?也许我该如何解决?
谢谢!
【问题讨论】:
-
导致刷新的事件:调用 api.refreshCells() 通知网格数据已更改(请参阅刷新)。
-
刷新单元格:api.refreshCells(cellRefreshParams) - 获取网格以刷新所有单元格。更改检测将用于仅刷新显示单元格值与实际值不同步的单元格。如果使用带有刷新方法的 cellRenderer,则会调用刷新方法。