1

Internal filter widget as opposed to an external one as is outlined in this example:

http://mottie.github.io/tablesorter/beta-testing/example-external-filters-using-select2.html

I am looking for a behavior that is similar to the first two external filter boxes with placeholders: AlphaNumeric and AlphaNumeric Tag but I want that behavior inside of the table. Here is what I tried to do:

<th class="filter-select2" data-placeholder="select something">

This does not work, but if I change "filter-select2" to "filter-select", then it does.

I am looking for a way to hack/customize the existing tablesorter behavior to allow for using select2 internally. I do not know JS and the library well enough to attempt this on my own.

Here is JavaScript snippet that I use to initialize the tablesorter library.

$('#table1').tablesorter({
    theme : 'ice',
    cssInfoBlock : 'tablesorter-no-sort',
    widgets: ['zebra', 'stickyHeaders', 'filter']
});
Leonid
  • 622
  • 3
  • 9
  • 22
  • It's a bit more complicated than that... I was working on some code to get select2 to work with the [filter formatter option](http://mottie.github.io/tablesorter/docs/#widget-filter-formatter), but I haven't tested it thoroughly. I'll see what I can do, when I have more free time. – Mottie Mar 11 '14 at 03:29
  • Hi @Mottie, I understand and can wait. You do not owe anything to anyone, although your enthusiasm about improving and maintaining tablesorter is certainly appreciated by other programmers and myself. Have you considered soliciting PayPal donations for this highly valuable library? – Leonid Mar 11 '14 at 17:54
  • This may not be exactly related to this question, but I am currently using chosen, not select2 (simply because I stumbled upon chosen first). I can dump it and start using select2. I suppose there was a reason why you started to support one and not the other. Any comments on: http://stackoverflow.com/questions/13575531/what-are-the-differences-between-chosen-and-select2 – Leonid Mar 12 '14 at 00:27
  • Same reason... I ran into chosen first. LOL. I do prefer select2 now, but I have so much other stuff going on that I have a hard time finding time, or remembering to work on these little side projects. – Mottie Mar 12 '14 at 02:05

1 Answers1

1

I just added some filter formatter code for the select2 plugin. Use it as follows:

$('table').tablesorter({
  theme: 'blue',
  widthFixed: true,
  widgets: ['zebra', 'filter'],
  widgetOptions : {
    filter_reset : 'button.reset',
    filter_formatter : {
      // Alphanumeric (match)
      0 : function($cell, indx){
        return $.tablesorter.filterFormatter.select2( $cell, indx, {
          match : true, // adds "filter-match" to header
          cellText : 'Match: ',
          width: '85%'
        });
      }
    }
  }
});
Mottie
  • 84,355
  • 30
  • 126
  • 241