【问题标题】:Apply unique class for multiple columns为多个列应用唯一类
【发布时间】:2016-12-18 15:33:46
【问题描述】:

如何为 Jquery 数据表中的每一列应用不同的类。 我尝试在列定义中使用一些属性

$('#asset-table').DataTable({..... 
"columns": [
                                {
                                    "name": "claimNum",
                                    "title": "Claim#",
                                    "width": "11%",
                                    "type": "string",
                                    "data": "claimNum",
                                    "visible": assetDisplayColumns.indexOf("claimNum") != -1
                                },
                                {
                                    "name": "salvor",
                                    "title": "Salvage Provider",
                                    "width": "5%",
                                    "type": "string",
                                    "data": "salvor",
                                    "visible": assetDisplayColumns.indexOf("salvor") != -1
                                },.....

【问题讨论】:

    标签: jquery css datatables


    【解决方案1】:

    它对每列使用 columsDefs 属性

    var assetTable = $('#asset-table').DataTable({
                            "columnDefs": [{ className: "makeItalic", "targets": [ 1,2,3 ] }, 
    { className: "makeBold", "targets": [ 4,5 ] }],....
    

    【讨论】:

      【解决方案2】:

      您可以将多个类应用于此列中的单个列,例如我添加了类数据表标题和数据正文。

         $('#asset-table').DataTable({
      
              "columnDefs": [
                                  {className: "dt-body-center dt-head-center", width: '10%', "targets": [0]},
                                  {className: "dt-body-left dt-head-center", width: '40%', "targets": [1]},
                                  {className: "dt-body-left dt-head-center", width: '30%', "targets": [2]},
                                  {className: "dt-body-center dt-head-center", width: '20%', "targets": [3]}
                              ].......
      

      【讨论】:

        猜你喜欢
        • 2018-04-16
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-06-01
        • 1970-01-01
        • 2011-11-26
        • 2014-11-08
        相关资源
        最近更新 更多