From 443f963567b64a628627770e04c2e2101858c948 Mon Sep 17 00:00:00 2001 From: Mottie Date: Mon, 3 Nov 2014 17:33:02 -0600 Subject: [PATCH] Filter: fix filter initialization intermittently stalling --- js/jquery.tablesorter.widgets.js | 42 ++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 16 deletions(-) diff --git a/js/jquery.tablesorter.widgets.js b/js/jquery.tablesorter.widgets.js index c1eba9db..84a14836 100644 --- a/js/jquery.tablesorter.widgets.js +++ b/js/jquery.tablesorter.widgets.js @@ -657,7 +657,7 @@ ts.filter = { $(document) .undelegate(wo.filter_reset, 'click.tsfilter') .delegate(wo.filter_reset, 'click.tsfilter', function() { - // trigger a reset event, so other functions (filterFormatter) know when to reset + // trigger a reset event, so other functions (filter_formatter) know when to reset c.$table.trigger('filterReset'); }); } @@ -764,23 +764,27 @@ ts.filter = { completed = function(){ wo.filter_initialized = true; c.$table.trigger('filterInit', c); - ts.filter.findRows(c.table, c.$table.data('lastSearch'), null); + ts.filter.findRows(c.table, c.$table.data('lastSearch') || []); }; - $.each( wo.filter_formatterInit, function(i, val) { - if (val === 1) { - count++; - } - }); - clearTimeout(wo.filter_initTimer); - if (!wo.filter_initialized && count === wo.filter_formatterCount) { - // filter widget initialized + if ( $.isEmptyObject( wo.filter_formatter ) ) { completed(); - } else if (!wo.filter_initialized) { - // fall back in case a filter_formatter doesn't call - // $.tablesorter.filter.formatterUpdated($cell, column), and the count is off - wo.filter_initTimer = setTimeout(function(){ + } else { + $.each( wo.filter_formatterInit, function(i, val) { + if (val === 1) { + count++; + } + }); + clearTimeout(wo.filter_initTimer); + if (!wo.filter_initialized && count === wo.filter_formatterCount) { + // filter widget initialized completed(); - }, 500); + } else if (!wo.filter_initialized) { + // fall back in case a filter_formatter doesn't call + // $.tablesorter.filter.formatterUpdated($cell, column), and the count is off + wo.filter_initTimer = setTimeout(function(){ + completed(); + }, 500); + } } }, @@ -1114,10 +1118,16 @@ ts.filter = { $(this).hasClass('filter-parsed'); }).get(); - if (c.debug) { time = new Date(); } + if (c.debug) { + ts.log('Starting filter widget search', filters); + time = new Date(); + } // filtered rows count c.filteredRows = 0; c.totalRows = 0; + // combindedFilters are undefined on init + combinedFilters = (filters || []).join(''); + for (tbodyIndex = 0; tbodyIndex < $tbodies.length; tbodyIndex++ ) { if ($tbodies.eq(tbodyIndex).hasClass(c.cssInfoBlock || ts.css.info)) { continue; } // ignore info blocks, issue #264 $tbody = ts.processTbody(table, $tbodies.eq(tbodyIndex), true);