I am using agGrid in Angular.
I need to set background color of cell to yellow when cell value changed and background color to red when someone edit to make the value empty.
Here's the code
import { Component, OnInit } from '@angular/core';
import { APICallService } from '../../.././PortalServices/webapicall.service';
@Component({
selector: 'master-gender',
templateUrl: 'app/PortalPages/MasterPages/GenderMaster/gender.component.html',
providers: [APICallService],
})
export class GenderComponent implements OnInit {
private updateDict = new Map();
genderRowData: [];
constructor(private genderService: APICallService) {
}
ngOnInit() {
this.genderService.getApiCall('getallgenders')
.subscribe((rowData) => this.genderRowData = rowData,
(error) => { alert(error) }
);
}
columnDefs = [
{
headerName: 'Gender Name', field: 'Name',
onCellValueChanged: this.genderCellValueChanged.bind(this)
},
]
genderCellValueChanged(event: any) {
const cell = event.api.getFocusedCell();
if (event.oldValue !== event.newValue) {
if (event.newValue == '')
cell.column.colDef.cellStyle = { 'background-color': 'red' };
else
cell.column.colDef.cellStyle = { 'background-color': 'yellow' };
}
event.api.refreshCells(cell);
}
}
The cellStyle never applied when cell value changed for first time. However when I try to edit the cell for second time then cellStyle applied. I tried to use redrawRows() but it is affecting whole column which I dont want. I want to change the style of cell whenever value is getting changed.
How to refresh the style instantly?