Sorting date column not sorting in correct order

Sorting date column not sorting in correct order

GlitchEclipseGlitchEclipse Posts: 14Questions: 2Answers: 0

I have a table that is pulling its data from a sql server table. This loads in the data fine, but when I click on the date columns they are not sorting the dates in the correct order.

I am not too sure what I need to do to correct. If I sort in management studio the order is correct. Thought that would just work fine, but I guess not. Here is what I have:

var table;

        $(document).ready(function () {
            table = $('#WellTestTable').DataTable({
                "scrollX": true,
                "order": [[2, 'desc']]
            });
        });

What am I missing to get the data to sort correctly? I don't have time in there yet, but it would need to sort by time as well.

Here is the date data from in the table on sql.

Thanks.

Answers

  • kthorngrenkthorngren Posts: 20,144Questions: 26Answers: 4,736

    This blog should help:
    https://datatables.net/blog/2014-12-18

    Kevin

  • GlitchEclipseGlitchEclipse Posts: 14Questions: 2Answers: 0
    edited July 2018

    I installed the package. install-package moment.js and I have it in my bundleConfig.

    I included the below format.

        var table;
    
            $.fn.table.moment('YYYY-MM-DD hh:mm:ss');
    
            $(document).ready(function () {
                table = $('#WellTestTable').DataTable({
                    "scrollX": true,
                    "order": [[2, 'desc']]
                });
            });
    

    and I am still getting this return.

    What did I do wrong?

    I also tried

    $.fn.dataTable.moment( 'M/D/YYYY hh:mm:ss A');
    
  • GlitchEclipseGlitchEclipse Posts: 14Questions: 2Answers: 0

    Figured it out. My fn.dataTable.moment was not within the document.ready function. I have it working with

    $.fn.dataTable.moment( 'M/D/YYYY hh:mm:ss A');
    
This discussion has been closed.