Columns mapping with th data
Columns mapping with th data
Opsse
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
This discussion has been closed.
Answers
Yes, you can provide initialisation options in HTML5
data-*
attributes. The documentation for that is available here.Allan
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.Heh - yeah I can see that
data-data
is a bit odd! I think it makes sense to drop thecolumns
part though since we can infer that from the HTML structure.Allan
Yes it makes sense, thank you for your answer.