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?
charlesread
Posts: 3Questions: 0Answers: 0
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
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
This discussion has been closed.
Replies
DataTables will automatically detect columns with Date.parse() suitable columns - so just setting sType: "date" isn't enough - a plug-in is required.
Allan
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!
Allan
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!
:)