jquery - 将搜索应用于多个列
问题描述
我正在使用 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
等于用户全名的值。我的问题是,我认为通过指定前两列,它会尝试将过滤器中的名称与用户的名字和姓氏相匹配,但是当我尝试使用该代码时,不会返回任何行。如何根据第一列和第二列都包含至少一部分过滤器的位置将其返回到返回行的位置?
解决方案
推荐阅读
- python - 在/使用对象的属性中递归 {pattern} 替换
- javascript - 如何使用 JavaScript 循环在第一个重复值后返回重复值的空格
- fftw - 真实二维数据上的 FFT
- doctrine-orm - Doctrine Migration Bundle:升级到版本 3 后出现更新错误
- android - 如何将recycleview的变化反映到父活动?
- php - 你如何将文件/图像从服务器传输到客户端电脑
- grails - GORM 批量获取和更新
- nginx - 迁移到 Kubernetes 时的并行请求问题
- ansible - Ansible 从 API 提供 ansible_ssh_pass 值
- laravel - 如何使用 php 或 javascript 将对象转换为数组?