将搜索应用于多列

时间:2018-12-19 20:50:30

标签: jquery datatables

我使用的是DataTables版本1.10.16,目前我已将数据表初始化如下:

// Setup the emails datatable
var auto_responders = $('#auto_responders').DataTable({
  ajax: {
    url: "assets/php/get_auto_responders.php",
    dataSrc: ''
  },
  columns: [
    { data: 'user_first_name', title: 'User Name', createdCell:
  function (td, cellData, rowData, row, col) {
  $(td).text(cellData + ' ' + rowData['user_last_name']);
}
},
    { data: 'user_last_name', visible: false},
    { data: 'customer_first_name', title: 'Customer Name', createdCell:
  function (td, cellData, rowData, row, col) {
  $(td).text(cellData + ' ' + rowData['customer_last_name']);
}
},
    { data: 'customer_last_name', visible: false},
    { data: 'email', title: 'Email', createdCell:
  function (td, cellData, rowData, row, col) {
  $(td).html('<a href="mailto:' + cellData + '">' + cellData + '</a>');
}
},
    { data: 'customer_id', searchable: false, visible: false },
    { data: 'date_entered', title: 'Date Entered' },
    { data: 'title', title: 'Auto-Responder' },
    { data: 'queued_ids', title: 'Upcoming Responders', searchable: false, createdCell:
      function (td, cellData, rowData, row, col) {
        if (!cellData) {
    $(td).html('<span class="text-danger text-center d-block">No Automatic Responders Queued</span>');
  } else {
    $(td).html('<button type="button" class="btn btn-block btn-outline-success queued_auto_responders" data-queued-ids="' + cellData + '" data-toggle="modal" data-target="#modal_queued_responders">View Queued Automatic Responders</button>');
  }
      }
    }
  ]
});

正如您所知道的,我在显示时将前两列(用户的名字和姓氏)和后两列(客户的名字和姓氏)组合在一起,但是我要设置各自的姓氏列可见性为假。

要为网页上的人创建一个下拉过滤器以快速查看特定用户的所有行,我有以下代码:

auto_responders.columns([0, 1]).search(filter).draw();

其中值filter等于用户全名的值。我的问题是,我认为通过指定前两列来尝试将过滤器中的名称与用户的名字和姓氏进行匹配,但是当我尝试使用该代码时,不会返回任何行。如何根据第一列和第二列均包含至少一部分过滤器的位置到达返回行的位置?

1 个答案:

答案 0 :(得分:2)

您可以使用数据表中的搜索API进行自定义搜索过滤

$.fn.dataTable.ext.search

此处示例Custom Filtering

相关问题