admin管理员组

文章数量:1327660

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 ] }
  ]
} );

本文标签: javascriptHow to add a class to the lttdgt in serverside processing modeStack Overflow