className doesn't seem to work

className doesn't seem to work

abarnesabarnes Posts: 16Questions: 5Answers: 0

I have been trying using the className option with no success. Here is what I have:
"columnDefs": [
{"className": "semi-bold", "targets": [2]}
],

Any ideas? It is a valid css class and I've tried different ones such as dt-middle etc. No change

Answers

  • abarnesabarnes Posts: 16Questions: 5Answers: 0

    This is my var. None of the classes are applied:

    var table = $('#accounts').DataTable( {
    "info": false,
    "paging": false,
    "filter": false,
    "responsive": true,
    "serverSide": true,
    "ajax": {
    url: deviceTBL+'&request=accounts',
    type: 'POST'
    },
    "columnDefs": [
    {"orderable": false, "targets": "_all"},
    {"className": "clickable", "targets": "_all"},
    {"className": "dt-middle", "targets": "_all"},
    {"className": "text-center", "targets": [2]}
    ],
    "columns": [
    { data: "accountUser"},
    { data: "accountPass"},
    { data: "accountButton"},
    ]
    } );

  • kthorngrenkthorngren Posts: 21,242Questions: 26Answers: 4,929
    edited January 2019

    You need to combine the classes. Also it seems order is important.

    If they are in this order then the text-center class is not applied to column 2.

    "columnDefs": [
    {"orderable": false, "targets": "_all"},
    {"className": "clickable dt-middle", "targets": "_all"},
    {"className": "clickable dt-middle text-center", "targets": [2]},
    ],
    

    In this order the text-center plus the others are applied to column 2.

    "columnDefs": [
    {"orderable": false, "targets": "_all"},
    {"className": "clickable dt-middle text-center", "targets": [2]},
    {"className": "clickable dt-middle", "targets": "_all"},
    ],
    

    See this example:
    http://live.datatables.net/xulepeye/1/edit

    You can inspect each td to verify the classes are applied.

    Kevin

This discussion has been closed.