jquery - 基于单元格值的 jQuery 数据表行颜色更改
问题描述
我想根据单元格值更改行背景颜色和文本颜色。我
的 Html 代码如下
<button id="refersh">Refresh</button>
<button id="AddRow">Add New Row</button>
<table id="stdTable" class="table table-bordered table-striped" width="100%">
<thead>
<tr>
<th>Id</th>
<th>Name</th>
<th>Age</th>
<th>Date of birth</th>
<th>Edit/View</th>
</tr>
</thead>
</table>
数据表版本为 v 1.10.12。数据加载方式为ajax。
解决方案
使用这个 createdRow 函数:
"createdRow": function( row, data, dataIndex ) {
if ( data["LAYOUT"] == "N" ) {
$( row ).css( "background-color", "Orange" );
$( row ).addClass( "highlight" );
}
}
推荐阅读
- css - 按钮在 safari 上多次显示
- varnish - Ubuntu 上的 Varnish 策略引擎
- spring-boot - 数据流服务器上的 Spring 批处理 (JSR-352) 应用示例
- r - R data.table 值取决于前一行
- angular - Angular - 生命周期:要完全加载的子组件
- ignite - 如何在 webapps 之间共享一个 Ignite 实例?
- vue.js - 如何在 vuetify 中删除列表项的填充
- regex - 在大写字母之前插入空格但不在缩写之间插入空格的pythonic方法
- redux - Redux persistedState 对象没有设置默认的 redux 状态
- php - 在 PHP 中将 VueJS 输出从 String 转换为 Int