I have following javascript:
$(function(){
$table = $('#myTable')
.tablesorter({
theme: 'blue',
widthFixed: true,
headerTemplate: '{content} {icon}',
widgets: ['zebra','filter'],
widgetOptions: {
zebra: ["even", "odd"],
// filter_anyMatch replaced! Instead use the filter_external option
// Set to use a jQuery selector (or jQuery object) pointing to the
// external filter (column specific or any match)
filter_external : '.search',
// add a default type search to the first name column
filter_defaultFilter: { 1 : '~{query}' },
// include column filters
filter_columnFilters: true,
filter_placeholder: { search : 'Search...' },
filter_saveFilters : true,
filter_reset: '.reset'
}
})
// needed for pager plugin to know when to calculate filtered rows/pages
.addClass('hasFilters')
.tablesorterPager({
container: $(".table-pager"),
output: '{page} of {filteredPages} ({filteredRows})',
size: 5
});
$('#search').quicksearch('table tbody tr', {
delay: 500,
show: function () {
$(this).removeClass('filtered');
$table.trigger('pageSet'); // reset to page 1 & update display
},
hide: function () {
$(this).hide().addClass('filtered');
$table.trigger('pageSet'); // reset to page 1 & update display
},
onAfter: function () {
$table.trigger('update.pager');
}
});
});
(function(b,k,q,r){b.fn.quicksearch=function(l,p){var m,n,h,e,f="",g=this,a=b.extend({delay:100,selector:null,stripeRows:null,loader:null,noResults:"",matchedResultsCount:0,bind:"keyup",onBefore:function(){},onAfter:function(){},show:function(){this.style.display=""},hide:function(){this.style.display="none"},prepareQuery:function(a){return a.toLowerCase().split(" ")},testQuery:function(a,b,d){for(d=0;d<a.length;d+=1)if(-1===b.indexOf(a[d]))return!1;return!0}},p);this.go=function(){for(var c=0,b=
0,d=!0,e=a.prepareQuery(f),g=0===f.replace(" ","").length,c=0,k=h.length;c<k;c++)g||a.testQuery(e,n[c],h[c])?(a.show.apply(h[c]),d=!1,b++):a.hide.apply(h[c]);d?this.results(!1):(this.results(!0),this.stripe());this.matchedResultsCount=b;this.loader(!1);a.onAfter();return this};this.search=function(a){f=a;g.trigger()};this.currentMatchedResults=function(){return this.matchedResultsCount};this.stripe=function(){if("object"===typeof a.stripeRows&&null!==a.stripeRows){var c=a.stripeRows.join(" "),f=a.stripeRows.length;
e.not(":hidden").each(function(d){b(this).removeClass(c).addClass(a.stripeRows[d%f])})}return this};this.strip_html=function(a){a=a.replace(RegExp("<[^<]+>","g"),"");return a=b.trim(a.toLowerCase())};this.results=function(c){"string"===typeof a.noResults&&""!==a.noResults&&(c?b(a.noResults).hide():b(a.noResults).show());return this};this.loader=function(c){"string"===typeof a.loader&&""!==a.loader&&(c?b(a.loader).show():b(a.loader).hide());return this};this.cache=function(){e=b(l);"string"===typeof a.noResults&&
""!==a.noResults&&(e=e.not(a.noResults));n=("string"===typeof a.selector?e.find(a.selector):b(l).not(a.noResults)).map(function(){return g.strip_html(this.innerHTML)});h=e.map(function(){return this});f=f||this.val()||"";return this.go()};this.trigger=function(){this.loader(!0);a.onBefore();k.clearTimeout(m);m=k.setTimeout(function(){g.go()},a.delay);return this};this.cache();this.results(!0);this.stripe();this.loader(!1);return this.each(function(){b(this).on(a.bind,function(){f=b(this).val();g.trigger()})})}})(jQuery,
this,document);
following html:
<form>
<div>
<input id="search" type="search" placeholder="Search" />
</div>
</form>
<div class="table-pager">Show
<select class="pagesize">
<option selected="selected" value="5">5</option>
<option value="10">10</option>
</select>entries | <span class="pagedisplay"></span> |
<button type="button" class="btn prev">←</button>
<button type="button" class="btn next">→</button>
</div>
<table id="myTable">
<thead>
<tr>
<th>One</th>
<th>Two</th>
<th>Three</th>
<th>Four</th>
</tr>
</thead>
<tbody>
<tr>
<td>abc 123</td>
<td>10</td>
<td>Koala</td>
<td>http://www.google.com</td>
</tr>
<tr>
<td>abc 1</td>
<td>234</td>
<td>Ox</td>
<td>http://www.yahoo.com</td>
</tr>
<tr>
<td>abc 9</td>
<td>10</td>
<td>Girafee</td>
<td>http://www.facebook.com</td>
</tr>
<tr>
<td>zyx 24</td>
<td>767</td>
<td>Bison</td>
<td>http://www.whitehouse.gov/</td>
</tr>
<tr>
<td>abc 11</td>
<td>3</td>
<td>Chimp</td>
<td>http://www.ucla.edu/</td>
</tr>
<tr>
<td>abc 2</td>
<td>56</td>
<td>Elephant</td>
<td>http://www.wikipedia.org/</td>
</tr>
<tr>
<td>abc 9</td>
<td>155</td>
<td>Lion</td>
<td>http://www.nytimes.com/</td>
</tr>
<tr>
<td>ABC 10</td>
<td>87</td>
<td>Zebra</td>
<td>http://www.google.com</td>
</tr>
<tr>
<td>zyx 1</td>
<td>999</td>
<td>Koala</td>
<td>http://www.mit.edu/</td>
</tr>
<tr>
<td>zyx 12</td>
<td>0</td>
<td>Llama</td>
<td>http://www.nasa.gov/</td>
</tr>
<tr>
<td>abc 111</td>
<td>10</td>
<td>Koala</td>
<td>http://www.google.com</td>
</tr>
<tr>
<td>abc 1</td>
<td>234</td>
<td>Ox</td>
<td>http://www.yahoo.com</td>
</tr>
<tr>
<td>abc 9</td>
<td>10</td>
<td>Girafee</td>
<td>http://www.facebook.com</td>
</tr>
<tr>
<td>zyx 24</td>
<td>767</td>
<td>Bison</td>
<td>http://www.whitehouse.gov/</td>
</tr>
<tr>
<td>abc 11</td>
<td>3</td>
<td>Chimp</td>
<td>http://www.ucla.edu/</td>
</tr>
<tr>
<td>abc 2</td>
<td>56</td>
<td>Elephant</td>
<td>http://www.wikipedia.org/</td>
</tr>
<tr>
<td>abc 9</td>
<td>155</td>
<td>Lion</td>
<td>http://www.nytimes.com/</td>
</tr>
<tr>
<td>ABC 10</td>
<td>87</td>
<td>Zebra</td>
<td>http://www.google.com</td>
</tr>
<tr>
<td>zyx 1</td>
<td>999</td>
<td>Koala</td>
<td>http://www.mit.edu/</td>
</tr>
<tr>
<td>zyx 12</td>
<td>0</td>
<td>Llama</td>
<td>http://www.nasa.gov/</td>
</tr>
<tr>
<td>abc 222</td>
<td>10</td>
<td>Koala</td>
<td>http://www.google.com</td>
</tr>
<tr>
<td>abc 1</td>
<td>234</td>
<td>Ox</td>
<td>http://www.yahoo.com</td>
</tr>
<tr>
<td>abc 9</td>
<td>10</td>
<td>Girafee</td>
<td>http://www.facebook.com</td>
</tr>
<tr>
<td>zyx 24</td>
<td>767</td>
<td>Bison</td>
<td>http://www.whitehouse.gov/</td>
</tr>
<tr>
<td>abc 11</td>
<td>3</td>
<td>Chimp</td>
<td>http://www.ucla.edu/</td>
</tr>
<tr>
<td>abc 2</td>
<td>56</td>
<td>Elephant</td>
<td>http://www.wikipedia.org/</td>
</tr>
<tr>
<td>abc 9</td>
<td>155</td>
<td>Lion</td>
<td>http://www.nytimes.com/</td>
</tr>
<tr>
<td>ABC 10</td>
<td>87</td>
<td>Zebra</td>
<td>http://www.google.com</td>
</tr>
<tr>
<td>zyx 1</td>
<td>999</td>
<td>Koala</td>
<td>http://www.mit.edu/</td>
</tr>
<tr>
<td>zyx 12</td>
<td>0</td>
<td>Llama</td>
<td>http://www.nasa.gov/</td>
</tr>
</tbody>
</table>
It works almost good. I have one issue only.
When I click X
to reset filter - nothings to happens.
desired result - filter should reset and table should update.
Also I have a problem when I erase symbols in search field - table don't update
How to fix this issue?
It looks like the quicksearch demo no longer works properly.
So, instead of using the quicksearch plugin, you could use the filter widget to match content in all columns:
<input class="search" type="search" data-column="all">
then include that input as an external filter, and hide the filter row
filter_external : '.search',
filter_columnFilters: false
To do the same thing, and have the "x" in the input work properly.
Full code & demo:
$(function () {
$table = $('#myTable')
.tablesorter({
theme: 'blue',
widthFixed: true,
headerTemplate: '{content} {icon}',
widgets: ['zebra', 'filter'],
widgetOptions: {
zebra: ["even", "odd"],
filter_external: '.search',
filter_columnFilters: false
}
})
.tablesorterPager({
container: $(".table-pager"),
output: '{page} of {filteredPages} ({filteredRows})',
size: 5
});
});