WordPress.org

Ready to get started?Download WordPress

Forums

TablePress
[resolved] Sorting numbers is screw 1 - 10 - 100 - 1011 .. (6 posts)

  1. wimothy2
    Member
    Posted 2 months ago #

    Hello,

    When you click on the second column instead of getting 1, 2 , 3 , 4 .. I get
    1 10 100 101 102 ...
    http://www.sport-events.be/website/startlijsten-bilzen111/

    How can I sort by numbers correctly ?

    Thanks
    Wim

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

  2. TobiasBg
    Member
    Plugin Author

    Posted 2 months ago #

    Hi,

    thanks for your post, and sorry for the trouble.

    You are probably refering to column 2 here? My assumption is that the JS library is somehow not recognizing the cell content as numbers, but as strings. We can however to try set that as fixed, by adding this to the "Custom Commands" textfield on the "Edit" screen of the table:

    "aoColumnDefs": [ { "sType": "numeric", "aTargets": [ 1 ] } ]

    Can you please try that? Thanks!

    Regards,
    Tobias

  3. wimothy2
    Member
    Posted 2 months ago #

    no

    Please try to sort a column and see what happens

  4. TobiasBg
    Member
    Plugin Author

    Posted 2 months ago #

    Hi,

    ah, found the problem: Your theme is loading a JS file http://www.sport-events.be/website/wp-content/themes/Fest/js/gk.scripts.js
    That file contains some JS code that modifies each table cell, by prepending some HTML code in it. this HTML code however breaks the data type and therefore the sorting.
    It is this code:

    jQuery('article section table').each(function (i, table) {
        table = jQuery(table);
        var heads = table.find('thead th');
        var cells = table.find('tbody td');
        var heads_amount = heads.length;
        // if there are the thead cells
        if (heads_amount) {
            var cells_len = cells.length;
            for (var j = 0; j < cells_len; j++) {
                var head_content = jQuery(heads.get(j % heads_amount)).text();
                jQuery(cells.get(j)).html('<span class="gk-table-label">' + head_content + '</span>' + jQuery(cells.get(j)).html());
            }
        }
    });

    You will need to turn that code of by editing that mentioned file, by commenting that code out with /* and */ around it, like

    /*
     ... code from above ...
    */

    You can then also remove the code from the "Custom Commands" from my first reply.

    Regards,
    Tobias

  5. wimothy2
    Member
    Posted 2 months ago #

    perfect Thanks !

  6. TobiasBg
    Member
    Plugin Author

    Posted 2 months ago #

    Hi,

    no problem, you are very welcome! :-) Good to hear that this helped!

    Best wishes,
    Tobias

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

Reply

You must log in to post.

About this Plugin

About this Topic

Tags

No tags yet.