WordPress.org

Ready to get started?Download WordPress

Forums

WP-Table Reloaded
[resolved] Sorting numbers (8 posts)

  1. try2bepro
    Member
    Posted 1 year ago #

    Hello,

    I'm using your (very good) plugin by importing .csv files and customizing tables with them : )

    One of my columns is number-valued and your plugin formats my numbers to the way like this:
    12 200 191
    15 243 512
    243 512
    (spaces in numbers) And now when I sort it - it only sees the first number (12 and 15 in here) and in some ways results are not correct. (When i sort above numbers - it shows that 243 512 is the highest)

    When I manually delete spaces from numbers, and my numbers become like:
    12200191
    15243512
    243512

    Everything works fine. Is it possible to have spaces in my numbers and sort them correctly?

    Cheers! Thank you for your work!

    http://wordpress.org/extend/plugins/wp-table-reloaded/

  2. TobiasBg
    Member
    Plugin Author

    Posted 1 year ago #

    Hi,

    you are correct. Sorting values with spaces (just like currency values) needs some "special treatment". This is because the JavaScript code does not know that the cell content is number when it contains spaces and then believes it is a string.
    From the DataTables website I found some code which should tell the plugin how to sort such values anyway. I built a WP-Table Reloaded Extension from that, which you can get here: http://tobias.baethge.com/download/plugins/additional/wp-table-reloaded-currency-sorting.zip

    (Don't let the name fool you. The code is intended for currency values but works for your numbers as well.)

    Please install that as a regular WordPress plugin and activate it.
    After that, you will need to add a command to the "Custom Commands" textfield in the "DataTables JavaScript Features" section on the "Edit" screen of your table:

    "aoColumnDefs": [ { "sType": "currency_sorting", "aTargets": [ "column-1", "column-3" ] } ]

    That example would make the columns 1 and 3 treated with this code, so just change that as necessary.

    Regards,
    Tobias

  3. try2bepro
    Member
    Posted 1 year ago #

    Thank you Tobias - it looks great! : )

    I have one more question according to this fix, let's say that I have number-valued column and some of the fields are like "no data" and it's signed by dash and it looks like that:

    12 200 191
    15 243 512
    -
    243 512
    15 666 512
    -
    14 243 512

    It looks like sorting can't handle these dashes - is there some special character, which should I use for this purpose?

    I tried with no character at all instead of dash and it works weird too : /

    Thank you!

  4. TobiasBg
    Member
    Plugin Author

    Posted 1 year ago #

    Hi,

    it should actually work with an empty cell, as that is treated as 0 as far as I know...

    Regards,
    Tobias

  5. try2bepro
    Member
    Posted 1 year ago #

    Hi,

    it' actually not working with empty cells : ( Works fine only when all cells are numbers.

    Thank you!

  6. TobiasBg
    Member
    Plugin Author

    Posted 1 year ago #

    Hi,

    mmh, okay... It is possible that the empty cells only work if the default sorting is used. I guess, you'll have to decide: Either use only numbers without spaces, or don't include rows without a value...

    Regards,
    Tobias

  7. try2bepro
    Member
    Posted 1 year ago #

    Ok, i'll do it that way : ) thanks!

  8. TobiasBg
    Member
    Plugin Author

    Posted 1 year ago #

    Hi,

    ok :-) Sorry for not having a solution that works with both these things.

    Best wishes,
    Tobias

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.