Datatables Search Onclick button
Datatables Search Onclick button
I am trying to add an onclick event button "Filter Results" next to "Clear Filters" button. The behavior should be -
once the user selects the dropdown values, the results should be presented only when the user clicks on the button. How can I do this? Thanks.
I tried the following code
$('#myInput').on( 'keyup', function () {
table.search( this.value ).draw();
} );
Test case - https://live.datatables.net/qoxoweca/3/edit
This question has an accepted answers - jump to answer
Answers
You will need to remove this part of the code:
Since its a button you will want to use
click
instead ofkeyup
.In the event handler you will need to get the values of each input then perform a
column().search()
for the appropriate column, for example:Kevin
Thanks, Kevin. It worked. However it removed the cascading of the columns. Now it retains all the column values instead of updating the column based upon the selection (see my original example). Is there a way to retain cascading as well?
This is my updated test case based upon your response.
https://live.datatables.net/qoxoweca/5/edit
Once you click
Filter Results
thebuildSelect()
function will be called, updating the select lists, due totable.draw();
. The select lists won't be updated until you perform the search and draw functions.Maybe we should go back to your previous test case and remove the
.draw()
from teh column search, for example:And call
buildSelect()
using thesearch
event, for example:Update the click event handler to call
draw()
, for example:Updated test case:
https://live.datatables.net/wutosiyi/1/edit
Kevin
This works great. Thankyou so much!