HTML表格单元格的条件格式 [英] conditional formatting of html table cells

查看:138
本文介绍了HTML表格单元格的条件格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



有了条件格式,我更感兴趣的是将不同的颜色作为单元格背景,具体取决于这个或其他列的值(数字)(在同一个表中)。

类似于我们在excel中有的条件格式化 - >色阶 - >红色黄绿色。我想在一个通过JSP动态生成的表中实现它。



有没有JavaScript / jquery或JSP解决方案? b

解决方案

我已经做了类似于ZDYN和David的建议,但是采用了更为数学证明的方式。

在计算了我的动态值之后,我绕着计算我想用颜色代码的列的百分位数来计算百分位数。\\ b
$ b


(L / N )* 100

其中:L =>物品数量减去百分比值的计算结果

N =>物品总数

现在,根据我从上面的计算中得到的百分位数,在显示表格时分配适当的颜色以供使用。

使用这种方法,我可以根据需要灵活地使用不同粒度级别的不同颜色调色板。
例如,我可以使用Red作为百分位数,范围从0-5在另一种情况下是0-10。所有这些部分都可以灵活编码,因为所有上述步骤都在@后端完成。 (用Java)

Are there any out of the box solutions to have conditional formatting of HTML tables?

With conditional formatting I am more interested in having different colors as cell background depending on the value (numeric) of that or some other column (in the same table).

Something similar to what we have in excel Conditional Formating -> Color Scales -> Red Yellow Green. I want to implement that in a table that is being dynamically generated via JSP.

Are there any JavaScript/jquery or JSP solutions for this?

解决方案

I have done similar to similar to what ZDYN and David propose but in a more mathematically proven way.

After my dynamic values are calculated I go around calculating percentiles for the columns that I want to color code using

(L/N)*100
where: L=> Number of Items less the value for which percentile is being calculated
N => Total number of items

Now, depending on the percentile I get from the above calculations, appropriate colors are assigned for use when displaying the table.
With this approach I get the flexibility of using different color palettes at different granularity levels as the need be.
For example I can use Red for percentile ranging from 0-5 in one case and 0-10 in another. All these parts can be flexibly coded for as all of the above steps are done @ backend. (in Java)

这篇关于HTML表格单元格的条件格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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