Can't get currency sorting to work
Can't get currency sorting to work
I've got a pretty standard USD currency column but sorting doesn't seem to detect that it's a currency. For my particular set of data, when I sort, I get the following:
$6.00
$500.00
$500.00
$50.00
$5.00
$5.00
$5.00
$4,072.66
$10,634,884.55
Do I need to enable something specific for type auto-detection?
$6.00
$500.00
$500.00
$50.00
$5.00
$5.00
$5.00
$4,072.66
$10,634,884.55
Do I need to enable something specific for type auto-detection?
This discussion has been closed.
Replies
Did you include the currency type-detection and sorting plug-ins?
Type detection: http://datatables.net/plug-ins/type-detection#currency
Sorting: http://datatables.net/plug-ins/sorting#currency
Example: http://datatables.net/examples/api/sorting_plugin.html
Regards,
Allan
If you've included the two plug-ins as shown in the example, then it should all just automatically work. The column type will be detected as 'currency' and the column will sort as required. Make sure that the plug-ins are added after the DataTables JS file, but before initialising the table.
Allan
Is there anything I can do to debug this to see which functions it's calling to sort this? Perhaps it's detecting it wrong?
If you run "console.dir( oTable.fnSettings().aoColums );" in Firebug and look for the array element which contains the information for your currency column, that will tell you the type - and if it's been detected correctly or not. Failing that, then there might be a bug in the sorting functions themselves. Do you have a link you could provide - it might made debugging easier. If you have one but don't want to make it public, you can send it to me direct at http://datatables.net/contact .
Regards,
Allan
Unfortunately this particular project is an internal company, so I am unable to let you take a look. I realize this makes it much more difficuilt for you :(
Is there any way to debug the sort-detect function?
Thanks!
I'm using v1.5.1
Assuming you have the currency type detection plug-in installed correctly, it should add currency type detection to the aTypes array. The formatting for the currency detection is fairly strict, you can't have any white space in the table cell (you can modify the plug-ins to add support for this if you need), and only there characters -0123456789 and . or , are allowed, with a $ or £ at the start. Does that match your current formatting?
Regards,
Allan
Regardless, it works now so I'm going to go sit in the corner and be ashamed of myself for not figuring it out on my own.
Thanks!
They could probably do with a link from one to the other on the plug-in pages other than just being mentioned in the text. I'll add it to the to-do list :-)
Good to hear you got it sorted.
Allan