How to exclude a specific row (top row) from filtering

How to exclude a specific row (top row) from filtering

caa5042caa5042 Posts: 2Questions: 0Answers: 0

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

  • kthorngrenkthorngren Posts: 21,330Questions: 26Answers: 4,951

    According to the Search Plugin docs the dataIndex parameter is the index of the row. Maybe add this to your search plugin:

    if (dataIndex === 0) {
      return true;
    }
    

    Kevin

  • caa5042caa5042 Posts: 2Questions: 0Answers: 0

    I can't believe I missed that parameter. thanks.

This discussion has been closed.