Inside my grid, I have this column:
{
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])]
};
}
}
As you can see, it has a custom Cell Renderer. Here's its definition:
@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;
}
}
I wanted to refresh the grid everytime the user chooses an option from the dropDown list.
I thought my code should work, because I used the same logic when refreshing the grid where it was defined.
However, it didn't.
Any idea why? And maybe how I can solve it?
Thank you!