简体   繁体   English

搜索DataTable

[英]Search DataTable

I need to search on the DataTable and return true if a particular "string" has been found across the table. 我需要搜索DataTable ,如果在表中找到特定的“字符串”,则返回true。 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. 但它继续返回true,即使表中没有任何类似的东西,它总是“找到”。 What am I doing wrong ? 我究竟做错了什么 ?

if(table.columns().search("ddd"))
  {
    alert("found");
    return true;
  }
  else
  {
    alert("not found");
    return false;
  }

In Datatable documentation, you can see this Link . 在Datatable文档中,您可以看到此链接 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. 此外,您的输入具有搜索功能,具有keyup功能。 Why do you need it ? 你为什么需要它 ?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM