数据表 - 如何更改动态更改的单元格的背景和文本颜色? [英] Datatables - How do I change background and text color of a cell changed dynamically?

查看:19
本文介绍了数据表 - 如何更改动态更改的单元格的背景和文本颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用以下代码动态更新单元格并完美运行,唯一的问题是如何更改背景颜色和该单元格数据的文本.如果可能的话,还有一个如何更改整行的示例.提前致谢.

I use the following code to update a cell dynamically and works perfect, the only thing is how to change the color of the background and the text of that cell data. If it´s possible an example of how to change the entire row as well. Thanks in advance.

$(document).ready(function (){
    var table = $('#example').DataTable();

    table.rows().every( function ( rowIdx, tableLoop, rowLoop ) {
        var data = this.data();       
        console.log(data);

        data[0] = '* ' + data[0];

        this.data(data);
    });
});

推荐答案

SOLUTION

您可以使用访问cell节点cell().node() API 方法.

SOLUTION

You can access the cell node by using cell().node() API method.

$(document).ready(function (){
    var table = $('#example').DataTable();

    table.rows().every( function ( rowIdx, tableLoop, rowLoop ) {
        var cell = table.cell({ row: rowIdx, column: 0 }).node();
        $(cell).addClass('warning');
    });
});

演示

有关代码和演示,请参阅此 jsFiddle.

这篇关于数据表 - 如何更改动态更改的单元格的背景和文本颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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