Unable to allow user sort after specifying sTypes in aoColumns

Unable to allow user sort after specifying sTypes in aoColumns

nyknyk Posts: 18Questions: 0Answers: 0
edited September 2011 in General
Exactly as the title says. I have a Datatable that's rendering from an HTML table. In the initial dataTables call, I'm specifying:


[code]"aoColumns": [{"sType": "numeric"}, null][/code]

on a two-column table. The first column is a number(Integer) but I'm using EL to render it(${id}). Before it was sorting them as a String(so 10, 100 came before 20, when it should be 10, 20, 100). Now that I add the above string, it sorts it properly initially, but when I click the header to have it sort(by descending instead of ascending) it doesn't allow the column with the changed sType to be sorted.

The numbers are Raw integers, no formatting and no ,'s or .' to worry about, just 1234.

Any idea or help?

Replies

  • allanallan Posts: 63,532Questions: 1Answers: 10,475 Site admin
    Can you give us a link? If it wasn't detected as 'numeric' automatically then there is some non-numeric data in the column somewhere, which will likely be causing a Javascript error (have a look at the console in Firebug / Inspector).

    Allan
  • nyknyk Posts: 18Questions: 0Answers: 0
    edited September 2011
    I have firebug installed and there are no errors being reported.

    The site is internal so I'm unable to share it, but all the data is numbers in that column. From what I've seen before, EL has problems with Numbers so it's really printing them out and that's it, I don't know if they are true and proper Integer classes, and it's going into an HTML , but I can verify that everything in the column is a valid integer.
  • nyknyk Posts: 18Questions: 0Answers: 0
    edited September 2011
    Found the problem. When I rendered the table elements like:

    [code]

    1

    [/code]

    instead of like:

    [code]

    1

    [/code]

    It caused dataTables to not see it properly I guess, because as soon as I did it as example 2 here, it sorted it properly.
  • allanallan Posts: 63,532Questions: 1Answers: 10,475 Site admin
    What version of DataTables are you using? It should be able to deal with this okay...

    Thanks,
    Allan
  • nyknyk Posts: 18Questions: 0Answers: 0
    1.8.0. Not sure, but once I take away the labels I had around them and put it on one line, it all works fine.
  • allanallan Posts: 63,532Questions: 1Answers: 10,475 Site admin
    I've just tested it with 1.8.2 and it seems to work okay there. If you could try upgraded and test it that would be great. If that doesn't help, if you could let me know what platform and browser you are using, that would also be useful.

    Allan
  • nyknyk Posts: 18Questions: 0Answers: 0
    I'll upgrade, but the problems seems to stem from using around the number. Once that is added it becomes a sort by string.
  • nyknyk Posts: 18Questions: 0Answers: 0
    I fixed my above solution, it's not the TD that was killing it, it was 1 that would cause it to be read as text instead of a number by DataTables.
  • allanallan Posts: 63,532Questions: 1Answers: 10,475 Site admin
    Yup that would do it :-). It would cause it to be read as HTML, and thus string sorted. There is an HTML numeric sorting plug-in available here: http://datatables.net/plug-ins/sorting#numbers_html

    Allan
  • nyknyk Posts: 18Questions: 0Answers: 0
    It's okay, I can remove the label tags I put them there so that it would display a mouse pointer instead of a highlighter when mousing over it. I just though it was weird that it would read it like that.
This discussion has been closed.