gpt4 book ai didi

jquery - 根据word替换DataTables列中的内容

转载 作者:行者123 更新时间:2023-11-28 09:14:03 25 4
gpt4 key购买 nike

如何根据单元格中的单词替换 DataTables 中列中单元格的值。例如,如果单词是“Active”,则该单词将显示为绿色。如果单词是“Inactive”,它将显示为红色。目前我只能突出显示同一列中的所有单词,但不能根据单词甚至首字母定位列。

数据表代码:

$('#dataTables-example').dataTable( {
"ajax": 'publishers.txt',
"createdRow": function ( row, data, index ) {
if ( data[3].replace(/[\A,]/, '')) {
$('td', row).eq(3).addClass('highlight');
}
}
});

CSS:

td.highlight {
font-weight: bold;
color: blue;
}

最佳答案

在 Datatables 引用文档中找到解决方案:

"columnDefs": [ {
"targets": 3,
"createdCell": function (td, cellData, rowData, row, col) {
if ( cellData == "Active" ) {
$(td).css('color', 'green')
}
if ( cellData == "Inactive") {
$(td).css('color', 'red')
}
}
} ]

关于jquery - 根据word替换DataTables列中的内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26369641/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com