angular - 如何为 ag-grid 中的特定行着色?
问题描述
我有一个 ag 网格,我只想为一些行号着色。例如,处理后我发现我只需要为第 1、4 和 5 行着色。
我尝试了 ag-grid 的 getRowStyle 函数但徒劳无功
gridOptions.getRowStyle = function(params) {
if (params.node.rowIndex % 2 === 0) {
return { background: 'red' }
}
}
解决方案
这是直接来自文档的一些代码
如果您只需要为某些行着色。您需要知道要为哪些行着色。我假设您对此有一个状态。也许一个变量叫做indices
?
indices: Array<number> = [1,4,5]; // color these rows
gridOptions.getRowStyle = (params) => { // should use params, not indices in the first braces. Binds the component to this. Can use indices in the function now
if (this.indices.includes(params.node.rowIndex)) {
return { background: 'red' }
}
}
如果您需要更多帮助,则需要更具体。我不知道什么不起作用。
这是一个带有示例的 Plunkr。我不确定您是如何在项目中设置所有内容的,但您可能会获得一些关于如何修改代码以适应我从 ag-grid 文档调整的示例的想法。我希望这个例子有帮助
推荐阅读
- jquery - 仅在桌面视图上使用 Sticky Text JQuery
- javascript - 为什么具有相同参数的 2 个对象具有不同的行为?
- ruby - 继承链中类实例变量的初始值
- r - 减去R中的多列
- r - 从 R 导出克里格值
- android - 带有消息的应用程序的权限
- sql - 每种数据库类型的 SQL Sleep() 语法
- spring-boot - 在我的 Spring 启动中: TransientObjectException: object references an unsaved transient instance - 在刷新之前保存瞬态实例
- c++ - 元组作为 C++ 中的模板
- dom-events - 在 JS 中创建 DOM 事件时,我不断收到错误消息