I'm currently developing a web app with a datatable functionality. I have implemented both a global search bar and individual search bars in each column, similar to this example: https://datatables.net/examples/api/multi_filter.html. Now, my goal is to enable searching by the first letter only in each individual column.
$(document).ready(function() {
var table=$('#example').DataTable( {
responsive: true
} );
$('.dataTables_filter input').on( 'keyup', function (e) {
var regExSearch = '\\b' + this.value;
table.search(regExSearch, true, false).draw();
});
} );
However, using the above approach does not yield the desired outcome for me. I have structured my individual searches as follows:
table.columns(':gt(1)').every( function () {
var that = this;
$( 'input', this.footer() ).on( 'keyup change clear', function () {
if ( that.search() !== this.value ) {
that
.search(this.value )
.draw();
}
} );
} );
I attempted to adapt the global search logic by adding .search('\\b' +this.value )
, but my searches return no results. It's possible that I am overlooking something, could someone provide guidance on how to achieve this?