ag-grid-angular - 如何为我知道 ag-grid 中行索引和字段名称的单元格着色?
问题描述
let, row index = 5 & field = 'age' 现在,如何在 ag-grid 中为 row = 5 & field = 'age' 的单元格着色?我已经尝试了过去两天,但未能实现这一点。
解决方案
我想你有一个包含行索引和字段名称的对象数组:
rowIndexes = [
{ row: 3, field: ['age']},
{ row: 5, field: ['name']},
{ row: 10, field: ['name', 'salary'] }
];
cellStyle
为每个 columnDef添加属性:
{
headerName: 'Name',
field: 'name',
cellStyle: (params) => {
let rowIndex = params.node.rowIndex;
if (this.isColoredCell(rowIndex, 'name'))
return { backgroundColor: 'red' }
return null;
}
}
...
...
并将您的逻辑添加到isColoredCell
方法中:
isColoredCell(rowIndex: number, field: string): boolean {
let indexes = this.rowIndexes.filter(item => item.row == rowIndex);
if (indexes.length > 0) {
let fields = indexes[0].field;
if (fields.indexOf(field) > -1) {
return true;
}
return false;
}
return false;
}
希望你能以这种方式为你的细胞着色。
推荐阅读
- php - password_verify 始终返回 true
- nginx - 两个反向代理后面的气流 - 图 GET 请求不包含任何 DAG ID
- c++ - TTF_RenderText_Blend() 生成的奇怪的文本阴影?
- android - 媒体不允许主目录下载
- r - 如何在条形图中按月汇总数据总和?
- python-3.x - 通过 pip 安装 vowpalwabbit 会出现错误“目标模式不包含 % ... 目标配方失败”
- python-3.x - 消息框后的entry_focus怎么做
- python-3.x - Python 类继承 - 均值,错误:未定义均值
- c# - 如何将csv文件读入列表
- > 使用 CSVHelper
- airflow - 使用 Logstash 解析嵌套的 Apache Airflow 日志行