1

I have some tables which use the jQuery plugin 'tablesorter' to allow easy sorting. Recently, I found out that it included a zebra striping widget. I enabled it, and it's been working well.

I also decided to add the 'Sieve' plugin, as an alternative to the existing, homebuilt table search function, and that's where my problem arose - the striping is not redone during or after the search, leaving the table uneven and mismatched.

Thus far, I haven't been able to find a way to make it manually refresh, and I'm not sure where I would put it if I had - in the sieve .js file? Is there a way to make these two plugins play nice with each other?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Damien H
  • 174
  • 11
  • 1
    why wouldn't you use tablesorter filtering? https://mottie.github.io/tablesorter/docs/example-widget-filter.html – charlietfl Nov 07 '14 at 02:20
  • 1
    I think you will find that the original tablesorter hasn't been updated since about 2008, and that at least one fork [by Mottie](https://github.com/Mottie/tablesorter) is actively maintained - and includes some mention of zebrastriping in the changelog. To give yourself the best chance of success, I suggest using Mottie's fork. – Roamer-1888 Nov 07 '14 at 02:28
  • @charlietfl Well, I didn't know it existed until I read your and Roamer's comments. The version I had came with the application when I inherited it. I've found an equivalent to Sieve with https://mottie.github.io/tablesorter/docs/example-widget-filter-any-match.html however, I'm not sure where to put the JS code from that example. Would you know? – Damien H Nov 07 '14 at 04:08
  • look at the demo source code – charlietfl Nov 07 '14 at 13:24

1 Answers1

1

If you want to use the Sieve plugin, this code will work with either the original version of tablesorter or my fork of tablesorter (demo):

$(function () {
    var $table = $('table');

    $table
        .tablesorter({
            widgets: ['zebra']
        })
        .sieve({
            complete: function(){
                // update the zebra widget after Sieve completes
                $table.trigger('applyWidgets');
            }
        });

});
Mottie
  • 84,355
  • 30
  • 126
  • 241
  • Thank you very much! I have updated to your fork, and thanks to the snippet above, have everything working. In case you're curious, I'm not currently using the filtering widget because it doesn't deal with separated words very well - E.g. in a list of items 'A, B, C, D' I cannot search 'A C' and get a result, whereas I can do that in Sieve. Of course, there are drawbacks as well, but for the moment at least, I'll stick to a hybrid. – Damien H Nov 10 '14 at 04:08
  • The filter widget allows entering regex, and it also supports the "AND" and "OR" operators. So to find multiple items, search for "A|B|C|D". A full list of filter types can be found on [this page](http://mottie.github.io/tablesorter/docs/example-widget-filter.html) in the table inside the Notes sections of the accordion. – Mottie Nov 10 '14 at 22:18