Creating custom search on jquery datatables
Creating custom search on jquery datatables
horaccie
Posts: 2Questions: 1Answers: 0
I need help with customizing jquery datatables search. I need to make main search to work for individual columns. In fact I have to implement this logic (https://datatables.net/examples/api/multi_filter.html) in my main search input, so it have search logic like these individual footer inputs.
I have this code right now but its still not working as expected. Please help...
var table = $('#editable-usage').DataTable();
table.columns().every(function() {
var that = this;
$('#editable-usage_filter input').on('keyup change', function() {
if (that.search() == this.value) {
that.search(this.value).draw();
}
});
});
This discussion has been closed.
Answers
I'm afraid I don't quite understand what you are looking for. The code you have there will apply the same search string to every column. Is that what you want? The same value would need to be in every column for anything to show up.
Allan
In fact I need to make search to work from left to right, each letter for all columns. For example:
if I type letter "a" show me only names that starts with that letter(or something from other column that starts with letter "a")
if there is Michal and Alan in column, and if I type "al" , just show me "Alan" not "Michal". So it needs to go from left to right for each word in all columns.
You'd need to use a regex for that.
\b
is the boundary condition, so you could use something liketable.search( '\b'+value', true, false );
.See also
search()
for the details docs.Allan