为多列应用唯一类

时间:2016-08-11 18:51:49

标签: jquery css datatables

如何为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
                                },.....

2 个答案:

答案 0 :(得分:1)

它使用每列的columsDefs属性

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

答案 1 :(得分:0)

你可以将多个类应用于单列,例如我有add class datatable header和datable body。

   $('#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]}
                        ].......