How do I sort date columns?
How do I sort date columns?
totallyplandom
Posts: 27Questions: 1Answers: 1
Hi All,
I've looked around and seen some amazingly complex solutions to the problem I have and am wondering what the most straightforward mechanism is. Basically, I need to have my date columns sort by something other than date as they are displayed in "m-d-Y" format and are sorting based on the month. I need to have another property (perhaps a "data" attribute with a totalseconds attribute) that the table uses to sort those particular columns. Is there anything remotely straightforward to do this?
If not, I've seen various "plugins", but I'm honestly unsure as to how to actually make use of these things. Any assistance would be most appreciated.
Best!
I've looked around and seen some amazingly complex solutions to the problem I have and am wondering what the most straightforward mechanism is. Basically, I need to have my date columns sort by something other than date as they are displayed in "m-d-Y" format and are sorting based on the month. I need to have another property (perhaps a "data" attribute with a totalseconds attribute) that the table uses to sort those particular columns. Is there anything remotely straightforward to do this?
If not, I've seen various "plugins", but I'm honestly unsure as to how to actually make use of these things. Any assistance would be most appreciated.
Best!
This discussion has been closed.
Replies
in your .dataTable() intialization, set "sType" for the column (in aoColumns or aoColumnDefs) you want to use that routine
here's an example page: http://www.datatables.net/release-datatables/examples/plug-ins/sorting_sType.html
[code]TypeError: 'undefined' is not a function (evaluating 'k[(qa?qa:"string")+"-"+h[c][1]](H(a,O,F,"sort"),H(a,B,F,"sort"))')[/code]
The table has six columns, and my initialization code looks like so:
[code]
$('#member_balance').dataTable({
"aoColumns":[
null,
null,
null,
null,
{"sType": 'currency-asc'},
null
],
"sScrollY": "400",
"bScrollCollapse": true,
"bPaginate": false,
"bJQueryUI": true,
"aaSorting": [[1,"asc"]]
});
[/code]
Any thoughts?
[code]
$('#member_balance').dataTable({
"aoColumns":[
null,
null,
null,
null,
{"sType": 'currency'},
null
],
"sScrollY": "400",
"bScrollCollapse": true,
"bPaginate": false,
"bJQueryUI": true,
"aaSorting": [[1,"asc"]]
});
[/code]
Thanks again!