【问题标题】:How to implement a smart search box to query data from database?如何实现智能搜索框从数据库中查询数据?
【发布时间】:2015-04-10 13:27:43
【问题描述】:
  • 我想实现 搜索框,它将:

    查询我的数据库中的inventories表中的所有库存。

  • 想要显示搜索输入框,并且列出我的任何项目作为开始。

  • 我遇到了一个不错的插件调用DataTable。我用过。我喜欢它。
  • 我想继续使用这个插件,然后稍微调整一下以满足我的需要。

这是我所拥有的:

这是我想要的:

我在Here找到了这个

如何隐藏任何数据作为开始?

【问题讨论】:

  • DataTables 是一个表格数据插件,它可以用来在你的数据库上执行服务器端搜索(所以表格最初可能是空的,甚至是隐藏的,但是你需要链接它到搜索字段,以便将搜索值复制到 DataTables 过滤器,但这可能不是您真正想要做的)但我认为您的问题太宽泛了。
  • 我喜欢你的建议,你能提供更多关于如何link it to a search field 如你所说的细节。事实上,这正是我想要做的。我希望你不介意回答。
  • 如果您使用 jQuery,您可以将搜索字段值复制到 DataTables 过滤器值并触发搜索。可能有比这更好的方法,但最好的办法是阅读 DataTables 文档。

标签: php jquery html mysql css


【解决方案1】:

首先,隐藏默认搜索框:

.dataTables_filter {
   display: none;
}

其次,在 HTML 的某处创建自己的搜索框:

<input type="text" id="searchbox">

三、在搜索框中输入时搜索/过滤的脚本

$("#searchbox").keyup(function() {
   dataTable.fnFilter(this.value);
});    

工作演示 -> http://jsfiddle.net/TbrtF/

【讨论】:

    【解决方案2】:
    You have to get the data from the server side in the form of a JSON object. once   you get the data you can use this simple to populate the searched data in list   format. You have complete control on which information you want to show.
    
      Refer to this [link][1]
    
    
      [1]: http://jsfiddle.net/yogesh_2022/56wjeu7y/1/
    

    【讨论】:

      猜你喜欢
      • 2010-09-18
      • 2021-03-10
      • 1970-01-01
      • 2013-02-09
      • 2011-03-09
      • 2017-04-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多