search event is always triggered

This commit is contained in:
CiTRO33 2019-12-02 20:30:23 +01:00
parent 3ccc4e28f2
commit 7d58c8de18
2 changed files with 35 additions and 56 deletions

View File

@ -3539,7 +3539,7 @@ $('table').trigger('search', false);</pre></div>
<li>Possible values to use as parameter <li>Possible values to use as parameter
<ul> <ul>
<li>Boolean <code>false</code> Default same as <code>['blur', 13]</code></li> <li>Boolean <code>false</code> Default same as <code>['blur', 13]</code></li>
<li>String <code>search change keypress input blur</code>. Events</li> <li>String <code>search change keypress input blur</code> Events</li>
<li>Number Keycodes 13 = Enter, 9 = Tab, etc. see <code>$.tablesorter.keyCodes</code> for internal constants</li> <li>Number Keycodes 13 = Enter, 9 = Tab, etc. see <code>$.tablesorter.keyCodes</code> for internal constants</li>
<li>Object <code>{keycode: Number, ctrl : boolean, alt : boolean, shift : boolean}</code></li> <li>Object <code>{keycode: Number, ctrl : boolean, alt : boolean, shift : boolean}</code></li>
</ul> </ul>

View File

@ -461,7 +461,7 @@
}, 100); }, 100);
} }
// check if search is included because enter trigger a search event // check if search is included because enter trigger a search event
/* if ( event.type === 'search' ) { if ( event.type === 'search' ) {
var triggerSearch = false, var triggerSearch = false,
searchTrigger = wo.filter_searchTrigger === false ? [ 'blur', tskeyCodes.enter ] : wo.filter_searchTrigger; searchTrigger = wo.filter_searchTrigger === false ? [ 'blur', tskeyCodes.enter ] : wo.filter_searchTrigger;
// skip search if not included // skip search if not included
@ -469,15 +469,15 @@
var stType = typeof searchTrigger[t], var stType = typeof searchTrigger[t],
trigger = searchTrigger[t]; trigger = searchTrigger[t];
// only events required // only events required
if ( stType === "string" && event.type === trigger ) { if ( stType === 'string' && event.type === trigger ) {
triggerSearch = true; triggerSearch = true;
break; break;
} }
} }
if( !triggerSearch ) { if ( !triggerSearch ) {
return; return;
} }
} */ }
// pass true ( skipFirst ) to prevent the tablesorter.setFilters function from skipping the first // 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 // input ensures all inputs are updated when a search is triggered on the table
// $( 'table' ).trigger( 'search', [...] ); // $( 'table' ).trigger( 'search', [...] );
@ -928,41 +928,41 @@
if ( table.config.widgetOptions.filter_initialized ) { if ( table.config.widgetOptions.filter_initialized ) {
// Only if liveSearch is disabled // Only if liveSearch is disabled
if ( liveSearch === false ) { if ( liveSearch === false ) {
if ( eventType === 'search' ) { // if ( eventType === 'search' ) {
triggerSearch = true; // triggerSearch = true;
} else { // } else {
for ( var t in searchTrigger ) { for ( var t in searchTrigger ) {
var stType = typeof searchTrigger[t], var stType = typeof searchTrigger[t],
trigger = searchTrigger[t]; trigger = searchTrigger[t];
// events // events
if ( stType === 'string' && eventType === trigger) { 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; triggerSearch = true;
break; // check modifier
} else if ( stType === 'number' && event.which === trigger ) { if ( typeof trigger.ctrl !== 'undefined' && trigger.ctrl !== event.ctrlKey ) {
// keys triggerSearch = false;
triggerSearch = true; }
break; if ( typeof trigger.alt !== 'undefined' && trigger.alt !== event.altKey ) {
} else if ( stType === 'object' ) { triggerSearch = false;
// key combinations }
if ( typeof trigger.keyCode === 'number' && event.which === trigger.keyCode || if ( typeof trigger.shift !== 'undefined' && trigger.shift !== event.shiftKey ) {
tskeyCodes[ trigger.keyCode ] !== undefined && triggerSearch = false;
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;
}
} }
} }
} }
} }
//}
// change & input events must be ignored if liveSearch !== true // 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 // prevent search if liveSearch is a number
@ -974,31 +974,10 @@
} }
if ( triggerSearch ) { 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(); event.preventDefault();
// init search with no delay // init search with no delay
$( this ).attr( 'data-lastSearchTime', new Date().getTime() ); $( this ).attr( 'data-lastSearchTime', new Date().getTime() );
tsf.searching( table, eventType !== 'keypress' || event.which === tskeyCodes.enter, true, column ); tsf.searching( table, eventType !== 'keypress' || event.which === tskeyCodes.enter, true, column );
} }
} }
}); });