4

I need to search on the DataTable and return true if a particular "string" has been found across the table. As starter I have this. But it keeps on returning true and the value is always "found" even if there is nothing like it in the table. What am I doing wrong ?

if(table.columns().search("ddd"))
  {
    alert("found");
    return true;
  }
  else
  {
    alert("not found");
    return false;
  }
Smit Patel
  • 2,992
  • 1
  • 26
  • 44
OneLazy
  • 499
  • 4
  • 16
  • `table.colums().search("textbox.text"); ` but there in `columns()` you must have to parse selected column index. – Soni Vimalkumar Feb 09 '17 at 05:21
  • https://datatables.net/reference/api/column().search() here you found solution in this link. `Build a search for each column with a select-filter class.:` cheack this – Soni Vimalkumar Feb 09 '17 at 05:24
  • Possible duplicate of [search exact match and highlight jquery datatable regex](http://stackoverflow.com/questions/29783136/search-exact-match-and-highlight-jquery-datatable-regex/) – guest271314 Feb 09 '17 at 05:26
  • [documentation](https://datatables.net/reference/api/columns().search()) search is done to filter out table column in datatables `column.search( this.value ).draw();` and in yours case `table.columns().search("ddd")` it will always be true – Deep 3015 Feb 09 '17 at 05:57

1 Answers1

0

In Datatable documentation, you can see this Link. According to this link, search result will be string if it is available on search and if there is no match it will return empty string.

So, in either way your condition will be true and you always get found alert. Also, your input has search ability, with keyup function. Why do you need it ?

Yigit Yuksel
  • 1,060
  • 2
  • 18
  • 35