【问题标题】:How can I search in a specific column using the jQuery DataTables plugin?如何使用 jQuery DataTables 插件在特定列中搜索?
【发布时间】:2014-09-07 13:57:12
【问题描述】:

我使用jquery dataTable plugin 显示包含(用户名、日期和电子邮件)的表格。 我想禁用对用户名和电子邮件列的过滤/搜索,并仅启用对日期的搜索。当我点击搜索字段时,我会打开一个日历来选择我们要查找的日期。

基本上,我只想使用这个插件来过滤日期。这个可以吗?

-编辑--

我阅读了文档:dateRange 但它对我不起作用我添加了

('.dataTable').dataTable()
    .columnFilter({
        sPlaceHolder: "head:before",
        aoColumns: [null, { type: "date-range" }, null]
    });

我复制了标题,但无法获取日期字段或任何其他字段来搜索数据。

【问题讨论】:

  • 阅读有关配置列和列选项的文档
  • 感谢您阅读。但我没有得到任何结果。我添加了` $('#example').dataTable() .columnFilter({ sPlaceHolder: "head:before", aoColumns: [ null, { type: "date-range" }, null ] });` 但我可以'看不到日期范围过滤器。
  • 你误解了过滤器在列配置中的作用

标签: jquery arrays jquery-plugins datatables


【解决方案1】:

您可以使用column().search()获取特定值的搜索,例如:

  var table = $('#example-table').DataTable();

  $('#search-input').on('change', function(){

    table
    .column(4)
    .search(this.value)
    .draw();

  });

Working Demo

Refrences

【讨论】:

  • 搜索:2009/01/12 在此演示中不起作用,我想搜索这样的日期范围:jquery-datatables-column-filter.googlecode.com/svn/trunk/…。您能帮帮我吗?
  • 请再次check the demo 这是标记而不是Javascript代码的问题,关于您提到的插件,它适用于DataTables 1.09 我认为它与当前版本(1.11)不兼容为什么您尝试时它不起作用,但您仍然可以通过扩展 $.fn.dataTable.ext.search 函数来做出相同的行为,请检查此 example
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-03-24
  • 1970-01-01
  • 2021-10-31
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多