Basic time sorting
Basic time sorting
joesapo
Posts: 2Questions: 1Answers: 0
For the life of me I can't get time sorting working on my table. I've tried setting up datetime-moment and that doesn't work, I've tried manually setting the column sort type with http://datatables.net/plug-ins/sorting/ and that doesn't work either.
HTML
<td><div class="starttime">12:15 AM</div></td>
JS
$(document).ready(function() {
$.fn.dataTable.moment('h:mm A');
// instantiate datatable
$('#document_list_table').DataTable({
"paging": false,
"columnDefs": [
{ "type": "datetime-moment", targets: 5 }
]
});
});
This discussion has been closed.
Answers
I ended up using data-order from https://datatables.net/examples/advanced_init/html5-data-attributes.html. I'm still bummed I was unable to use datatables-moment to do automatic date/time sort mask detection, but at least things are working now.
The Moment plug-ins should be able to do this I think. I've just tried a quick little example and it appears to work okay: http://live.datatables.net/boreviye/1/edit .
Thinking about it, what might be the issue is the
div
element. Do you need that? If so, you would need to modify the Moment sorting plug-in for DataTables to strip the HTML I think.Allan
@joesapo, would you be able to share some of your code of how you used data-order to sort your time? Thanks.