Soft columns by date

Soft columns by date

btgomezbtgomez Posts: 14Questions: 6Answers: 0

Hi, got problem when sorting columns. It seems that the column are not sorting accordingly. I followed the documentation here: https://datatables.net/plug-ins/sorting/

Below is my code:
Btw, I'm using dd/MM/yy

    var dtallJob = $('#allJob').DataTable({
        "aLengthMenu": [[20, -1], [20, "All"]],
        iDisplayLength: 20,
        sScrollY: "50vh",
        bScrollInfinite: true, //this property disables pagination 
        "scrollCollapse": true,
        "pagingType": "simple_numbers",
        "lengthChange": false,
        "bInfo": false,
        "dom": 'lrtip',
        columnDefs: [
            { type: 'date-eu', targets: 1 },
            { type: 'date-eu', targets: 2 },
            { type: 'date-eu', targets: 3 },
            { type: 'date-eu', targets: 4 }
        ]
    });

This question has accepted answers - jump to:

Answers

  • colincolin Posts: 15,142Questions: 1Answers: 2,586

    Hi @btgomez ,

    That date-eu plugin now is deprecated, see a comment in that post - it says to use datetime now.

    Those links should help. If not, we're happy to take a look, but as per the forum rules, if you could link to a running test case showing the issue we can offer some help. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.

    Cheers,

    Colin

  • btgomezbtgomez Posts: 14Questions: 6Answers: 0

    Hello @colin, here's the live example for the sort date problem:

    http://live.datatables.net/coqapici/1/edit

    Our date format is: dd/MM/yyyy

    As you can see in the first column or in other date column, it doesn't sort correctly.

    Regards,

  • colincolin Posts: 15,142Questions: 1Answers: 2,586
    edited February 2019 Answer ✓

    Hi @btgomez ,

    You can use the datetime-moment to change the global default for dates - see this thread. This also deals with blank cells.

    The datetime plugin that I mentioned before, would also work, provided all the dates are valid, see here.

    Cheers,

    Colin

  • btgomezbtgomez Posts: 14Questions: 6Answers: 0

    Thanks @colin. Is there any option for the blank cells should always be in the last?

  • colincolin Posts: 15,142Questions: 1Answers: 2,586
    Answer ✓

    Hi @btgomez ,

    Yep, you can use the absolute plugin for that, see here.

    Cheers,

    Colin

  • btgomezbtgomez Posts: 14Questions: 6Answers: 0

    Again, thanks @colin, the absolute solved my issue on the NULL. However, on the datetime-moment got an error. I already posted it to the github here's the reference FYI.

    I used like this:

    <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.19/css/jquery.dataTables.css">
    <script type="text/javascript" charset="utf8" src="https://cdn.datatables.net/1.10.19/js/jquery.dataTables.js"></script>
    <script type="text/javascript" charset="utf8" src="https://cdn.datatables.net/plug-ins/1.10.19/sorting/datetime-moment.js"></script>
    <script type="text/javascript" charset="utf8" src="https://cdn.datatables.net/plug-ins/1.10.19/sorting/absolute.js"></script>
    
    

    Uncaught ReferenceError: moment is not defined

    datetime-moment.js:27 Uncaught ReferenceError: moment is not defined
        at datetime-moment.js:27
        at datetime-moment.js:29
    (anonymous) @ datetime-moment.js:27
    (anonymous) @ datetime-moment.js:29
    

    I didn't yet put the code on my source code based from the example: https://datatables.net/plug-ins/sorting/datetime-moment

  • btgomezbtgomez Posts: 14Questions: 6Answers: 0

    Okay, I think I'm missing this:

    <script type="text/javascript" charset="utf8" src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.8.4/moment.min.js"></script>
    
This discussion has been closed.