在我的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'];
}如何做到这一点?
你也可以在下面的柱塞器中进行更改:
发布于 2019-04-14 04:53:13
你可以这样做
编辑列定义并向其中添加cellClass函数
{
headerName: "Year",
field: "year",
editable: true,
cellClass: this.cellClass
}然后定义函数并添加所需的条件,并返回一个包含类的值的字符串
cellClass(params) {
if (params.value >= 2015)
return "redClass"
}不要忘记为这些类添加css样式。
发布于 2019-04-14 05:07:28
请参阅更新后的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(),
};
}https://stackoverflow.com/questions/55666503
复制相似问题