Sorting dates (mm dd, yyyy hh:mi am) what am I doing wrong?

Sorting dates (mm dd, yyyy hh:mi am) what am I doing wrong?

charlesreadcharlesread Posts: 3Questions: 0Answers: 0
edited June 2012 in General
Hi everybody,

I love DT, what a great product! I have a table with two dates, and I can't seem to get them to sort as dates, they will sort as strings without an sType specification, but wont sort at all with one. Here is my code:



oTable = $('#pacr').dataTable({
"bJQueryUI": true,
"sPaginationType": "full_numbers",
"bAutoWidth" : true,
"aaSorting" : [[2,'desc']],
"aoColumns": [
null,
null,
{"sType":"date"},
{"sType":"date"},
null,
{ "iDataSort": 6 },
{ "bVisible": false }
]
});;
oTable.fnAdjustColumnSizing();






My Purchase Authorizations




ID
Status
Date Created
Date Needed
For
Total
dTotal




168Submitted
Jun 5, 2012 11:15 PMJun 27, 2012

$10,000.00
10000.00


167Submitted
Jun 5, 2012 5:56 PMAug 23, 2012

$4,000.00
4000.00







When I put the sType specifications on columns 3 and 4 the columns are no longer sortable... can anybody see what I am doing wrong?

Thanks in advance!!!

CR

Replies

  • allanallan Posts: 63,542Questions: 1Answers: 10,476 Site admin
    Your date's won't be parsed by Javascript's built in Date.parse() method. If your date format doesn't work with that, then you need a date sorting plug-in: http://datatables.net/plug-ins/sorting#date_eu .

    DataTables will automatically detect columns with Date.parse() suitable columns - so just setting sType: "date" isn't enough - a plug-in is required.

    Allan
  • charlesreadcharlesread Posts: 3Questions: 0Answers: 0
    edited June 2012
    Thank you very much for the response, but perhaps I am misunderstanding. The JS commands below return milliseconds:

    alert(Date.parse('June 5, 2012 5:56 PM'));
    alert(Date.parse('June 05, 2012'));
    alert(Date.parse('Jun 5, 2012'));
    alert(Date.parse('Jun 05, 2012 5:56 PM'));

    Am I misinterpreting your response?

    Thanks again!
  • allanallan Posts: 63,542Questions: 1Answers: 10,476 Site admin
    Fair enough :-). In that case there is something else in the column that is causing DataTables to thinking that it is string based. Can you run your table through the debugger please?

    Allan
  • charlesreadcharlesread Posts: 3Questions: 0Answers: 0
    Thanks again!

    The debug code is: eforup. I think I see the issue, it is that I have the content in the TD (that is a date) wrapped in an anchor so that it will link to another page in my application (in this case a page where a purchase authorization can be edited) - so it seems like I need to strip the anchor out before sorting - any idea how I can do this?

    Thanks for all of your help!

    :)
This discussion has been closed.