Filter: force cache build on initial search when delayInit true. Fixes #678

This commit is contained in:
Mottie 2014-07-11 14:52:59 -05:00
parent 4ef7bcd5a8
commit 4f29e36f12
2 changed files with 17 additions and 7 deletions

View File

@ -475,7 +475,7 @@
<li><a href="example-widget-editable.html">Content Editable widget</a> (v2.9; <span class="version updated">v2.13.2</span>).</li>
<li><span class="results">&dagger;</span> Filter Widget (<span class="version updated">v2.17.4</span>):
<ul>
<li><a href="example-widget-filter.html">basic</a> (v2.0.18; <span class="version updated">v2.17.1</span>)</li>
<li><a href="example-widget-filter.html">basic</a> (v2.0.18; <span class="version updated">v2.17.5</span>)</li>
<li><a href="example-widget-filter-any-match.html">external option (match any column)</a> (<span class="version">v2.13.3</span>; <span class="version updated">v2.15</span>)</li>
<li><a href="example-widget-filter-external-inputs.html">external inputs</a> (<span class="version">v2.14</span>; <span class="version updated">v2.15</span>)</li>
<li><a href="example-widget-filter-custom.html">custom</a> (v2.3.6; <span class="version updated">v2.10.1</span>)</li>
@ -496,9 +496,9 @@
<br><br>
</li>
<li>Pager plugin (<a href="example-pager.html">basic</a> &amp; <a href="example-pager-ajax.html">ajax</a> demos; <span class="version updated">v2.17.4</span>).</li>
<li>Pager plugin (<a href="example-pager.html">basic</a> &amp; <a href="example-pager-ajax.html">ajax</a> demos; <span class="version updated">v2.17.5</span>).</li>
<li>
Pager widget (<a href="example-widget-pager.html">basic</a> &amp; <a href="example-widget-pager-ajax.html">ajax</a> demos) (<span class="version">v2.12</span>; <span class="version updated">v2.17.4</span>).<br>
Pager widget (<a href="example-widget-pager.html">basic</a> &amp; <a href="example-widget-pager-ajax.html">ajax</a> demos) (<span class="version">v2.12</span>; <span class="version updated">v2.17.5</span>).<br>
<br>
</li>

View File

@ -592,7 +592,7 @@ ts.filter = {
}
c.$table.bind('addRows updateCell update updateRows updateComplete appendCache filterReset filterEnd search '.split(' ').join(c.namespace + 'filter '), function(event, filter) {
c.$table.find('.' + ts.css.filterRow).toggle( !(wo.filter_hideEmpty && $.isEmptyObject(c.cache)) ); // fixes #450
c.$table.find('.' + ts.css.filterRow).toggle( !(wo.filter_hideEmpty && $.isEmptyObject(c.cache) && !(c.delayInit && event.type === 'appendCache')) ); // fixes #450
if ( !/(search|filter)/.test(event.type) ) {
event.stopPropagation();
ts.filter.buildDefault(table, true);
@ -689,8 +689,10 @@ ts.filter = {
var wo = this.config.widgetOptions;
filters = ts.filter.setDefaults(table, c, wo) || [];
if (filters.length) {
// prevent delayInit from triggering a cache build if filters are empty
if ( !(c.delayInit && filters.join('') === '') ) {
ts.setFilters(table, filters, true);
// ts.filter.checkFilters(table, filters);
}
}
c.$table.trigger('filterFomatterUpdate');
if (!wo.filter_initialized) {
@ -852,7 +854,15 @@ ts.filter = {
filters = (filterArray) ? filter : ts.getFilters(table, true),
combinedFilters = (filters || []).join(''); // combined filter values
// prevent errors if delay init is set
if ($.isEmptyObject(c.cache)) { return; }
if ($.isEmptyObject(c.cache)) {
// update cache if delayInit set & pager has initialized (after user initiates a search)
if (c.delayInit && c.pager && c.pager.initialized) {
c.$table.trigger('updateCache', [function(){
ts.filter.checkFilters(table, false, skipFirst);
}] );
}
return;
}
// add filter array back into inputs
if (filterArray) {
ts.setFilters( table, filters, false, skipFirst !== true );