Sorting by Numbers
Sorting by Numbers
islandtalker
Posts: 7Questions: 0Answers: 0
I see a lot of posts about problems sorting with numbers.
I have tried most of the solutions, but can't get none to work for me.
This is my table:
[code]
Title 1
Title 2
Title 3
Title 4
My value 1
My Value 2
My Value 3
$101.66
My value 1
My Value 2
My Value 3
$21,546.32
My value 1
My Value 2
My Value 3
$122.94
[/code]
As you can see, there is some html on it and the numbers have the dollar symbol, commas and period.
My last attempt was with naturalSort.js. I included the .js on my page and call the table as follows:
[code]
jQuery.fn.dataTableExt.oSort['natural-asc'] = function (a, b) {
return naturalSort(a, b);
};
jQuery.fn.dataTableExt.oSort['natural-desc'] = function (a, b) {
return naturalSort(a, b) * -1;
};
jQuery('#dyntable_tab1').dataTable({
"sPaginationType": "full_numbers",
"aoColumns": [
null,
null,
null,
{ "sType": "natural" }
]
[/code]
What am I doing wrong?
Thanks!
I have tried most of the solutions, but can't get none to work for me.
This is my table:
[code]
Title 1
Title 2
Title 3
Title 4
My value 1
My Value 2
My Value 3
$101.66
My value 1
My Value 2
My Value 3
$21,546.32
My value 1
My Value 2
My Value 3
$122.94
[/code]
As you can see, there is some html on it and the numbers have the dollar symbol, commas and period.
My last attempt was with naturalSort.js. I included the .js on my page and call the table as follows:
[code]
jQuery.fn.dataTableExt.oSort['natural-asc'] = function (a, b) {
return naturalSort(a, b);
};
jQuery.fn.dataTableExt.oSort['natural-desc'] = function (a, b) {
return naturalSort(a, b) * -1;
};
jQuery('#dyntable_tab1').dataTable({
"sPaginationType": "full_numbers",
"aoColumns": [
null,
null,
null,
{ "sType": "natural" }
]
[/code]
What am I doing wrong?
Thanks!
This discussion has been closed.
Replies
v1.10, which is currently pre-beta can be found here: https://github.com/DataTables/DataTables/tree/1_10_wip/media/js .
Let me know how you get on.
Allan
Can you post a direct link to download the .js? Thanks!
Ok, got someone to send me the code (I can't access github) and it works as expected.
Thanks!
Allan
I think you'll need the latest version of TableTools from git: https://github.com/DataTables/TableTools/tree/master/media/js
Allan
I have to mention, on the new version of DataTables, I still have an issue where if I add horizontal scrolling, the width of the table doesn't go full 100% and if I force 100% or 110% then the sorting labels don't show up correctly untill I click that bar.
Will you be addressing that on later fixes?
I do have to say this version is faster, at least seems that way, and smoother.
Thanks for your work.
Good to hear that it feels faster - it should be although I haven't yet profiled it :-)
Allan
Can't link to an actual page and I can't upload screenshoots. And without looking at all the code I'm not sure it would help much.
Basically, the title columns don't match the width of data columns.