在我的Angular的Jquery&JavaScript中,所有单独的应用程序都包括带有columnDef的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'];
 }


这个怎么做 ??

您还可以为此在下面的代码中进行更改:-

https://plnkr.co/edit/lmjtuqfId4FIsTI5luL8?p=preview

最佳答案

你可以这样

编辑列定义并向其添加cellClass函数

 {
    headerName: "Year",
    field: "year",
    editable: true,
    cellClass: this.cellClass
  }


然后定义函数并添加所需条件,并返回带有类值的字符串

  cellClass(params) {
    if (params.value >= 2015)
      return "redClass"
  }


不要忘记为类添加css样式。

Example

10-06 15:09