WordPress.org

Support

Support » Plugins and Hacks » [Resolved] Sorting by Dollar Values

[Resolved] Sorting by Dollar Values

  • WP: ver 3.8.1
    TP: ver 1.3

    I’ve noticed that sorting a table by price (i.e., a column that contains dollar values) does not work correctly: Values are sorted by the first digit (e.g., $1, $12, $123, $2, $23, $234, and so on) and all other digits are ignored.

    I’ve read the section “Sorting or other JS functions are not working” of the TablePress Support FAQ and checked the versions of jQuery that are included in the page:

    eric@eric-x1:~$ grep -i jquery /tmp/example.com.htm | grep --color ver | sort
    <script type='text/javascript' src='http://example.com/wordpress_3/wp-content/plugins/contact-form-7/includes/js/jquery.form.min.js?ver=3.46.0-2013.11.21'></script>
    <script type='text/javascript' src='http://example.com/wordpress_3/wp-content/plugins/flexslider/assets/js/jquery.flexslider.min.js?ver=2.1.0-20121206'></script>
    <script type='text/javascript' src='http://example.com/wordpress_3/wp-content/plugins/flexslider/assets/js/jquery.mousewheel.min.js?ver=2.1.0-20121206'></script>
    <script type='text/javascript' src='http://example.com/wordpress_3/wp-content/plugins/revslider/rs-plugin/js/jquery.themepunch.revolution.min.js?ver=3.8.1'></script>
    <script type='text/javascript' src='http://example.com/wordpress_3/wp-content/plugins/tablepress/js/jquery.datatables.min.js?ver=1.3'></script>
    <script type='text/javascript' src='http://example.com/wordpress_3/wp-content/themes/inovado/framework/js/twitter/jquery.tweet.min.js?ver=1.0'></script>
    <script type='text/javascript' src='http://example.com/wordpress_3/wp-includes/js/jquery/jquery.js?ver=1.10.2'></script>
    <script type='text/javascript' src='http://example.com/wordpress_3/wp-includes/js/jquery/jquery-migrate.min.js?ver=1.2.1'></script>

    Could the other versions of jQuery be the problem? Or is this problem systemic to jQuery and/or Datatables?

    · TablePress: 1.3
    · TablePress (DB): 23
    · TablePress table scheme: 3
    · Plugin installed: 2014/01/28 23:32:31
    · WordPress: 3.8.1
    · Multisite: no
    · PHP: 5.3.3
    · mySQL (Server): 5.1.71
    · mySQL (Client): 5.1.71
    · ZIP support: yes
    · UTF-8 conversion: yes
    · WP Memory Limit: 40M
    · Server Memory Limit: 256M
    · Magic Quotes: off
    · WP_DEBUG: false
    · WP_POST_REVISIONS: true

    Eric P.

    http://wordpress.org/plugins/tablepress/

Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Author TobiasBg

    @tobiasbg

    Hi,

    thanks for your post, and sorry for the trouble.

    This is not a problem of the library not working at, but just a consequence of the data type that you are using. The sorting algorithm doesn’t recognize currencies by default and therefore sorts them as strings.
    To change that, please take a look at this TablePress Extension: http://tablepress.org/extensions/datatables-sorting-plugins/

    Regards,
    Tobias

    Thanks, Tobias:

    Installing the DataTables Sorting Extensions plugin fixed the way that currency values are sorted and it did it all without any configuration!

    Eric P.

    Plugin Author TobiasBg

    @tobiasbg

    Hi Eric,

    yes, cool, isn’t it? 🙂
    Good to hear that this helped!

    Best wishes,
    Tobias

    Tobias:

    Sorting of dollar-values / currencies breaks if there’s an empty cell in the sort range (e.g., http://rocket-powered.com/services/ssl-certificates/comodo-ssl-certificates/). Is there a work-around for this behavior?

    Thanks, again!
    Eric P.

    Sorting of dollar-values / currencies breaks if there’s an empty cell in the sort range…

    i.e., jquery/DataTables/TablePress treats the cells “above” the empty cell and the cells “below” the empty cell as separate groups and sorts within the groups correctly but that’s not the desired behavior [in this case].

    Plugin Author TobiasBg

    @tobiasbg

    Hi,

    sorry, unfortunately, I don’t have a readily usable solution for this. The problem is that the empty cell is no number, and thus the sorting algorithm from the DataTables JS library doesn’t know how to treat it.
    It would be necessary to extend that sorting algorithm here, if you can’t simply add a number there.

    Regards,
    Tobias

    Tobias:

    I took your explanation [to a different problem] at face-value:

    When sorting, HTML code is stripped before the sorting, which leaves that image column with empty strings.

    …and tried adding invisible zeros:

    <span style="visibility:hidden">0</span> and
    <span style="color:white">0</span>

    …but the get the same behavior: Values are sorted by the first digit (e.g., $1, $12, $123, $2, $23, $234, and so on) and all other digits are ignored.

    Can you recommend a simple work-around for sorting mixed numeric/empty columns?

    Thanks, again!
    Eric P.

    Plugin Author TobiasBg

    @tobiasbg

    Hi Eric,

    right now, I don’t really have a solution here. You could maybe add (plain) 0 to the cell and make it invible via CSS (see the FAQ question http://tablepress.org/faq/highlight-cells-or-content/ ), where you change the text color.

    Regards,
    Tobias

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘[Resolved] Sorting by Dollar Values’ is closed to new replies.