Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Default dataTable search box text

The code below filters the table upon initialization to match "Search for..." This is not useful to me.

$(document).ready(function(){
  $('.table').dataTable({
    "oSearch": {"sSearch": "Search for..."});
});

What I want is for "Search for..." to appear in the search box itself without initializing the search parameters on page load. When the user places focus on the search box, the string disappears and the user can start typing. Any ideas?

like image 449
jamesfzhang Avatar asked Feb 17 '26 03:02

jamesfzhang


1 Answers

You can give the searchbox an value like "Search for" and use jquery to clear it with onfocus, or blur, which you prefer. To clear the value when somebody "focusses " on the box.

like image 80
Jonathan Römer Avatar answered Feb 21 '26 13:02

Jonathan Römer



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!