Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
本质上,我想做的是根据单元格的值将其他 CSS 类应用于数据网格中的单个单元格。例如,当美元值为负时,将文本涂成红色。
我发现的唯一解决方案是使用列的格式化程序为跨度创建一个字符串,该跨度具有基于传入值的类。我认为必须有更好的方法。
指定结构时,您传入一个表示给定列的小部件配置的对象。作为该对象的一部分,在定义中包含一个格式化函数:
{ ... formatter: function(val, rowIdx, cell) { classes = compute_classes(val, rowIdx, cell); cell.customClasses.push(classes); } }
但是,您的“compute_classes”计算要使用的类取决于您。它们将应用于单元格,然后您可以在 CSS 中管理它们的外观。