如何根据单元格值为行提供单独的颜色 [英] How do I give separate color to rows depending on cell value

查看:106
本文介绍了如何根据单元格值为行提供单独的颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

I am using datatables.net. 

Rows in tables are arranged with EmployeeGroupNumber. 

I would like to have even EmployeeGroupNumber rows with one color and odd with another. so that it could be clean to separate the details in the table





我尝试过的事情:



目前我正在使用bootstrap



What I have tried:

currently I am using bootstrap

table-striped

类,它使用我不想要的单独颜色的备用行。

class which makes alternate rows with separate color which I do not want.

推荐答案

你需要为每一行调用 createdRow 事件提供实现,你可以在那里在一些业务逻辑上更改行的样式如下:



You will need to provide the implementation for createdRow event that would be called for each row and there you can change style of the row on some business logic like following:

"createdRow": function (row, data, index) {
                            if (data["Building"] == null)
                                return;
                            switch (data["Building"].toLowerCase()) {
                                case 'west':


' td: not(:last-child)',row).css({
' background' ' red'
' color'' white'
});
break ;
}
}
('td:not(:last-child)', row).css({ 'background': 'red', 'color': 'white' }); break; } }





我在这里做的是将行背景颜色设置为读取和文本 - 所有行单元格的颜色为白色。



希望它有所帮助。



What i was doing here is set the row background-color to read and text-color for all the row cells white.

Hope it helps.


这篇关于如何根据单元格值为行提供单独的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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