Search/Filter question
Search/Filter question
I've built a datatable using server side method. It works just great. I'm struggling with the search filter.
I want the search filter to only allow numbers so I constructed the following:
tableAllBalances = $('#tableMainBilling').DataTable({
dom: 'Bfrtip',
autoWidth: false,
..blah blah blah code
});
..there's what I did:
$('#tableMainBilling_filter input').unbind();
$('#tableMainBilling_filter input').bind('keypress', function (e) {
if ((e.which === 32) || (e.which > 64 && e.which < 91) || (e.which > 96 && e.which < 123))
return false;
tableAllBalances.draw();
});
The filter works fine before I implemented the .unbind, .bind but I really want to make sure that only numbers are accepted as part of the search filter.
The problem is that the table does not refresh to refelect. It works and makes the trip to the database but the draw() does not seem to be working...
Answers
Maybe this from the jQuery unbind() docs:
Sounds like maybe you want to use 'off()' and '.on()' instead.
Kevin
Hi .. we are using jquery 2.2.3..
Have you validated the the JSON response is what you expect?
I copied your code (changing the table ID) into this server side example and it seems to work:
http://live.datatables.net/manamaba/1/edit
Can you post a link or test case showing the issue?
Kevin
Here's a sample:
Maybe you can update my example with your code and Datatable versions. Are you using Datatable 1.9 or 1.10?
Have you looked at your browser's dev tools to see the JSON response?
Kevin
Hi Kevin,
Check the json returning does help. It kept bringing back the same dadta. I found out that the search parameter that is passed to the controller is null.
Any idea why?
FIXED! A few things - Kevin's suggestion also helped along with:
Key: search(this.val()).draw() helps populate the passed sSearch parameter.
I also had a wrong parameter in an Oracle stored procedure.
Thanks Kevin!