sType sorting with JSON
sType sorting with JSON
First, excellent tool. DataTables is a dream come true, for the most part...
I'm guessing someone has a fix for this, as it seems like a common request, but I can't get the plug in to hold. I want my data to sort as integers, it is currently sorting as a string.
I have a (valid) json file pulling in my data, but it is full of % and $ signs. I know I can change sType to "numeric" to try to read the numbers, but the data no longer sorts when I do that. Am I missing something?
Here is my code:
[code]
ar oTable = $('#example').dataTable( {
"bProcessing": true,
"sAjaxSource": "alcohol.js",
"aoColumns": [
{
"mDataProp": null,
"sClass": "control center",
"sDefaultContent": ''
},
{ "mDataProp": "Type" },
{ "mDataProp": "Sales in 2011", "sType": "numeric" },
{ "mDataProp": "Share of all sales", "sType": "numeric" },
{ "mDataProp": "Bottles sold in 2011", "sType": "numeric" },
{ "mDataProp": "Share of all bottles", "sType": "numeric" },
]
} );
[/code]
Here is my json file: http://media.hamptonroads.com/media/content/pilotonline/2011/12/alcohol.js
I'm guessing someone has a fix for this, as it seems like a common request, but I can't get the plug in to hold. I want my data to sort as integers, it is currently sorting as a string.
I have a (valid) json file pulling in my data, but it is full of % and $ signs. I know I can change sType to "numeric" to try to read the numbers, but the data no longer sorts when I do that. Am I missing something?
Here is my code:
[code]
ar oTable = $('#example').dataTable( {
"bProcessing": true,
"sAjaxSource": "alcohol.js",
"aoColumns": [
{
"mDataProp": null,
"sClass": "control center",
"sDefaultContent": ''
},
{ "mDataProp": "Type" },
{ "mDataProp": "Sales in 2011", "sType": "numeric" },
{ "mDataProp": "Share of all sales", "sType": "numeric" },
{ "mDataProp": "Bottles sold in 2011", "sType": "numeric" },
{ "mDataProp": "Share of all bottles", "sType": "numeric" },
]
} );
[/code]
Here is my json file: http://media.hamptonroads.com/media/content/pilotonline/2011/12/alcohol.js
This discussion has been closed.
Replies
you can write your own sort routines, and it might be as simple as removing those characters and parsing the value as a float or int.
see http://www.datatables.net/plug-ins/sorting in particular the "Percentage" plug in code