diff --git a/docs/example-widget-filter.html b/docs/example-widget-filter.html index 1a59f2ea..8a224020 100644 --- a/docs/example-widget-filter.html +++ b/docs/example-widget-filter.html @@ -257,7 +257,7 @@ $(function(){

Filter widget defaults (added inside of tablesorter widgetOptions)

- TIP! Click on the link in the function column to reveal full details (or toggle|show|hide all) or double click to update the browser location. + TIP! Click on the link in the function column to reveal full details (or toggle|show|hide all) or double click to update the browser location.
@@ -327,7 +327,7 @@ $(function(){
  • Select2 plugin.
  • - + @@ -431,7 +431,7 @@ $(function(){ - + @@ -562,12 +562,12 @@ $(".search").bind('search keyup', function (e) {

    Changes

    -

    Moved to the wiki pages - filter change log. + Moved to the wiki pages - filter change log.

    Localization

    -

    You can now change the language of the searches used within the filter widget. For example, to change the localization to French, do the following: + You can now change the language of the searches used within the filter widget. For example, to change the localization to French, do the following:

    // add French support
     $.extend($.tablesorter.language, {
     	to  : 'à',
    diff --git a/js/jquery.tablesorter.widgets.js b/js/jquery.tablesorter.widgets.js
    index d9c366a6..ef265c56 100644
    --- a/js/jquery.tablesorter.widgets.js
    +++ b/js/jquery.tablesorter.widgets.js
    @@ -568,6 +568,9 @@ ts.filter = {
     		}
     		c.$table.addClass('hasFilters');
     
    +		// define searchTimer so using clearTimeout won't cause an undefined error
    +		wo.searchTimer = null;
    +
     		$.extend( regex, {
     			child : new RegExp(c.cssChildRow),
     			filtered : new RegExp(wo.filter_filteredRow),
    @@ -592,6 +595,7 @@ ts.filter = {
     				ts.filter.buildDefault(table, true);
     			}
     			if (event.type === 'filterReset') {
    +				c.$table.find('.' + ts.css.filter).add(wo.filter_$externalFilters).val('');
     				ts.filter.searching(table, []);
     			} else if (event.type === 'filterEnd') {
     				ts.filter.buildDefault(table, true);
    @@ -788,29 +792,46 @@ ts.filter = {
     		.attr('data-lastSearchTime', new Date().getTime())
     		.unbind('keypress keyup search change '.split(' ').join(c.namespace + 'filter '))
     		// include change for select - fixes #473
    -		.bind('keyup search change '.split(' ').join(c.namespace + 'filter '), function(event) {
    +		.bind('keyup' + c.namespace + 'filter', function(event) {
     			$(this).attr('data-lastSearchTime', new Date().getTime());
     			// emulate what webkit does.... escape clears the filter
     			if (event.which === 27) {
     				this.value = '';
    -			// liveSearch can contain a min value length; ignore arrow and meta keys, but allow backspace
    -			} else if ( (typeof wo.filter_liveSearch === 'number' && this.value.length < wo.filter_liveSearch && this.value !== '') ||
    -				( event.type === 'keyup' && ( (event.which < 32 && event.which !== 8 && wo.filter_liveSearch === true && event.which !== 13) ||
    -				( event.which >= 37 && event.which <= 40 ) || (event.which !== 13 && wo.filter_liveSearch === false) ) ) ) {
    -					return;
    +			// live search
    +			} else if ( wo.filter_liveSearch === false ) {
    +				return;
    +				// don't return if the search value is empty (all rows need to be revealed)
    +			} else if ( this.value !== '' && (
    +				// liveSearch can contain a min value length; ignore arrow and meta keys, but allow backspace
    +				( typeof wo.filter_liveSearch === 'number' && this.value.length < wo.filter_liveSearch ) ||
    +				// let return & backspace continue on, but ignore arrows & non-valid characters
    +				( event.which !== 13 && event.which !== 8 && ( event.which < 32 || (event.which >= 37 && event.which <= 40) ) ) ) ) {
    +				return;
     			}
     			// change event = no delay; last true flag tells getFilters to skip newest timed input
    -			ts.filter.searching( table, event.type !== 'change', true );
    +			ts.filter.searching( table, true, true );
     		})
    -		.bind('keypress.' + c.namespace + 'filter', function(event){
    -			if (event.which === 13) {
    +		.bind('search change keypress '.split(' ').join(c.namespace + 'filter '), function(event){
    +			// triggered change event won't fire a search unless the return key was pressed
    +			if (event.which === 13 || event.type === 'search') {
     				event.preventDefault();
    -				$(this).blur();
    +				// init search with no delay
    +				ts.filter.searching( table, false, true );
     			}
     		});
    -		c.$table.bind('filterReset', function(){
    -			$el.val('');
    -		});
    +	},
    +	searching: function(table, filter, skipFirst) {
    +		var wo = table.config.widgetOptions;
    +		clearTimeout(wo.searchTimer);
    +		if (typeof filter === 'undefined' || filter === true) {
    +			// delay filtering
    +			wo.searchTimer = setTimeout(function() {
    +				ts.filter.checkFilters(table, filter, skipFirst );
    +			}, wo.filter_liveSearch ? wo.filter_searchDelay : 10);
    +		} else {
    +			// skip delay
    +			ts.filter.checkFilters(table, filter, skipFirst);
    +		}
     	},
     	checkFilters: function(table, filter, skipFirst) {
     		var c = table.config,
    @@ -1221,19 +1242,6 @@ ts.filter = {
     				ts.filter.buildSelect(table, columnIndex, updating, $header.hasClass(wo.filter_onlyAvail));
     			}
     		}
    -	},
    -	searching: function(table, filter, skipFirst) {
    -		if (typeof filter === 'undefined' || filter === true) {
    -			var wo = table.config.widgetOptions;
    -			// delay filtering
    -			clearTimeout(wo.searchTimer);
    -			wo.searchTimer = setTimeout(function() {
    -				ts.filter.checkFilters(table, filter, skipFirst );
    -			}, wo.filter_liveSearch ? wo.filter_searchDelay : 10);
    -		} else {
    -			// skip delay
    -			ts.filter.checkFilters(table, filter, skipFirst);
    -		}
     	}
     };
     
    
    Removed options
    Removed options