• Resolved JDAsbill

    (@jdasbill)


    Hi,
    I love your plugin. It was exactly what I was looking for, and I was so excited to find it.
    I was wondering if there is way that certain keywords could be ignored when sorting. Namely “a,” “an,” and “the.” In my tables I deal heavily with titles, so ignoring these keywords while listing alphabetically, would be a wonderful modification.
    Thank you so much for your time, and this wonderful plugin!

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

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

    (@tobiasbg)

    Hi,

    thanks for your post, and sorry for the trouble.

    This is not possible by default, but you can try to add this by adding a new sorting algorithm.
    As a starting point, I suggest to install the “Sorting Plugins” Extension from http://tablepress.org/extensions/datatables-sorting-plugins/
    Then, append this to BOTH JavaScript files in the Extension:

    jQuery.extend( jQuery.fn.dataTableExt.oSort, {
        "anti-the-pre": function ( a ) {
            return a.replace(/^the /i, "").replace(/^an /i, "").replace(/^a /i, "");
        },
         "anti-the-asc": function ( a, b ) {
            return ((a < b) ? -1 : ((a > b) ? 1 : 0));
        },
         "anti-the-desc": function ( a, b ) {
            return ((a < b) ? 1 : ((a > b) ? -1 : 0));
        }
    } );

    Finally, add something like this to the “Custom Commands” textfield on the table’s “Edit” screen:

    "aoColumnDefs": [ { "sType": "anti-the", "aTargets": [ 2, 3 ] } ]

    The “2, 3” indicate that this sorting shall then apply to the third and fourth columns (counting starts with 0), so adjust that as necessary.

    Regards,
    Tobias

    Thread Starter JDAsbill

    (@jdasbill)

    Thanks a lot,
    I’m trying this out…

    Plugin Author TobiasBg

    (@tobiasbg)

    Hi,

    no problem, you are very welcome! 🙂 If there’s a problem, just let me know.

    Best wishes,
    Tobias

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

    Thread Starter JDAsbill

    (@jdasbill)

    Hi,
    It works like a charm. Thank you very much.
    The only problem is that the visitors have lost the ability to search, sort, and decide how many entries are immediately visible, in the actual page.
    In the TablePress Dashboard, all the checkboxes are filled in the “Features of the DataTables…” so I am not really sure why it doesn’t show up.

    Thread Starter JDAsbill

    (@jdasbill)

    Now the search, sorting, and pagination functions are all there. But sorting no longer works on column B and D – which are the targeted columns – and the ignoring of keywords “a,” “an,” and “the” is no longer working.
    I’m sorry that I am being such a nuisance.

    Plugin Author TobiasBg

    (@tobiasbg)

    Hi,

    can you please post a link to the page with the table?

    Regards,
    Tobias

    Thread Starter JDAsbill

    (@jdasbill)

    Sure, here is the website.

    Plugin Author TobiasBg

    (@tobiasbg)

    Hi,

    thanks for the link!

    The problem is how you inserted the JS code from above. For some reason, the quotation marks " where inserted as the encoded entity &quot;. This breaks the code. Could you please re-add the code from above and double check that it looks exactly like that?

    Regards,
    Tobias

    Thread Starter JDAsbill

    (@jdasbill)

    Hi,
    I got it working. Thanks so much for your help, I really appreciate it. Keep up the good work.

    Plugin Author TobiasBg

    (@tobiasbg)

    Hi,

    no problem, you are very welcome! 🙂 Good to hear that this helped!

    Best wishes,
    Tobias

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Ignore Keywords in Sorting’ is closed to new replies.