Apply unique class for multiple columns

2020-05-06 12:45发布

问题:

How to apply different class for each column in Jquery data tables. I have tried using some properties in column definitions

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

回答1:

It worked using columsDefs property for each columns

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


回答2:

You can apply the multiple classes to single column in this e.g i have add class datatable header and 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]}
                        ].......