how to sort by a column that has this format ?

how to sort by a column that has this format ?

mlotfimlotfi Posts: 60Questions: 5Answers: 0

Hi,

I would like to display the table sorted by a column called createdAt that has this for mat :
2015-03-09T14:46:57.678-04:00

thanks, your help is appreciated.

Replies

  • tangerinetangerine Posts: 3,350Questions: 37Answers: 394
  • mlotfimlotfi Posts: 60Questions: 5Answers: 0

    I am not looking to format 2015-03-09T14:46:57.678-04:00 , I am looking for a way when the table displays it will be sorted by that column createdAT.

  • mlotfimlotfi Posts: 60Questions: 5Answers: 0

    I added :

    {
    "aaSorting": [4, "desc"]
    }

    the sorting works fine, but the datatable is destroyed :

    and I got this error :

    DataTables warning (table id = 'inviteeListTable'): aTargets must be an array of targets, not a undefined
    Uncaught TypeError: Cannot read property 'length' of undefined

  • allanallan Posts: 61,744Questions: 1Answers: 10,111 Site admin
    edited May 2015

    Can you link to a test page showing the error please. Also, make sure you are using the latest version of DataTables. That error suggests you might be using a legacy version.

    Allan

  • mlotfimlotfi Posts: 60Questions: 5Answers: 0
    edited June 2015

    Here is a jsfiddle :

    http://jsfiddle.net/mlotfi/qfmhmcw0/

    the date format now is : 07/06/2015 04:37:32 PM EDT

  • allanallan Posts: 61,744Questions: 1Answers: 10,111 Site admin

    You are using aoColumnDefs without a targets option. See columnDefs.targets.

    Allan

  • mlotfimlotfi Posts: 60Questions: 5Answers: 0

    even with the targets it does not work :
    http://jsfiddle.net/qfmhmcw0/19/

  • allanallan Posts: 61,744Questions: 1Answers: 10,111 Site admin

    I'm not sure why you put aTargets in its own object, the documentation I linked to doesn't show that. Put it in the object that you need to tell what column to apply to: http://jsfiddle.net/qfmhmcw0/20/ .

    Allan

  • mlotfimlotfi Posts: 60Questions: 5Answers: 0

    Hi Allan,
    if you take a look to the result of your jsfiddle, the column that has dates is not sorted in desc or asc,

  • allanallan Posts: 61,744Questions: 1Answers: 10,111 Site admin

    No - but that is a different question :-). Your date string is not in a format that is supported by the Date.parse() Javascript method (which DataTables uses for date / time sorting).

    See this plug-in for how you can sort any data time format.

    Allan

This discussion has been closed.