Ag-Grid 树状结构根据验证将 cellClass 附加到 NodeChildren 单元格
Ag-Grid Tree like structure attach cellClass to NodeChildren cells based on validation
在我的 Jquery&JavaScript、Angular 中,我在所有单独的应用程序中都包含了带有 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'];
}
如何操作??
您也可以为此在下面的插件中进行更改:-
你可以这样做
编辑列定义并向其添加 cellClass 函数
{
headerName: "Year",
field: "year",
editable: true,
cellClass: this.cellClass
}
然后定义函数并添加你需要的条件和return一个字符串,其值为class
cellClass(params) {
if (params.value >= 2015)
return "redClass"
}
不要忘记为 class 添加 css 样式。
请查看更新后的 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(),
};
}
在我的 Jquery&JavaScript、Angular 中,我在所有单独的应用程序中都包含了带有 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'];
}
如何操作??
您也可以为此在下面的插件中进行更改:-
你可以这样做
编辑列定义并向其添加 cellClass 函数
{
headerName: "Year",
field: "year",
editable: true,
cellClass: this.cellClass
}
然后定义函数并添加你需要的条件和return一个字符串,其值为class
cellClass(params) {
if (params.value >= 2015)
return "redClass"
}
不要忘记为 class 添加 css 样式。
请查看更新后的 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(),
};
}