How to sort date time columns

How to sort date time columns

kalpesh.vyas26kalpesh.vyas26 Posts: 10Questions: 2Answers: 0

I am trying to get sorting column in datetime by following below link but it is not working for me.
https://datatables.net/plug-ins/sorting/datetime-moment

Used below code
var ticketTable;
j$ = jQuery.noConflict();
j$.fn.dataTable.moment( 'HH:mm MMM D, YY' );
ticketTable = j$('[id$="ticketTable"]').DataTable({
columnDefs: [{ type: 'natural', targets: 0 }]//for natural sorting for column 1
});

Getting error below:
Uncaught TypeError: j$.fn.dataTable.moment is not a function

Answers

  • kthorngrenkthorngren Posts: 21,591Questions: 26Answers: 5,006

    Did you include both JS files needed as described in the referenced blog post?
    https://datatables.net/blog/2014-12-18

    Kevin

  • kalpesh.vyas26kalpesh.vyas26 Posts: 10Questions: 2Answers: 0

    Yes. I have included them both //cdnjs.cloudflare.com/ajax/libs/moment.js/2.8.4/moment.min.js
    and //cdn.datatables.net/plug-ins/1.10.15/sorting/datetime-moment.js

  • kthorngrenkthorngren Posts: 21,591Questions: 26Answers: 5,006

    I put your init code into an example that works (didn't load the natural plugin):
    http://live.datatables.net/dowoyose/1/edit

    Maybe there is a conflict or load order issue with your include files. Can you post a link showing the issue?

    Kevin

  • kalpesh.vyas26kalpesh.vyas26 Posts: 10Questions: 2Answers: 0

    Okay thanks I will check by removing some other plugin

  • kalpesh.vyas26kalpesh.vyas26 Posts: 10Questions: 2Answers: 0

    Hi @kthorngren ,
    Yes you are right, it is getting conflict from natural.js
    What can be done to have both working together?

This discussion has been closed.