简体   繁体   中英

Problems with sorting by date (dd.mm.YYYY) in Datatable using Moment.js and Ordering Plugin

I'm trying to make a Datatable sortable using the method described in this blogpost . As described in the blogpost, I included the two files moment.min.js and datetime-moment.js into my page.

My dates are in the following format: 16.03.2015

Before initialising the datatable, I am executing moment, like:

$.fn.dataTable.moment('dd.mm.YYYY');

$('.datatable').DataTable({
    "retrieve": true,
    "bLengthChange": false,
    "autoWidth": true,
    "responsive": true,
    "oLanguage": {
    ......
    ......

Unfortunately, the table still gets sorted alphabetically when clicking on the date column. I already tried to change "DataTable" in "dataTable" and vice versa - but it doesn't make any difference! Mabye be I have to specify which column is the column with the date? But I could not find out how to specify it. On the Chrome Developer Console there is no error message or log. It just sorts the date column alphabetically all the time. I could use a different plugin - but the other one is declared as deprecated. Does anybody know what could be the problem that causes this plugin not to sort the datatable? Thank you!

You're not using correct date format dd.mm.YYYY , see Moment.js documentation . dd is day of the week, and mm is minutes.

For dates in the format 16.03.2015 use the initialization code below:

$.fn.dataTable.moment('DD.MM.YYYY');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM