Numerical Sorting

Numerical Sorting

lauralaura Posts: 14Questions: 0Answers: 0
edited June 2009 in General
Hi there - love this script - it's the best thing since sliced bread!

I am having a problem sorting by numerical data. My first column in the table contains an ID number and I want the table to default to sorting by Number backwards (20, 19, 18, 17... etc).

This is what I have but changing asc or desc doesn't do anything - it always sorts as 1, 2, 3, 4...


$(document).ready(function() {
$('#articles').dataTable( {
"aoData": [
{ "sType": "numeric", "sWidth": "0%"},
{ "sType": "html", "sWidth": "30%" },
{ "sType": "string", "sWidth": "70%" }
],
aaSorting: [[0,'desc']],
"sPaginationType": "full_numbers"
} );
} );


What am I doing wrong?

Thanks for your help!

Replies

  • lauralaura Posts: 14Questions: 0Answers: 0
    Sorry - got it figured out - seems I had the numbers wrapped in a and when I removed it, all works fine.

    Thanks!
  • allanallan Posts: 61,833Questions: 1Answers: 10,133 Site admin
    Hi Laura,

    Good thanks - thanks for noting that you got this fixed. If you do require the div wrappers, then it is possible to have a custom sorting function which will take this into account and still sort numerically. If you want more information on this, please feel free to ask.

    Regards,
    Allan
  • myqalanmyqalan Posts: 13Questions: 0Answers: 0
    Allan,

    I'm having a very similar problem. I use ColdFusion variables to populate my table. The first column is a numeric value that is also a link. When the table populates, the column is properly sorted (asc) but when I click on the column header to switch it to descending, nothing happens. I also noticed that if I sort on a different column, the first will change as expected, but will not be sortable. It appears that the ability to sort the first column has been disabled.

    I was originally having a problem getting the column to sort properly (numeric values being sorted alphabetically), so I added the "sType": "numeric" value. That's when I started having the above problem.

    Here is what I have:

    [code]
    $('#writerHistory').dataTable( {
    "sPaginationType": "full_numbers",
    "bAutoWidth": false,
    "aoColumns": [
    { "sWidth": "90px", "sType": "numeric" },
    { "sWidth": "350px" },
    { "sWidth": "90px" },
    { "sWidth": "130px" },
    { "sWidth": "150px" }
    ]
    } );
    [/code]

    And this is the code for the column that is having the issue:

    [code]
    #essayhistory.essayid#
    [/code]

    Any ideas?
  • myqalanmyqalan Posts: 13Questions: 0Answers: 0
    Allan,

    Please disregard my request for help above. After writing it, I found the sorting plug-in information, and was able to utilize the "num-html" sorting function provided there.

    Thanks for an AWESOME product!!!
This discussion has been closed.