简体   繁体   中英

How to add a class to the <td> in server-side processing mode

When using server-side processing on a DataTable, there is a mechanism to add an ID, class, or data-* attribute to the table row ( <tr> ) by including the DT_RowId , DT_RowClass or DT_RowData properties, respectively, to the JSON data for each row: https://datatables.net/examples/server_side/ids.html .

Is there a similar (or any) mechanism for adding additional markup to the table columns ( <td> )?

You can add classes to columns like so, but not sure if this gets you where you want to go:

     var all_data = data;
     $("#example").DataTable({
            "data": all_data,
      "aoColumns": [{
        "data": 'cat_code',
        "className": "lang_body_2",//you can add whatever you want for a specific column here.
        "visible": false
    }, {
        "data": 'value',
        "searchable": false,
        "width": "20%",
        "className": "lang_body_2",
        "title": ""
    }]
  })

Other way, from off. sites docs . Assign class my_class to first column

$('#example').dataTable( {
  "columnDefs": [
    { className: "my_class", "targets": [ 0 ] }
  ]
} );

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM