sType='numeric' doesn't seem to work anymore

sType='numeric' doesn't seem to work anymore

ses4jses4j Posts: 5Questions: 1Answers: 0

Hi -

Testing out datatables 1.10. I have an aoColumns member with {'sType':'numeric'} which no longer seems to work. {'sType': 'num'} seems to work instead, now. Intentional change? Am I doing something stupid?

Scott

Answers

  • RockbRockb Posts: 97Questions: 0Answers: 0

    There are some changes like this. I've checked everything: Some "oldies" work, but the rest seems to be deprecated, so I fixed everything.

    Use "type" instead: http://datatables.net/reference/option/columns.type

  • ses4jses4j Posts: 5Questions: 1Answers: 0

    Thanks, didn't see type. Should this stuff make it into the release notes for 1.10?

  • RockbRockb Posts: 97Questions: 0Answers: 0

    I think that would be too much in this "major" release, but that's just my guess. Maybe Allan can explain it.

  • ses4jses4j Posts: 5Questions: 1Answers: 0

    It's here I'd hope to see those things: https://datatables.net/upgrade/1.10

  • allanallan Posts: 61,665Questions: 1Answers: 10,096 Site admin
    edited May 2014

    The numeric type was built-in and would have been auto detected if the data in the column was suitable for it. If it wasn't numeric data, then the column wouldn't have been detected as numeric (it would be something else, likely string). Setting it manually to numeric doesn't mean that the data in the column magically becomes numeric.

    Because this was an internal data type, that was auto detected, that change wasn't documented in the upgrade notes.

    Can you show me that table the is causing you the problem here, with the non-numeric data that you want to treat as numeric? :-) Or if there is an error in DataTables numeric type detection, that would be good to find and debug.

    Allan

  • ses4jses4j Posts: 5Questions: 1Answers: 0

    Sure. The tables in question had mostly numerics, but the odd "N/A" or things like that. Forcing them to identify as numeric caused it to sort well enough, certainly better than any string/alphanumeric generic sorting, and much easier than builting a custom sorter of "numerics or N/As"...

  • allanallan Posts: 61,665Questions: 1Answers: 10,096 Site admin

    Okay, but numeric sorting assumes that it was sorting numeric data. "N/A" is not numeric and therefore can't be sorted as such - which is why you had to force it. It was an internal "quirk" that you were using, which is absolutely fine, but if I documented every internal change the list would be massive.

    A custom sorter, as you indicate, is the correct why to sort this type of data and would work through the upgrade.

    Allan

  • ses4jses4j Posts: 5Questions: 1Answers: 0

    Shrug, up to you. I didn't make it up though, and I don't think I got it from code spelunking... The trick is referenced here: http://stackoverflow.com/questions/8008442/how-to-impose-numerical-sort-with-jquery-and-datatables and other places I'm sure.

    Separately, maybe there's some way to cleanly have the automatic format detector identify numeric-plus-an-empty-string-or-a-few-special-values, because I would believe it's the most common case. As it is, it will sort alphabetically, which makes sense from the inside, and is most definitely not what the user wants. I've brought datatables into several different teams in the last couple years, and seen it be abused every which way. One bug I frequently have had to fix is this one, where they leave the defaults but their data includes "n/a" or its like.

  • allanallan Posts: 61,665Questions: 1Answers: 10,096 Site admin

    Yup - it is a pain for sure, but the library has to move forward. If I just kept supporting all the hacks over the years it would never develop!

    The built in numeric type will allow - as the only non-numeric data. A sort type that detects any configurable string I'm sure would be quite easy to create.

    Allan

This discussion has been closed.