Reputation: 1207
Ag grid column definition
columnDefs = [
{ headerName: "Status", field: "statusCode", cellStyle: {'background-color': 'green'}}, }
]
Instead of hard coding color, its getting from server.
columnDefs = [
{ headerName: "Status", field: "statusCode", cellStyle: {'background-color': ['colorVal']}}, }
]
colorVal will have value like red or green, but the above syntax is not working.
This is the json that I'm setting to the rowData of ag-grid.
{"statusCode":101,"colorVal":green}
Can I set using or use this.gridOptions. ?
Upvotes: 0
Views: 4081
Reputation: 1207
@Basavaraj Thanks for the hint.
columnDefs = [
{ headerName: "Status", field: "statusCode",cellStyle: this.cellStyling},
]
Call this method to display style dynamically
cellStyling(params:any){
return {'background-color': params.data.colourCode};
}
Upvotes: 2
Reputation: 86800
try this
let data= {"statusCode":101,"colorVal":green}
columnDefs = [
{ headerName: "Status", field: "statusCode", cellStyle: {'background-color': data.colorVal}}, }
]
here let
is a local variable you have to use this within the scope of your method
PS:- Too long for comment so posting this as answer.
Upvotes: 0