Hi,
thanks for your question, and sorry for the trouble.
I can see what you are trying to do, but unfortunately, I’m not aware of a possibility to change this search behavior 🙁 As I’m not the developer of the external DataTables JS library that TablePress uses for this, and as I therefore don’t know all the details about it, I can only suggest that you check the documentation at http://www.datatables.net for more information or ask in the DataTables forums there.
Regards,
Tobias
Hi Tobias,
thank you.
After one day in the other forum here is my idea:
Enable regex filter and search with ^
^ <- Starts with the first letter.
My question? How 😀 ?
Hi,
ah, indeed, nice idea.
I haven’t tested it, but this code should achieve this:
add_filter( 'tablepress_datatables_command', 'tablepress_filter_on_enter', 10, 5 );
function tablepress_filter_on_enter( $command, $html_id, $parameters, $table_id, $js_options ) {
if ( ! in_array( $table_id, array( '1', '3' ) ) )
return $command;
$name = 'DT_' + str_replace( '-', '_', $html_id );
$command = <<<JS
var {$name} = $('#{$html_id}').dataTable({$parameters});
$('#{$html_id}_filter input').unbind().bind('keyup', function(e) {
{$name}.fnFilter( '^' + this.value, null, true );
});
JS;
return $command;
}
Just paste that into a new small plugin or into your theme’s “functions.php” file. Also, the line
if ( ! in_array( $table_id, array( '1', '3' ) ) )
needs to be adjusted, so that the array contains all the table IDs for which you want this search behavior.
Regards,
Tobias
Thank you for your hard work & help.
Hmmm – but the code failed.
I insert both in my theme function but now the search field is not there.
http://www.bundesverband-brennholz.de/?page_id=3591
Hi,
ah, my bad. There’s a small typo in the code above…
Please change
$name = 'DT_' + str_replace( '-', '_', $html_id );
to
$name = 'DT_' . str_replace( '-', '_', $html_id );
Regards,
Tobias
Hi,
🙂
Good to hear that this helps!
We might need one more modification though. It looks like the search field now gets the ^ in it as well. Please try this:
Replace
{$name}.fnFilter( '^' + this.value, null, true );
with
var search_term = this.value;
{$name}.fnFilter( '^' + search_term, null, true );
$(this).val( search_term );
Regards,
Tobias
Works !!! Thank you so much!!!!
A good idea and your knowledge.
Hi,
great. Looks like that worked 🙂
Best wishes,
Tobias
P.S.: In case you haven’t, please rate TablePress here in the plugin directory. Thanks!