我有一个表组件,可通过CDA执行SQL查询。
如何基于两个输入字段过滤结果,第一个输入用于第一列的行,第二个输入用于第四列的行?
我在表组件的后执行中使用以下Javascript函数创建了字段:
function f() {
$(document).ready(function () {
// Setup - add a text input to each footer cell
var arrayColumns = ['Application ID', 'Object Type'];
$('#example thead th').each(function () {
var testo = $('#example thead th').eq($(this).index()).html();
var title = $('#example thead th').eq($(this).index()).text();
if (arrayColumns.indexOf(title) > -1) {
$(this).html(testo + '<br><input type="text" placeholder="Search ' + title + '">');
}
});
// DataTable
var table = $('#example').DataTable();
// Apply the search.
table.columns().eq(0).each(function (colIdx) {
$('input', table.column(colIdx).header()).on('keyup change clear', function () {
table
.column(colIdx)
.search(this.value)
.draw();
});
// If you click in the field, it doesn't sort the results in the column in ascending/descending order.
$('input', table.column(colIdx).header()).on('click', function (e) {
e.stopPropagation();
});
});
});
}