【问题标题】:Datatable - assign css present inside a table cell to other table cellsDatatable - 将表格单元格内的 css 分配给其他表格单元格
【发布时间】:2012-12-13 11:11:37
【问题描述】:

我正在使用datatables plugin。 我的表包含一个列名 css,其中包含该行中列的 css。
例如,数据库中的表如下,

 Name   Priority   Percent    CSS 
--------------------------------------------------------- 
 abc    high       50         .priority{color:red}    .percent {color:yellow}
 xyz    low        70         .priority{color:green}  .percent {color:green}
 pqr    medium     10         .priority{color:yellow} .percent {color:red}

现在在显示数据表时,我不想包含 css 列,但我想在特定单元格上应用 css。 我正在尝试实现以下目标,

$('#example').dataTable({              
    "fnRowCallback": function (nRow, aData, iDisplayIndex, iDisplayIndexFull) {  
         $(row).children().each(function(index, td){
             // perform operation here
         });
    return nRow;
    }
 

我不明白如何使用来自同一行的 <td> 的 css 为特定的 <td> 添加 css。

请帮忙

【问题讨论】:

    标签: jquery css datatable


    【解决方案1】:

    它未经测试,但可能对您有用。在文档就绪处理程序中使用它。

    $("td:contains('high')").css({"color":"red"});
    $("td:contains('high')").next('td').css({"color":"yellow"});
    

    同样适用于其他 tds:

    $("td:contains('low')").css({"color":"green"});
    $("td:contains('low')").next('td').css({"color":"green"});
    

    $("td:contains('medium')").css({"color":"yellow"});
    $("td:contains('medium')").next('td').css({"color":"red"});
    

    如果这可以解决或有帮助,请尝试此操作。

    【讨论】:

    • 感谢杰。但 css 可以是任何东西,我的意思是它可以是 priority{color:red;background-color:#eee;text-decoration:underline;} .percent {color:yellow;font-size:12px;font-weight:bold}。在我的问题中,这只是一个例子。 css 取决于创建行的人,因为有很多人可以访问同一个表。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-09-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-14
    • 2012-04-05
    相关资源
    最近更新 更多