在我的jQuery和JavaScript Angular中,所有单独的应用程序都包括带有columnDefs的Ag-Grid,如下所示:-
this.columnDefs = [
{
headerName: "Age",
field: "age",
cellRenderer: "agGroupCellRenderer"
},
{
headerName: "Name",
field: "name"
},
{
headerName: "Year",
field: "year"
},
{
headerName: "Country",
field: "country"
}
];
我的行数据如下所示
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;
}
现在,我想基于验证将cellClass附加到子网格值,例如:-
if(age< 23 || ''){
return['classNameThatiWantToAttach'];
}
如何执行此操作?
您也可以在下面的导航器中进行更改:-
答案 0 :(得分:0)
您可以这样做
编辑列定义并向其添加cellClass函数
{
headerName: "Year",
field: "year",
editable: true,
cellClass: this.cellClass
}
然后定义函数并添加所需条件,并返回带有类值的字符串
cellClass(params) {
if (params.value >= 2015)
return "redClass"
}
别忘了为类添加css样式。
答案 1 :(得分:0)
请按照年龄进行验证,查看更新后的plunkr显示的单元格为红色:
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(),
};
}