首页 > 解决方案 > 基于单元格值的 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。

标签: jquerydatatables

解决方案


使用这个 createdRow 函数:

"createdRow": function( row, data, dataIndex ) {
                if ( data["LAYOUT"] == "N" ) {
                    $( row ).css( "background-color", "Orange" );
                    $( row ).addClass( "highlight" );
                }
            }

推荐阅读