gpt4 book ai didi

javascript - Ag-Grid 树状结构根据验证将 cellClass 附加到 NodeChildren 单元

转载 作者:行者123 更新时间:2023-12-02 23:50:36 29 4
gpt4 key购买 nike

在我的 Jquery&JavaScript、Angular、所有单独的应用程序中,我都包含了 Ag-Grid 和 columnDefs,如下所示:-

 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

关于javascript - Ag-Grid 树状结构根据验证将 cellClass 附加到 NodeChildren 单元,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55666503/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com