Reputation:
In my Jquery&JavaScript, Angular, all seperate applications i have included Ag-Grid with columnDefs like below :-
this.columnDefs = [
{
headerName: "Age",
field: "age",
cellRenderer: "agGroupCellRenderer"
},
{
headerName: "Name",
field: "name"
},
{
headerName: "Year",
field: "year"
},
{
headerName: "Country",
field: "country"
}
];
and my row Data is like below
this.rowData = [
{
age: "Group A",
participants: [
{
age: 1,
name: "Michael Phelps",
year: "2008",
country: "United States"
},
{
name: "A.2",
age: 2,
year: "2008",
country: "United States"
},
{
name: "A.3",
age: 50,
year: "2008",
country: "United States"
}
]}];
this.getNodeChildDetails = function getNodeChildDetails(rowItem) {
if (rowItem.participants) {
return {
group: true,
children: rowItem.participants,
};
} else {
return null;
}
Now i want to attach cellClass to children grid values based on validation, like:-
if(age< 23 || ''){
return['classNameThatiWantToAttach'];
}
How to do this ??
You can make changes in below plunker also for this: -
https://plnkr.co/edit/lmjtuqfId4FIsTI5luL8?p=preview
Upvotes: 0
Views: 1016
Reputation: 5602
Please see the updated plunkr showing a cell in red color as per validation of the age:
https://plnkr.co/edit/QZd2MM1LflQaruxdCmym?p=preview
this.columnDefs = [
// ...
{
headerName: "Age",
field: "age",
cellClassRules: this.getCssClass()
}
// ...
];
getCssClass(): {[cssClassName: string]: (Function | string)} {
return {
'invalid-age': this.validateAge(),
};
}
Upvotes: 0
Reputation: 3082
You can do it like this
edit the column definitions and add a cellClass function to it
{
headerName: "Year",
field: "year",
editable: true,
cellClass: this.cellClass
}
Then define the function and add the conditions you need and return a string with the value of the class
cellClass(params) {
if (params.value >= 2015)
return "redClass"
}
Don't forget to add the css styling for the classes.
Upvotes: 2