最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin5浏览0评论

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: .html.

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

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/examples/server_side/ids.html.

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

Share Improve this question edited Aug 14, 2015 at 18:24 Gyrocode. 58.9k16 gold badges156 silver badges191 bronze badges asked Aug 12, 2015 at 21:55 jbyrdjbyrd 5,6159 gold badges56 silver badges93 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 3

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 ] }
  ]
} );
发布评论

评论列表(0)

  1. 暂无评论