How to exclude a specific row (top row) from filtering
How to exclude a specific row (top row) from filtering
I'm trying to create a custim filter. it works fine except: i want the first row of the table to always be displayed even if it doesn’t meet the search criteria. how do i do this? here’s my code:
jQuery(function($) {
$.fn.dataTable.ext.search.push(
function( settings, data, dataIndex ) {
var searchTerm = $(‘#searchBar’).val();
console.log(searchTerm)
var others = data[13]
var modelVerb = data[0]
if ( others.includes(searchTerm) || modelVerb.includes(searchTerm))
{
return true;
}
return false;
}
)
});
jQuery(function($) {
$(document).ready(function() {
var table = $(‘#tablepress-10a’).DataTable({
dom: ‘l’,
paging: false,
ordering: false,
searching: true
});
// Event listener to the filtering input to redraw on input
$(‘#searchBar’).keyup( function() {
table.draw();
});
});
});
I definitely got this working last year although i don't remember what approach i used.
Replies
According to the Search Plugin docs the
dataIndex
parameter is the index of the row. Maybe add this to your search plugin:Kevin
I can't believe I missed that parameter. thanks.