Функциональность должна отличаться от приведенного здесь примера, поскольку мне нужно, чтобы это была только одна панель поиска/термин для всей таблицы.
Я пробовал использовать встроенные функции datatables .search() с регулярным выражением для поиска указанных столбцов отдельно от остальной части таблицы, но смог получить только один из них: выполнить поиск по всей таблице без совпадения подстрок или выполнить поиск только по указанным столбцам и игнорировать остальную часть таблицы, что не является желаемым результатом.
Моя последняя попытка оставила меня с этим:
Код: Выделить всё
//columns with the class "disable-substring-search" will be searched without substring matching
$('.data-table-search').on('keyup', function () {
var tableId = $(this).data("for");
var table = tables[tableId];
var val = $(this).val();
var noSubStringIndecies = [];
//get indecies of columns with substring matching disabled
table.columns('.disable-substring-search').flatten().each(function (colIndex) {
noSubStringIndecies.push(colIndex);
});
table.rows().flatten().each(function (rowIndex) {
var row = table.row(rowIndex);
var showRow = false;
row.cells().flatten().each(function (cellIndex) {
var cell = row.cells(cellIndex);
//if substring matching disabled for this column, do non fuzzy search
if (noSubStringIndecies.includes(cell.index().columnVisible)) {
//just perform the search with a ^ regex
//set showRow true if search returns a match
}
//do normal fuzzy search
else {
//set showRow true if search returns match
}
});
if (!showRow) {
//hide the row if there is no matching data
}
});
//redraw the table
});
Подробнее здесь: https://stackoverflow.com/questions/798 ... ble-search
Мобильная версия