Using HTML5 data attributes loaded programmatically

Using HTML5 data attributes loaded programmatically

voodoovoodoo Posts: 4Questions: 1Answers: 0

I have a DataTable that loads from a javascript source. I'd like to add some data-filter and data-order attributes. From my experimentation, DataTables doesn't recognize these if they're added as part of the DataTables draw.

Here's a fiddle using a javascript source:
http://jsfiddle.net/kthncoxv/2/

Here's the same thing with an HTML source. Notice the search attributes works fine when it's in the first row of the actual table, but doesn't work when I try to add it during the DataTables load (using "createdCell").
http://jsfiddle.net/p4o19fex/

Does the table need to be reloaded or am I missing something? This is with 1.10.

Thanks in advance for any help!

Answers

  • allanallan Posts: 61,822Questions: 1Answers: 10,127 Site admin

    That is correct - if you are using a Javascript or Ajax data source, use the columns.render or columns.data options to make use of orthogonal data. There is no option for DataTables to use HTML5 attributes that are added as part of the callback structure (it probably can technically be done, but I suspect it would be messy).

    Regards,
    Allan

  • voodoovoodoo Posts: 4Questions: 1Answers: 0

    Thanks Allan. I see what you're saying. I was able to use columns.render to add directly to the cell data. However, I'm still not sure if it's possible to add something like an attribute to the cell <td> itself.

    See this updated fiddle for my experimentation adding an attribute using render:
    http://jsfiddle.net/gf23mbob/

    Ideally, I'd like to add data-search and data-order. And, unfortunately, I don't have easy access to update the javascript datasource.

    Thanks!

  • allanallan Posts: 61,822Questions: 1Answers: 10,127 Site admin

    It is possible to add the attributes using the createdCell option (which provides a method of manipulating the node) - but there is no way to instruct an Ajax sourced DataTable to use those attributes - you would need to use the other orthogonal data approaches of DataTables to do it.

    Allan

This discussion has been closed.