Basic time sorting

Basic time sorting

joesapojoesapo 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 }
                ]
            });
        });

Answers

  • joesapojoesapo Posts: 2Questions: 1Answers: 0

    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.

  • allanallan Posts: 63,687Questions: 1Answers: 10,500 Site admin

    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

  • JohnEzlabJohnEzlab Posts: 17Questions: 4Answers: 0

    @joesapo, would you be able to share some of your code of how you used data-order to sort your time? Thanks.

This discussion has been closed.