Global custom search filter
Global custom search filter
bola2api
Posts: 4Questions: 2Answers: 0
Hi all, I'm trying to create a global app to act as a custom search filter. I've test it on individual input tag and datatable and its working. Could you guys point it to me what when wrong? Or is there any restriction when I'm trying to use this approach?
$('[data-toggle="datatable"]').each(function () {
var tableId = $(this).attr('id');
var table = $('#' + tableId).DataTable({});
var input = $('#' + tableId + 'input');
input.on('keyup', function () {
var value = input.val();
table.search(value).draw();
});
$(input, table.table().container()).on('search.dt', function () {
var value = input.val();
if (value === '') {
table.search('').draw();
}
});
});
This question has an accepted answers - jump to answer
Answers
You haven't said what went wrong?
We're happy to take a look, but as per the forum rules, please link to a test case - a test case that replicates the issue will ensure you'll get a quick and accurate response. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.
Colin
Hi Colin, thanks for replying. Please have a look at this
https://live.datatables.net/lixeboga/1/edit
What I'm trying to achieve is to create a global function for custom search filter. You can try to search in the input tag but nothing is being trigger.
Sorry I'm very new to Javascript language
Is the issue - it isn't matching anything. Your
input
element has an id ofexample1_input
, but the selector is matching that and then picking desendents ofinput
elements, of which there aren't any.Use:
And it will pick the correct element.
Allan
Ohh silly me.
Thanks a lot Allan!
You too Colin!