您如何有条件地在Dojo数据网格中创建一个单元格? [英] How do you conditionally style a cell in a Dojo data grid?

查看:159
本文介绍了您如何有条件地在Dojo数据网格中创建一个单元格?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

本质上,我想做的是根据单元格的值将额外的CSS类应用到数据网格中的单个单元格。一个例子是当一个美元值为负值时,将文本颜色变成红色。

Essentially what I want to do is to apply additional CSS classes to individual cells in a data grid based on the value of the cell. An example would be to color the text red when a dollar value is negative.

我发现唯一的解决方案是使用列的格式化程序为跨过该类的字符串创建一个基于所传递的值的类。必须有一个更好的方法。

The only solution I've found was to use the formatter of the column to create a string for a span that has the class based on the value passed in. I figure there has to be a better way.

推荐答案

当指定结构时,您传递一个表示窗口小部件配置的对象给定列。作为此对象的一部分,在定义中包含格式化函数:

When specifying the structure, you pass in an object that represents the widget configuration for a given column. As part of this object, include a formatter function in the definition:

{
...
 formatter: function(val, rowIdx, cell) {
    classes = compute_classes(val, rowIdx, cell);
    cell.customClasses.push(classes);
  }
}

然而,您的'compute_classes'计算要使用的类由你决定。它们将被应用到单元格中,然后可以在CSS中管理它们的外观。

however your 'compute_classes' computes the classes to use is up to you. They will be applied to the cell, and then you can manage their appearance in your CSS.

这篇关于您如何有条件地在Dojo数据网格中创建一个单元格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆