Columns mapping with th data

Columns mapping with th data

OpsseOpsse Posts: 3Questions: 1Answers: 0

Hi,

I fill the table with $('#example').rows.add(data);
It is possible to do something like that :

<table id="example">
  <thead>
    <th data-columns-data="fieldA">Field A</th>
    <th data-columns-data="fieldB">Field B</th>
    <th data-columns-data="fieldC">Field C</th>
...

instead of :

$('#example').dataTable( {
  "columns": [
    { "data": "fieldA" },
    { "data": "fieldB" },
    { "data": "fieldC" },
  ]
} );

I feel like the first one is clearer but I didn't find anything like that in the documentation.

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,205Questions: 1Answers: 10,415 Site admin
    Answer ✓

    Yes, you can provide initialisation options in HTML5 data-* attributes. The documentation for that is available here.

    Allan

  • OpsseOpsse Posts: 3Questions: 1Answers: 0

    I see, my mistake was to keep columns, the good sytaxe is <th data-data="fieldA">Field A</th>. Which is a bit wierd by it works.

  • allanallan Posts: 63,205Questions: 1Answers: 10,415 Site admin

    Heh - yeah I can see that data-data is a bit odd! I think it makes sense to drop the columns part though since we can infer that from the HTML structure.

    Allan

  • OpsseOpsse Posts: 3Questions: 1Answers: 0

    Yes it makes sense, thank you for your answer.

This discussion has been closed.