[英]How can i valid the data of an ag-grid cell?
I want to validate the cell, when the number will be different than 9 i want to change the background我想验证单元格,当数字与 9 不同时,我想更改背景
I have this table:我有这张表:
{
cellEditor: 'numberRenderer',
width: 150,
cellClass: this.compareValues,
newValueHandler: this.compareValues,
cellEditorParams: {
required: true,
},
compareValues(params) {
return params.value === 9?'':'myClass';
},
.myClass
background: var(--ag-header-background-color, #222628)
but when i put the number 9 i dont see the change of style, what is the problem?但是当我输入数字 9 时,我没有看到样式的变化,这是什么问题?
you need to make sure if you are doing type comparison with equality comparator then both side are of same type params.documentId === 9?'':'myClass';
你需要确保如果你正在用相等比较器进行类型比较,那么双方都是相同类型的params.documentId === 9?'':'myClass';
this will only work when params.documentId
is a number else it will always be false.这仅在params.documentId
是数字时才有效,否则它将始终为 false。 either change ===
to ==
comparison or make sure the types are same.要么将===
更改为==
比较,要么确保类型相同。
Try this using cellStyle
使用cellStyle
试试这个
{
cellEditor: 'numberRenderer',
cellStyle: function (params) {
if(params.value !==9){
setTimeout(() => {
params.api.refreshCells({
force: true,
rowNodes: [params.api.node],
});
}, 10000);
return {background: 'red'};
}
}
}
params.api.refreshCells({
force: true,
rowNodes: [params.api.node]
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.