From 8f4dd31b4c5ecf0e2041e50271d37a39de588545 Mon Sep 17 00:00:00 2001 From: CiTRO33 Date: Wed, 9 May 2018 20:22:41 +0200 Subject: [PATCH 01/10] Update widget-filter.js --- js/widgets/widget-filter.js | 73 +++++++++++++++++++++++++++---------- 1 file changed, 53 insertions(+), 20 deletions(-) diff --git a/js/widgets/widget-filter.js b/js/widgets/widget-filter.js index 99a851504..eb525eea7 100644 --- a/js/widgets/widget-filter.js +++ b/js/widgets/widget-filter.js @@ -59,7 +59,8 @@ filter_selectSourceSeparator : '|', // filter_selectSource array text left of the separator is added to the option value, right into the option text filter_serversideFiltering : false, // if true, must perform server-side filtering b/c client-side filtering is disabled, but the ui and events will still be used. filter_startsWith : false, // if true, filter start from the beginning of the cell contents - filter_useParsedData : false // filter all data using parsed content + filter_useParsedData : false, // filter all data using parsed content + filter_searchTrigger : ['search', 'blur' , 13 ] // array of events / Keys who trigger the search false = search, blur event and enterkey }, format: function( table, c, wo ) { if ( !c.$table.hasClass( 'hasFilters' ) ) { @@ -869,25 +870,57 @@ eventType = event.type, liveSearch = typeof wo.filter_liveSearch === 'boolean' ? wo.filter_liveSearch : - ts.getColumnData( table, wo.filter_liveSearch, column ); - if ( table.config.widgetOptions.filter_initialized && - // immediate search if user presses enter - ( event.which === tskeyCodes.enter || - // immediate search if a "search" or "blur" is triggered on the input - ( eventType === 'search' || eventType === 'blur' ) || - // change & input events must be ignored if liveSearch !== true - ( eventType === 'change' || eventType === 'input' ) && - // prevent search if liveSearch is a number - ( liveSearch === true || liveSearch !== true && event.target.nodeName !== 'INPUT' ) && - // don't allow 'change' or 'input' event to process if the input value - // is the same - fixes #685 - this.value !== c.lastSearch[column] - ) - ) { - event.preventDefault(); - // init search with no delay - $( this ).attr( 'data-lastSearchTime', new Date().getTime() ); - tsf.searching( table, eventType !== 'keypress', true, column ); + ts.getColumnData( table, wo.filter_liveSearch, column ), + searchTrigger = wo.filter_searchTrigger, + triggerSearch = false; + + if (table.config.widgetOptions.filter_initialized) { + + // Only if liveSearch is disabled + if(liveSearch === false){ + for (var t in searchTrigger){ + // events + var stType = typeof t; + if(stType === "string" && eventType === t){ + triggerSearch = true; + break; + } else if(stType === "number" && event.which === t){ + // keycodes + triggerSearch = true; + break; + } else if(stType === "object" ){ + if(t.hasOwnProperty('keyCode') && event.which === t.keyCode){ + // same keycode + triggerSearch = true; + // check modifier + if(t.hasOwnProperty('ctrl') && t.ctrl !== event.ctrl ){ + triggerSearch = false; + } + if(t.hasOwnProperty('alt') && t.alt !== event.alt ){ + triggerSearch = false; + } + if(t.hasOwnProperty('shift') && t.shift !== event.shift ){ + triggerSearch = false; + } + } + } + } + // change & input events must be ignored if liveSearch !== true + } else if ( eventType === 'change' || eventType === 'input' ) && + // prevent search if liveSearch is a number + ( liveSearch === true || liveSearch !== true && event.target.nodeName !== 'INPUT' ) && + // don't allow 'change' or 'input' event to process if the input value + // is the same - fixes #685 + this.value !== c.lastSearch[column]){ + triggerSearch = true; + } + + if(triggerSearch) { + event.preventDefault(); + // init search with no delay + $( this ).attr( 'data-lastSearchTime', new Date().getTime() ); + tsf.searching( table, eventType !== 'keypress', true, column ); + } } }); }, From 77cb81526f9faed4e427c728ca986c9c959eced3 Mon Sep 17 00:00:00 2001 From: CiTRO33 Date: Wed, 9 May 2018 20:30:03 +0200 Subject: [PATCH 02/10] Update widget-filter.js --- js/widgets/widget-filter.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/widgets/widget-filter.js b/js/widgets/widget-filter.js index eb525eea7..b01173f1f 100644 --- a/js/widgets/widget-filter.js +++ b/js/widgets/widget-filter.js @@ -906,7 +906,7 @@ } } // change & input events must be ignored if liveSearch !== true - } else if ( eventType === 'change' || eventType === 'input' ) && + } else if ( ( eventType === 'change' || eventType === 'input' ) && // prevent search if liveSearch is a number ( liveSearch === true || liveSearch !== true && event.target.nodeName !== 'INPUT' ) && // don't allow 'change' or 'input' event to process if the input value From 37db582131ed951dd97b62e209eac793ee3acbc6 Mon Sep 17 00:00:00 2001 From: CiTRO33 Date: Wed, 9 May 2018 21:40:24 +0200 Subject: [PATCH 03/10] New Option filter_searchTrigger New Option filter_searchTrigger Possible Values: bool = default, Number = keycode , String = events ( search, blur ), Objects = { keyCode : Number, alt: bool, ctrl: bool, shift: bool} Examples: filter_searchTrigger : false -> same als ['search', 'blur', 13] filter_searchTrigger : [13] -> Enter filter_searchTrigger :[ 13, 9] -> Enter and tab - key filter_searchTrigger : ['blur'] filter_searchTrigger : [{keyCode: 13, ctrl:true] -> ctrl + Enter --- js/widgets/widget-filter.js | 102 ++++++++++++++++++++++++++++++------ 1 file changed, 87 insertions(+), 15 deletions(-) diff --git a/js/widgets/widget-filter.js b/js/widgets/widget-filter.js index b01173f1f..34050f91c 100644 --- a/js/widgets/widget-filter.js +++ b/js/widgets/widget-filter.js @@ -60,7 +60,7 @@ filter_serversideFiltering : false, // if true, must perform server-side filtering b/c client-side filtering is disabled, but the ui and events will still be used. filter_startsWith : false, // if true, filter start from the beginning of the cell contents filter_useParsedData : false, // filter all data using parsed content - filter_searchTrigger : ['search', 'blur' , 13 ] // array of events / Keys who trigger the search false = search, blur event and enterkey + filter_searchTrigger : false // array of events / Keys who trigger the search false = search, blur event and enterkey }, format: function( table, c, wo ) { if ( !c.$table.hasClass( 'hasFilters' ) ) { @@ -459,6 +459,24 @@ c.$table.triggerHandler( 'filterFomatterUpdate' ); }, 100); } + + if(event.type === 'search'){ + var triggerSearch = false; + var searchTrigger = wo.filter_searchTrigger === false ? ['search', 'blur' , 13 ] : wo.filter_searchTrigger; + // skip search if not included + for (var t in searchTrigger){ + // events + var stType = typeof searchTrigger[t]; + if(stType === "string" && eventType === searchTrigger[t]){ + triggerSearch = true; + break; + } + } + if(!triggerSearch){ + return; + } + } + // pass true ( skipFirst ) to prevent the tablesorter.setFilters function from skipping the first // input ensures all inputs are updated when a search is triggered on the table // $( 'table' ).trigger( 'search', [...] ); @@ -837,7 +855,8 @@ wo = table.config.widgetOptions; // make sure "wo" isn't cached var column = parseInt( $( this ).attr( 'data-column' ), 10 ), liveSearch = typeof wo.filter_liveSearch === 'boolean' ? wo.filter_liveSearch : - ts.getColumnData( table, wo.filter_liveSearch, column ); + ts.getColumnData( table, wo.filter_liveSearch, column ), + searchTrigger = wo.filter_searchTrigger ; if ( typeof liveSearch === 'undefined' ) { liveSearch = wo.filter_liveSearch.fallback || false; } @@ -852,13 +871,67 @@ ( typeof liveSearch === 'number' && this.value.length < liveSearch ) || // let return & backspace continue on, but ignore arrows & non-valid characters ( event.which !== tskeyCodes.enter && event.which !== tskeyCodes.backSpace && - ( event.which < tskeyCodes.space || ( event.which >= tskeyCodes.left && event.which <= tskeyCodes.down ) ) ) ) ) { + ( event.which < tskeyCodes.space || ( event.which >= tskeyCodes.left && event.which <= tskeyCodes.down ) ) + ) && searchTrigger === false ) ) { return; // live search } else if ( liveSearch === false ) { - if ( this.value !== '' && event.which !== tskeyCodes.enter ) { - return; + + if (searchTrigger === false) { + if ( this.value !== '' && event.which !== tskeyCodes.enter ) { + return; + } + } else { + var skipSearch = true; + // only allow keyCode + for ( var t in searchTrigger ){ + // events + var stType = typeof searchTrigger[t]; + if(stType === "number" && event.which === searchTrigger[t]){ + // keycodes + skipSearch = false; + break; + } else if(stType === "object" ){ + if(searchTrigger[t].hasOwnProperty('keyCode') && event.which === searchTrigger[t].keyCode){ + // check modifier + var ctrl = true, alt = true, shift = true; + if(searchTrigger[t].hasOwnProperty('ctrl')){ + if(searchTrigger[t].ctrl === event.ctrlKey ){ + ctrl = true; + }else{ + ctrl = false; + } + } + if(searchTrigger[t].hasOwnProperty('alt')){ + if(searchTrigger[t].alt === event.altKey ){ + alt = true; + }else{ + alt = false; + } + } + if(searchTrigger[t].hasOwnProperty('shift')){ + if( searchTrigger[t].shift === event.shiftKey ){ + shift = true; + } + else{ + shift = false; + } + } + + if(ctrl && alt && shift){ + skipSearch = false; + } + } + } + } + if(skipSearch){ + return; + } + + } + + } // change event = no delay; last true flag tells getFilters to skip newest timed input tsf.searching( table, true, true, column ); @@ -871,35 +944,34 @@ liveSearch = typeof wo.filter_liveSearch === 'boolean' ? wo.filter_liveSearch : ts.getColumnData( table, wo.filter_liveSearch, column ), - searchTrigger = wo.filter_searchTrigger, + searchTrigger = wo.filter_searchTrigger === false ? ['search', 'blur' , 13 ] : wo.filter_searchTrigger, triggerSearch = false; if (table.config.widgetOptions.filter_initialized) { - // Only if liveSearch is disabled if(liveSearch === false){ for (var t in searchTrigger){ // events - var stType = typeof t; - if(stType === "string" && eventType === t){ + var stType = typeof searchTrigger[t]; + if(stType === "string" && eventType === searchTrigger[t]){ triggerSearch = true; break; - } else if(stType === "number" && event.which === t){ + } else if(stType === "number" && event.which === searchTrigger[t] ){ // keycodes triggerSearch = true; break; - } else if(stType === "object" ){ - if(t.hasOwnProperty('keyCode') && event.which === t.keyCode){ + } else if( stType === "object" ){ + if( searchTrigger[t].hasOwnProperty('keyCode') && event.which === searchTrigger[t].keyCode ){ // same keycode triggerSearch = true; // check modifier - if(t.hasOwnProperty('ctrl') && t.ctrl !== event.ctrl ){ + if( searchTrigger[t].hasOwnProperty('ctrl') && searchTrigger[t].ctrl !== event.ctrlKey ){ triggerSearch = false; } - if(t.hasOwnProperty('alt') && t.alt !== event.alt ){ + if( searchTrigger[t].hasOwnProperty('alt') && searchTrigger[t].alt !== event.altKey ){ triggerSearch = false; } - if(t.hasOwnProperty('shift') && t.shift !== event.shift ){ + if( searchTrigger[t].hasOwnProperty('shift') && searchTrigger[t].shift !== event.shiftKey ){ triggerSearch = false; } } From d28dd21673bc508c625e69b0878e7b221b619f15 Mon Sep 17 00:00:00 2001 From: CiTRO33 Date: Wed, 9 May 2018 21:43:58 +0200 Subject: [PATCH 04/10] Update widget-filter.js --- js/widgets/widget-filter.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/widgets/widget-filter.js b/js/widgets/widget-filter.js index 34050f91c..a6299b8f4 100644 --- a/js/widgets/widget-filter.js +++ b/js/widgets/widget-filter.js @@ -467,7 +467,7 @@ for (var t in searchTrigger){ // events var stType = typeof searchTrigger[t]; - if(stType === "string" && eventType === searchTrigger[t]){ + if(stType === "string" && event.type === searchTrigger[t]){ triggerSearch = true; break; } From abaff4bc7ee51697c3a919b34a346fb3059fe297 Mon Sep 17 00:00:00 2001 From: CiTRO33 Date: Thu, 10 May 2018 17:21:22 +0200 Subject: [PATCH 05/10] filter_searchTrigger Code format, allow search event always, allow names in object mode like [ { keyCode:'tab', ctrl:false}], possible values see tskeyCodes --- js/widgets/widget-filter.js | 148 ++++++++++++++++-------------------- 1 file changed, 67 insertions(+), 81 deletions(-) diff --git a/js/widgets/widget-filter.js b/js/widgets/widget-filter.js index a6299b8f4..21bb5b9d0 100644 --- a/js/widgets/widget-filter.js +++ b/js/widgets/widget-filter.js @@ -18,6 +18,7 @@ $.extend( tskeyCodes, { backSpace : 8, + tab : 9, escape : 27, space : 32, left : 37, @@ -459,24 +460,24 @@ c.$table.triggerHandler( 'filterFomatterUpdate' ); }, 100); } - - if(event.type === 'search'){ - var triggerSearch = false; - var searchTrigger = wo.filter_searchTrigger === false ? ['search', 'blur' , 13 ] : wo.filter_searchTrigger; + // check if search is included because enter trigger a search event + /* if ( event.type === 'search' ) { + var triggerSearch = false, + searchTrigger = wo.filter_searchTrigger === false ? [ 'blur', tskeyCodes.enter ] : wo.filter_searchTrigger; // skip search if not included - for (var t in searchTrigger){ - // events - var stType = typeof searchTrigger[t]; - if(stType === "string" && event.type === searchTrigger[t]){ + for ( var t in searchTrigger ) { + var stType = typeof searchTrigger[t], + trigger = searchTrigger[t]; + // only events required + if ( stType === "string" && event.type === trigger ) { triggerSearch = true; break; } } - if(!triggerSearch){ + if( !triggerSearch ) { return; } - } - + } */ // pass true ( skipFirst ) to prevent the tablesorter.setFilters function from skipping the first // input ensures all inputs are updated when a search is triggered on the table // $( 'table' ).trigger( 'search', [...] ); @@ -856,7 +857,7 @@ var column = parseInt( $( this ).attr( 'data-column' ), 10 ), liveSearch = typeof wo.filter_liveSearch === 'boolean' ? wo.filter_liveSearch : ts.getColumnData( table, wo.filter_liveSearch, column ), - searchTrigger = wo.filter_searchTrigger ; + searchTrigger = wo.filter_searchTrigger; if ( typeof liveSearch === 'undefined' ) { liveSearch = wo.filter_liveSearch.fallback || false; } @@ -871,67 +872,44 @@ ( typeof liveSearch === 'number' && this.value.length < liveSearch ) || // let return & backspace continue on, but ignore arrows & non-valid characters ( event.which !== tskeyCodes.enter && event.which !== tskeyCodes.backSpace && - ( event.which < tskeyCodes.space || ( event.which >= tskeyCodes.left && event.which <= tskeyCodes.down ) ) - ) && searchTrigger === false ) ) { + ( event.which < tskeyCodes.space || ( event.which >= tskeyCodes.left && event.which <= tskeyCodes.down ) ) ) && + searchTrigger === false ) ) { return; // live search } else if ( liveSearch === false ) { - - if (searchTrigger === false) { + if ( searchTrigger === false ) { if ( this.value !== '' && event.which !== tskeyCodes.enter ) { return; } } else { var skipSearch = true; - // only allow keyCode - for ( var t in searchTrigger ){ - // events - var stType = typeof searchTrigger[t]; - if(stType === "number" && event.which === searchTrigger[t]){ - // keycodes + // on keyup event only keycodes needed to be checked + for ( var t in searchTrigger ) { + var stType = typeof searchTrigger[t], + trigger = searchTrigger[t]; + // single keycode + if ( stType === 'number' && event.which === trigger ) { skipSearch = false; break; - } else if(stType === "object" ){ - if(searchTrigger[t].hasOwnProperty('keyCode') && event.which === searchTrigger[t].keyCode){ + } else if ( stType === 'object' ) { + // keyCode property must be in the object + if ( typeof trigger.keyCode === 'number' && event.which === trigger.keyCode || + tskeyCodes[ trigger.keyCode ] !== undefined && + event.which === tskeyCodes[ trigger.keyCode ] ) { // check modifier - var ctrl = true, alt = true, shift = true; - if(searchTrigger[t].hasOwnProperty('ctrl')){ - if(searchTrigger[t].ctrl === event.ctrlKey ){ - ctrl = true; - }else{ - ctrl = false; - } - } - if(searchTrigger[t].hasOwnProperty('alt')){ - if(searchTrigger[t].alt === event.altKey ){ - alt = true; - }else{ - alt = false; - } - } - if(searchTrigger[t].hasOwnProperty('shift')){ - if( searchTrigger[t].shift === event.shiftKey ){ - shift = true; - } - else{ - shift = false; - } - } - - if(ctrl && alt && shift){ + var ctrl = typeof trigger.ctrl === 'undefined' ? true : trigger.ctrl === event.ctrlKey, + alt = typeof trigger.alt === 'undefined' ? true : trigger.alt === event.altKey, + shift = typeof trigger.shift === 'undefined' ? true : trigger.shift === event.shiftKey; + if( ctrl && alt && shift ){ skipSearch = false; } } } } - if(skipSearch){ + if( skipSearch ) { return; } - - } - - } // change event = no delay; last true flag tells getFilters to skip newest timed input tsf.searching( table, true, true, column ); @@ -944,35 +922,43 @@ liveSearch = typeof wo.filter_liveSearch === 'boolean' ? wo.filter_liveSearch : ts.getColumnData( table, wo.filter_liveSearch, column ), - searchTrigger = wo.filter_searchTrigger === false ? ['search', 'blur' , 13 ] : wo.filter_searchTrigger, + searchTrigger = wo.filter_searchTrigger === false ? ['blur' , tskeyCodes.enter ] : wo.filter_searchTrigger, triggerSearch = false; - if (table.config.widgetOptions.filter_initialized) { + if ( table.config.widgetOptions.filter_initialized ) { // Only if liveSearch is disabled - if(liveSearch === false){ - for (var t in searchTrigger){ - // events - var stType = typeof searchTrigger[t]; - if(stType === "string" && eventType === searchTrigger[t]){ - triggerSearch = true; - break; - } else if(stType === "number" && event.which === searchTrigger[t] ){ - // keycodes - triggerSearch = true; - break; - } else if( stType === "object" ){ - if( searchTrigger[t].hasOwnProperty('keyCode') && event.which === searchTrigger[t].keyCode ){ - // same keycode + if ( liveSearch === false ) { + if ( eventType === 'search' ) { + triggerSearch = true; + } else { + for ( var t in searchTrigger ) { + var stType = typeof searchTrigger[t], + trigger = searchTrigger[t]; + // events + if ( stType === 'string' && eventType === trigger) { triggerSearch = true; - // check modifier - if( searchTrigger[t].hasOwnProperty('ctrl') && searchTrigger[t].ctrl !== event.ctrlKey ){ - triggerSearch = false; - } - if( searchTrigger[t].hasOwnProperty('alt') && searchTrigger[t].alt !== event.altKey ){ - triggerSearch = false; - } - if( searchTrigger[t].hasOwnProperty('shift') && searchTrigger[t].shift !== event.shiftKey ){ - triggerSearch = false; + break; + } else if ( stType === 'number' && event.which === trigger ) { + // keys + triggerSearch = true; + break; + } else if ( stType === 'object' ){ + // key combinations + if ( typeof trigger.keyCode === 'number' && event.which === trigger.keyCode || + tskeyCodes[ trigger.keyCode ] !== undefined && + event.which === tskeyCodes[ trigger.keyCode ] ) { + // same keycode + triggerSearch = true; + // check modifier + if ( typeof trigger.ctrl !== 'undefined' && trigger.ctrl !== event.ctrlKey ) { + triggerSearch = false; + } + if ( typeof trigger.alt !== 'undefined' && trigger.alt !== event.altKey ) { + triggerSearch = false; + } + if ( typeof trigger.shift !== 'undefined' && trigger.shift !== event.shiftKey ) { + triggerSearch = false; + } } } } @@ -984,10 +970,10 @@ // don't allow 'change' or 'input' event to process if the input value // is the same - fixes #685 this.value !== c.lastSearch[column]){ - triggerSearch = true; + triggerSearch = true; } - if(triggerSearch) { + if ( triggerSearch ) { event.preventDefault(); // init search with no delay $( this ).attr( 'data-lastSearchTime', new Date().getTime() ); From 3ccc4e28f20d0c7e6bc6d178f89c77dc9861c1a9 Mon Sep 17 00:00:00 2001 From: CiTRO33 Date: Mon, 2 Dec 2019 17:13:25 +0100 Subject: [PATCH 06/10] added Demo/Docs/Format --- .../example-widget-filter-search-trigger.html | 392 ++++++++++++++++++ docs/example-widget-filter.html | 8 +- docs/index.html | 39 +- js/widgets/widget-filter.js | 52 +-- 4 files changed, 463 insertions(+), 28 deletions(-) create mode 100644 docs/example-widget-filter-search-trigger.html diff --git a/docs/example-widget-filter-search-trigger.html b/docs/example-widget-filter-search-trigger.html new file mode 100644 index 000000000..0de096350 --- /dev/null +++ b/docs/example-widget-filter-search-trigger.html @@ -0,0 +1,392 @@ + + + + + + jQuery tablesorter 2.0 - searchTrigger Filter Widget Functions + + + + + + + + + + + + + + + + + + + + + + + + +
+ +

+
+

Demo

+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
First NameLast NameCityAgeTotalDiscountDate
AaronJohnson SrAtlanta35$5.9522%Jun 26, 2004 7:22 AM
AaronJohnsonYuma12$2.995%Aug 21, 2009 12:21 PM
ClarkHenry JrTampa51$42.2918%Oct 13, 2000 1:15 PM
DenniHenryNew York28$9.9920%Jul 6, 2006 8:14 AM
JohnHoodBoston33$19.9925%Dec 10, 2002 5:14 AM
ClarkKent SrLos Angeles18$15.8944%Jan 12, 2003 11:14 AM
PeterKent EsqSeattle45$153.1944%Jan 18, 2021 9:12 AM
PeterJohnsMilwaukee13$5.294%Jan 8, 2012 5:11 PM
AaronEvanChicago24$14.1914%Jan 14, 2004 11:23 AM
BruceEvansUpland22$13.1911%Jan 18, 2007 9:12 AM
ClarkMcMastersPheonix18$55.2015%Feb 12, 2010 7:23 PM
DennisMastersIndianapolis65$123.0032%Jan 20, 2001 1:12 PM
JohnHoodFort Worth25$22.0917%Jun 11, 2011 10:55 AM
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
First NameLast NameCityAgeTotalDiscountDate
AaronJohnson SrAtlanta35$5.9522%Jun 26, 2004 7:22 AM
AaronJohnsonYuma12$2.995%Aug 21, 2009 12:21 PM
ClarkHenry JrTampa51$42.2918%Oct 13, 2000 1:15 PM
DenniHenryNew York28$9.9920%Jul 6, 2006 8:14 AM
JohnHoodBoston33$19.9925%Dec 10, 2002 5:14 AM
ClarkKent SrLos Angeles18$15.8944%Jan 12, 2003 11:14 AM
PeterKent EsqSeattle45$153.1944%Jan 18, 2021 9:12 AM
PeterJohnsMilwaukee13$5.294%Jan 8, 2012 5:11 PM
AaronEvanChicago24$14.1914%Jan 14, 2004 11:23 AM
BruceEvansUpland22$13.1911%Jan 18, 2007 9:12 AM
ClarkMcMastersPheonix18$55.2015%Feb 12, 2010 7:23 PM
DennisMastersIndianapolis65$123.0032%Jan 20, 2001 1:12 PM
JohnHoodFort Worth25$22.0917%Jun 11, 2011 10:55 AM
+
+ +

Javascript

+
+

+		
+ +

HTML

+
+

+		
+ +
+
+ Next up: Filter Widget ›› +
+
+ + + \ No newline at end of file diff --git a/docs/example-widget-filter.html b/docs/example-widget-filter.html index 48a1984f4..280fc1365 100644 --- a/docs/example-widget-filter.html +++ b/docs/example-widget-filter.html @@ -603,7 +603,11 @@

NOTE This table includes very basic infor true Allow searching through already filtered rows in special circumstances; will speed up searching in large tables if true. - + + filter_searchTrigger + false + If String,Number,Object, search is only triggered by the given types, see here + filter_selectSource null @@ -621,7 +625,7 @@

NOTE This table includes very basic infor false If true, filter will be done server-side. The client-side filtering will be disabled, but the ui and events will still be used. - + filter_startsWith false diff --git a/docs/index.html b/docs/index.html index c9e103ec7..c09c41a25 100644 --- a/docs/index.html +++ b/docs/index.html @@ -3511,7 +3511,44 @@

Comparison example

1 2 - + + + Boolean,String,Number,Object + false + + Filter widget: If set, only passed Keys/Events are used to trigger the search. + filter_liveSearch must be set to false +
+
+ Use the filter_searchTrigger option as follows: +
$(function() {
+  $("table").tablesorter({
+    widgets: ["filter"],
+    widgetOptions : {
+      filter_searchTrigger : [
+		  {
+			  keycode : $.tablesorter.keyCodes.enter, ctrl : true, alt : false, shift : false
+		  },
+		  $.tablesorter.keyCodes.tab,
+		  "blur"
+	  ]
+    }
+  });
+});
+
    +
  • Possible values to use as parameter +
      +
    • Boolean false Default same as ['blur', 13]
    • +
    • String search change keypress input blur. Events
    • +
    • Number Keycodes 13 = Enter, 9 = Tab, etc. see $.tablesorter.keyCodes for internal constants
    • +
    • Object {keycode: Number, ctrl : boolean, alt : boolean, shift : boolean}
    • +
    +
  • +
+
+ + Example + String diff --git a/js/widgets/widget-filter.js b/js/widgets/widget-filter.js index 676a0c59d..4d1827e62 100644 --- a/js/widgets/widget-filter.js +++ b/js/widgets/widget-filter.js @@ -56,12 +56,12 @@ filter_saveFilters : false, // Use the $.tablesorter.storage utility to save the most recent filters filter_searchDelay : 300, // typing delay in milliseconds before starting a search filter_searchFiltered: true, // allow searching through already filtered rows in special circumstances; will speed up searching in large tables if true + filter_searchTrigger : false, // array of events / Keys who trigger the search false = search, blur event and enterkey filter_selectSource : null, // include a function to return an array of values to be added to the column filter select filter_selectSourceSeparator : '|', // filter_selectSource array text left of the separator is added to the option value, right into the option text filter_serversideFiltering : false, // if true, must perform server-side filtering b/c client-side filtering is disabled, but the ui and events will still be used. filter_startsWith : false, // if true, filter start from the beginning of the cell contents - filter_useParsedData : false, // filter all data using parsed content - filter_searchTrigger : false // array of events / Keys who trigger the search false = search, blur event and enterkey + filter_useParsedData : false // filter all data using parsed content }, format: function( table, c, wo ) { if ( !c.$table.hasClass( 'hasFilters' ) ) { @@ -900,13 +900,13 @@ var ctrl = typeof trigger.ctrl === 'undefined' ? true : trigger.ctrl === event.ctrlKey, alt = typeof trigger.alt === 'undefined' ? true : trigger.alt === event.altKey, shift = typeof trigger.shift === 'undefined' ? true : trigger.shift === event.shiftKey; - if( ctrl && alt && shift ){ + if ( ctrl && alt && shift ) { skipSearch = false; } } } } - if( skipSearch ) { + if ( skipSearch ) { return; } } @@ -942,7 +942,7 @@ // keys triggerSearch = true; break; - } else if ( stType === 'object' ){ + } else if ( stType === 'object' ) { // key combinations if ( typeof trigger.keyCode === 'number' && event.which === trigger.keyCode || tskeyCodes[ trigger.keyCode ] !== undefined && @@ -969,7 +969,7 @@ ( liveSearch === true || liveSearch !== true && event.target.nodeName !== 'INPUT' ) && // don't allow 'change' or 'input' event to process if the input value // is the same - fixes #685 - this.value !== c.lastSearch[column]){ + this.value !== c.lastSearch[column]) { triggerSearch = true; } @@ -980,24 +980,26 @@ tsf.searching( table, eventType !== 'keypress', true, column ); } ts.getColumnData( table, wo.filter_liveSearch, column ); - if ( table.config.widgetOptions.filter_initialized && - // immediate search if user presses enter - ( event.which === tskeyCodes.enter || - // immediate search if a "search" or "blur" is triggered on the input - ( eventType === 'search' || eventType === 'blur' ) || - // change & input events must be ignored if liveSearch !== true - ( eventType === 'change' || eventType === 'input' ) && - // prevent search if liveSearch is a number - ( liveSearch === true || liveSearch !== true && event.target.nodeName !== 'INPUT' ) && - // don't allow 'change' or 'input' event to process if the input value - // is the same - fixes #685 - this.value !== c.lastSearch[column] - ) - ) { - event.preventDefault(); - // init search with no delay - $( this ).attr( 'data-lastSearchTime', new Date().getTime() ); - tsf.searching( table, eventType !== 'keypress' || event.which === tskeyCodes.enter, true, column ); + if ( table.config.widgetOptions.filter_initialized && + // immediate search if user presses enter + ( event.which === tskeyCodes.enter || + // immediate search if a "search" or "blur" is triggered on the input + ( eventType === 'search' || eventType === 'blur' ) || + // change & input events must be ignored if liveSearch !== true + ( eventType === 'change' || eventType === 'input' ) && + // prevent search if liveSearch is a number + ( liveSearch === true || liveSearch !== true && event.target.nodeName !== 'INPUT' ) && + // don't allow 'change' or 'input' event to process if the input value + // is the same - fixes #685 + this.value !== c.lastSearch[column] + ) + ) { + event.preventDefault(); + // init search with no delay + $( this ).attr( 'data-lastSearchTime', new Date().getTime() ); + tsf.searching( table, eventType !== 'keypress' || event.which === tskeyCodes.enter, true, column ); + + } } }); }, @@ -2065,4 +2067,4 @@ return valid.length !== 0; }; -})( jQuery ); +})( jQuery ); \ No newline at end of file From 7d58c8de18425e7708e74e36bcb5d455a76b8e15 Mon Sep 17 00:00:00 2001 From: CiTRO33 Date: Mon, 2 Dec 2019 20:30:23 +0100 Subject: [PATCH 07/10] search event is always triggered --- docs/index.html | 2 +- js/widgets/widget-filter.js | 89 ++++++++++++++----------------------- 2 files changed, 35 insertions(+), 56 deletions(-) diff --git a/docs/index.html b/docs/index.html index c09c41a25..0e3086a17 100644 --- a/docs/index.html +++ b/docs/index.html @@ -3539,7 +3539,7 @@

Comparison example

  • Possible values to use as parameter
    • Boolean false Default same as ['blur', 13]
    • -
    • String search change keypress input blur. Events
    • +
    • String search change keypress input blur Events
    • Number Keycodes 13 = Enter, 9 = Tab, etc. see $.tablesorter.keyCodes for internal constants
    • Object {keycode: Number, ctrl : boolean, alt : boolean, shift : boolean}
    diff --git a/js/widgets/widget-filter.js b/js/widgets/widget-filter.js index 4d1827e62..48eb4a82f 100644 --- a/js/widgets/widget-filter.js +++ b/js/widgets/widget-filter.js @@ -461,7 +461,7 @@ }, 100); } // check if search is included because enter trigger a search event - /* if ( event.type === 'search' ) { + if ( event.type === 'search' ) { var triggerSearch = false, searchTrigger = wo.filter_searchTrigger === false ? [ 'blur', tskeyCodes.enter ] : wo.filter_searchTrigger; // skip search if not included @@ -469,15 +469,15 @@ var stType = typeof searchTrigger[t], trigger = searchTrigger[t]; // only events required - if ( stType === "string" && event.type === trigger ) { + if ( stType === 'string' && event.type === trigger ) { triggerSearch = true; break; } } - if( !triggerSearch ) { + if ( !triggerSearch ) { return; } - } */ + } // pass true ( skipFirst ) to prevent the tablesorter.setFilters function from skipping the first // input ensures all inputs are updated when a search is triggered on the table // $( 'table' ).trigger( 'search', [...] ); @@ -928,41 +928,41 @@ if ( table.config.widgetOptions.filter_initialized ) { // Only if liveSearch is disabled if ( liveSearch === false ) { - if ( eventType === 'search' ) { - triggerSearch = true; - } else { - for ( var t in searchTrigger ) { - var stType = typeof searchTrigger[t], - trigger = searchTrigger[t]; - // events - if ( stType === 'string' && eventType === trigger) { - triggerSearch = true; - break; - } else if ( stType === 'number' && event.which === trigger ) { - // keys + // if ( eventType === 'search' ) { + // triggerSearch = true; + // } else { + for ( var t in searchTrigger ) { + var stType = typeof searchTrigger[t], + trigger = searchTrigger[t]; + // events + if ( stType === 'string' && eventType === trigger) { + triggerSearch = true; + break; + } else if ( stType === 'number' && event.which === trigger ) { + // keys + triggerSearch = true; + break; + } else if ( stType === 'object' ) { + // key combinations + if ( typeof trigger.keyCode === 'number' && event.which === trigger.keyCode || + tskeyCodes[ trigger.keyCode ] !== undefined && + event.which === tskeyCodes[ trigger.keyCode ] ) { + // same keycode triggerSearch = true; - break; - } else if ( stType === 'object' ) { - // key combinations - if ( typeof trigger.keyCode === 'number' && event.which === trigger.keyCode || - tskeyCodes[ trigger.keyCode ] !== undefined && - event.which === tskeyCodes[ trigger.keyCode ] ) { - // same keycode - triggerSearch = true; - // check modifier - if ( typeof trigger.ctrl !== 'undefined' && trigger.ctrl !== event.ctrlKey ) { - triggerSearch = false; - } - if ( typeof trigger.alt !== 'undefined' && trigger.alt !== event.altKey ) { - triggerSearch = false; - } - if ( typeof trigger.shift !== 'undefined' && trigger.shift !== event.shiftKey ) { - triggerSearch = false; - } + // check modifier + if ( typeof trigger.ctrl !== 'undefined' && trigger.ctrl !== event.ctrlKey ) { + triggerSearch = false; + } + if ( typeof trigger.alt !== 'undefined' && trigger.alt !== event.altKey ) { + triggerSearch = false; + } + if ( typeof trigger.shift !== 'undefined' && trigger.shift !== event.shiftKey ) { + triggerSearch = false; } } } } + //} // change & input events must be ignored if liveSearch !== true } else if ( ( eventType === 'change' || eventType === 'input' ) && // prevent search if liveSearch is a number @@ -974,31 +974,10 @@ } if ( triggerSearch ) { - event.preventDefault(); - // init search with no delay - $( this ).attr( 'data-lastSearchTime', new Date().getTime() ); - tsf.searching( table, eventType !== 'keypress', true, column ); - } - ts.getColumnData( table, wo.filter_liveSearch, column ); - if ( table.config.widgetOptions.filter_initialized && - // immediate search if user presses enter - ( event.which === tskeyCodes.enter || - // immediate search if a "search" or "blur" is triggered on the input - ( eventType === 'search' || eventType === 'blur' ) || - // change & input events must be ignored if liveSearch !== true - ( eventType === 'change' || eventType === 'input' ) && - // prevent search if liveSearch is a number - ( liveSearch === true || liveSearch !== true && event.target.nodeName !== 'INPUT' ) && - // don't allow 'change' or 'input' event to process if the input value - // is the same - fixes #685 - this.value !== c.lastSearch[column] - ) - ) { event.preventDefault(); // init search with no delay $( this ).attr( 'data-lastSearchTime', new Date().getTime() ); tsf.searching( table, eventType !== 'keypress' || event.which === tskeyCodes.enter, true, column ); - } } }); From 5a98bf94f2f31ce9fdbb9ee1c633ff801d19db82 Mon Sep 17 00:00:00 2001 From: CiTRO33 Date: Thu, 19 Dec 2019 22:38:39 +0100 Subject: [PATCH 08/10] include search event als default to use select2 --- docs/index.html | 2 +- js/widgets/widget-filter.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/index.html b/docs/index.html index 0e3086a17..c89af6090 100644 --- a/docs/index.html +++ b/docs/index.html @@ -3538,7 +3538,7 @@

    Comparison example

    • Possible values to use as parameter
        -
      • Boolean false Default same as ['blur', 13]
      • +
      • Boolean false Default same as ['blur', 'search', 13]
      • String search change keypress input blur Events
      • Number Keycodes 13 = Enter, 9 = Tab, etc. see $.tablesorter.keyCodes for internal constants
      • Object {keycode: Number, ctrl : boolean, alt : boolean, shift : boolean}
      • diff --git a/js/widgets/widget-filter.js b/js/widgets/widget-filter.js index 48eb4a82f..5bf654e66 100644 --- a/js/widgets/widget-filter.js +++ b/js/widgets/widget-filter.js @@ -922,7 +922,7 @@ liveSearch = typeof wo.filter_liveSearch === 'boolean' ? wo.filter_liveSearch : ts.getColumnData( table, wo.filter_liveSearch, column ), - searchTrigger = wo.filter_searchTrigger === false ? ['blur' , tskeyCodes.enter ] : wo.filter_searchTrigger, + searchTrigger = wo.filter_searchTrigger === false ? ['blur' , 'search', tskeyCodes.enter ] : wo.filter_searchTrigger, triggerSearch = false; if ( table.config.widgetOptions.filter_initialized ) { From d88d010ce086dcec91030c30228ea62d572a81b6 Mon Sep 17 00:00:00 2001 From: CiTRO33 Date: Thu, 19 Dec 2019 22:39:22 +0100 Subject: [PATCH 09/10] Revert "include search event als default to use select2" This reverts commit 5a98bf94f2f31ce9fdbb9ee1c633ff801d19db82. --- docs/index.html | 2 +- js/widgets/widget-filter.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/index.html b/docs/index.html index c89af6090..0e3086a17 100644 --- a/docs/index.html +++ b/docs/index.html @@ -3538,7 +3538,7 @@

        Comparison example

        • Possible values to use as parameter
            -
          • Boolean false Default same as ['blur', 'search', 13]
          • +
          • Boolean false Default same as ['blur', 13]
          • String search change keypress input blur Events
          • Number Keycodes 13 = Enter, 9 = Tab, etc. see $.tablesorter.keyCodes for internal constants
          • Object {keycode: Number, ctrl : boolean, alt : boolean, shift : boolean}
          • diff --git a/js/widgets/widget-filter.js b/js/widgets/widget-filter.js index 5bf654e66..48eb4a82f 100644 --- a/js/widgets/widget-filter.js +++ b/js/widgets/widget-filter.js @@ -922,7 +922,7 @@ liveSearch = typeof wo.filter_liveSearch === 'boolean' ? wo.filter_liveSearch : ts.getColumnData( table, wo.filter_liveSearch, column ), - searchTrigger = wo.filter_searchTrigger === false ? ['blur' , 'search', tskeyCodes.enter ] : wo.filter_searchTrigger, + searchTrigger = wo.filter_searchTrigger === false ? ['blur' , tskeyCodes.enter ] : wo.filter_searchTrigger, triggerSearch = false; if ( table.config.widgetOptions.filter_initialized ) { From 4ec8789b7387f73d492654dbd3394129665feaef Mon Sep 17 00:00:00 2001 From: CiTRO33 Date: Thu, 19 Dec 2019 22:41:30 +0100 Subject: [PATCH 10/10] include search event as default value for select2 --- docs/index.html | 2 +- js/widgets/widget-filter.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/index.html b/docs/index.html index 0e3086a17..c89af6090 100644 --- a/docs/index.html +++ b/docs/index.html @@ -3538,7 +3538,7 @@

            Comparison example

            • Possible values to use as parameter
                -
              • Boolean false Default same as ['blur', 13]
              • +
              • Boolean false Default same as ['blur', 'search', 13]
              • String search change keypress input blur Events
              • Number Keycodes 13 = Enter, 9 = Tab, etc. see $.tablesorter.keyCodes for internal constants
              • Object {keycode: Number, ctrl : boolean, alt : boolean, shift : boolean}
              • diff --git a/js/widgets/widget-filter.js b/js/widgets/widget-filter.js index 48eb4a82f..5bf654e66 100644 --- a/js/widgets/widget-filter.js +++ b/js/widgets/widget-filter.js @@ -922,7 +922,7 @@ liveSearch = typeof wo.filter_liveSearch === 'boolean' ? wo.filter_liveSearch : ts.getColumnData( table, wo.filter_liveSearch, column ), - searchTrigger = wo.filter_searchTrigger === false ? ['blur' , tskeyCodes.enter ] : wo.filter_searchTrigger, + searchTrigger = wo.filter_searchTrigger === false ? ['blur' , 'search', tskeyCodes.enter ] : wo.filter_searchTrigger, triggerSearch = false; if ( table.config.widgetOptions.filter_initialized ) {