How to use HTML5 data-attribute with a Javascript datasource
How to use HTML5 data-attribute with a Javascript datasource
Hi everyone,
I have a complex datatables with a javascript datasource and I want to sort some columns with a speicific logic.
I already to try to implement a custom sorting plug-in (everything works) but the processing is very slow and all reasearch, ... are impacted and became very slow.
One solution is to use the HTML5 data-attribute, but it seem dosen't works with a JS DataSource (or I don't know how).
Please find a very very simple example -- > http://live.datatables.net/nogikiti/4/edit?html,js,output
As you can see if I add the "data-order" attribute in the createdRow function the sort processing does not work as well.
Could you please tell me if it's possible to use HTML5 data-attribute with a JS or Ajax datasource ?
And how to achieve this ?
Many thank's
This question has an accepted answers - jump to answer
Answers
The HTML5 data attributes work with DOM sourced tables. Datatables wont use them if they are added dynamically from Javascript. For Javascript/Ajax loaded data you would use
columns.render
, as described in this doc, to set the data for thesort
operation. See the updated example:http://live.datatables.net/nogikiti/5/edit
Kevin
Hi @kthorngren, many thank's for your help you solved my problem