Sorting by Numbers

Sorting by Numbers

islandtalkerislandtalker Posts: 7Questions: 0Answers: 0
edited August 2013 in General
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!

Replies

  • allanallan Posts: 63,514Questions: 1Answers: 10,472 Site admin
    Are you up for an experiment? :-). DataTables v1.10 has new sorting abilities which should support your data out of the box without any modifications.

    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
  • islandtalkerislandtalker Posts: 7Questions: 0Answers: 0
    Hi,

    Can you post a direct link to download the .js? Thanks!
  • islandtalkerislandtalker Posts: 7Questions: 0Answers: 0
    Hi,

    Ok, got someone to send me the code (I can't access github) and it works as expected.

    Thanks!
  • allanallan Posts: 63,514Questions: 1Answers: 10,472 Site admin
    Excellent - that's good to hear. Thanks for the feedback.

    Allan
  • islandtalkerislandtalker Posts: 7Questions: 0Answers: 0
    Will this version work with TableTools v1.0.2?
  • allanallan Posts: 63,514Questions: 1Answers: 10,472 Site admin
    I very much doubt it - TableTools 1.0.2 is an extremely old version and certainly is no longer supported.

    I think you'll need the latest version of TableTools from git: https://github.com/DataTables/TableTools/tree/master/media/js

    Allan
  • islandtalkerislandtalker Posts: 7Questions: 0Answers: 0
    Thanks, will check it out.

    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.
  • allanallan Posts: 63,514Questions: 1Answers: 10,472 Site admin
    Can you link me to a test page showing the issue so I can fix it please? I'm not currently aware of any issues - but that's not to say there aren't any - just to say that I'm not aware of them!

    Good to hear that it feels faster - it should be although I haven't yet profiled it :-)

    Allan
  • islandtalkerislandtalker Posts: 7Questions: 0Answers: 0
    Hi,

    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.
This discussion has been closed.