HTML5 Data attributes on initialisation
HTML5 Data attributes on initialisation
Busteren
Posts: 52Questions: 17Answers: 4
So I am trying to add data-sort attribute on initialisation of the datatable. Mainly for use of sorting dates or numbers.
datatables attribute
However after googling and searching I couldn't find how to do this in the .DataTable() initialisation.
Anyone have suggestion or can link to another post which shows it?
Something like having it in the columns option if this is doable:
.DataTable({columns: [{ data: 'date'}]})
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
Just to add an example of how I use the datatable:
live.datatables.net/tolomeji/7/edit
Note that I do use a custom render, which I haven't added here.
The HTML5 data-sort and data-search attributes are intended for DOM sourced tables. I'm not sure they will work with Javascript or Ajax loaded data as they would be added during initialization. I don't believe they would be applied by Datatables for sorting or searching.
The Orthogonal Data docs will describe how the HTML5 attributes are used. I think you would be better off using the
sort
type described in the same doc. You would use code similar to what is shown in the Computed Values section but for thesort
type to build your sorting data.If you are specifically trying to sort dates you may be interested in the Ultimate Date/Time sorting doc.
Kevin
This here fixed it Turned out I didn't need to add the data-order tag after all
@kthorngren cheers! I might have to modify what I already have, so that site is very handy. Thank you for the explanation as well