Support » Plugin: TablePress » Sorting should account for HTML tags

  • Resolved archon810

    (@archon810)



    Hi,

    I’m using TP 1.3, and I think it could use an optimization for incorrect sorting when HTML tags, like <span> or <font> or <strong> are used inside table cells to give them a certain style. It looks like the plugin then ends up sorting alphabetically and the tags confuse it.

    The end result is the sorting puts 13213 surrounded by a <font> tag before 2321 not surrounded by anything when sorting from smallest to largest.

    Here’s an example: http://i.imgur.com/yAtlQ1M.png

    The solution should be to strip all html tags before doing the sorting.

    https://wordpress.org/plugins/tablepress/

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

    (@tobiasbg)

    Hi,

    thanks for your post, and sorry for the trouble.

    You are correct, the HTML tags mess with the number sorting there. The fix is to use a different sorting algorithm. That is already available for the external DataTables JS library that TablePress uses.
    For details, please see the possible sorting algorithms at http://datatables.net/plug-ins/sorting

    Depending on the exact format, it might be enough to install the TablePress Extension from http://tablepress.org/extensions/datatables-sorting-plugins/
    Otherwise, you could simply add the extra sorting algorithms to that Extension.

    Regards,
    Tobias

    Cheers, I’ll try those out. May I suggest adding this information to the FAQ, which I checked before posting here?

    Plugin Author TobiasBg

    (@tobiasbg)

    Hi,

    no problem, you are very welcome! 🙂 Good to hear that this helped!
    And yes, I should probably add this to the FAQ. Thanks for the suggestion!

    Best wishes,
    Tobias

    P.S.: In case you haven’t, please rate TablePress here in the plugin directory. Thanks!

    Already rated 5 stars 🙂 Amazing support btw.

    So I just installed and activated that extension, but it didn’t seem to work. I can see it’s loading in the html, but the sorting is still incorrect. I wonder if it’s because I have JS plugins load in the footer? This looks correct though…

    <script type='text/javascript' src='http://ap2.androidpolice.com/wp-content/plugins/tablepress/js/jquery.datatables.min.js?ver=1.3'></script>
    <script type='text/javascript' src='http://ap2.androidpolice.com/wp-content/plugins/tablepress-datatables-numhtml/jquery.datatables.numhtml.js?ver=1.1'></script>
    <script type="text/javascript">
    jQuery(document).ready(function($){
    $('#tablepress-1').dataTable({"aaSorting":[],"bSortClasses":false,"asStripeClasses":['even','odd'],"bPaginate":false,"bInfo":false});
    $('#tablepress-1-no-2').dataTable({"aaSorting":[],"bSortClasses":false,"asStripeClasses":['even','odd'],"bPaginate":false,"bInfo":false});
    });
    </script>
    Plugin Author TobiasBg

    (@tobiasbg)

    Hi,

    you might have to manually set the data type for the corresponding columns, by adding

    "aoColumnDefs": [ { "sType": "num-html", "aTargets": [ 2, 3 ] } ]

    to the “Custom Commands” textfield of the table.
    Change the 2, 3 to the desired columns numbers (minus 1, as counting starts with 0).

    Regards,
    Tobias

    Any way to do this for all tables? I can’t have my writers think about things like that – they’ll just forget.

    Plugin Author TobiasBg

    (@tobiasbg)

    Hi,

    no, not really, because this code has to be added on a per-column basis 🙁
    You could maybe experiment with using the type detection that the DataTables JS library offers for this format: http://datatables.net/plug-ins/type-detection#numbers_html
    It might be enough to add this code to the two JS files in the Extension.

    Regards,
    Tobias

    Thanks, that did it. There was a JS error – I had to replace $ with jQuery, but after that, it worked.

    Plugin Author TobiasBg

    (@tobiasbg)

    Hi,

    very cool! Great to hear that it’s working now! 🙂

    Best wishes,
    Tobias

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Sorting should account for HTML tags’ is closed to new replies.