Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
15
rated 0 times [  20] [ 5]  / answers: 1 / hits: 18224  / 10 Years ago, wed, january 28, 2015, 12:00:00

I am using jquery datatables to make my table searchable. I have a dropdown that filters a gender column:



$(#genderDrop).on(change, function(e) {
var gender = $(this).val();

formTable.column(2).search(gender).draw();
});


this works fine, but now I want to be able to remove the filter when the user selects all from the dropdown. Here is my attempt:



$(#genderDrop).on(change, function(e) {
var gender = $(this).val();
if (gender != all) {
formTable.column(2).search(gender).draw();
} else {
formTable.column(2).search().draw();
}
});


Instead of removing the filter this just searches for an empty string, but I can't work out how to change this so it removes the filter. I also tried:



formTable.column(2).search(*).draw();


and  



formTable.column(2).search().draw();


but without any success.


More From » jquery

 Answers
14

You can use the option All from gender select with empty value:



<option value=>All</option>


them your code will work:



$(#genderDrop).on(change, function(e) {
var gender = $(this).val();

formTable.column(2).search(gender).draw();
});


Using DataTables example as base: http://jsfiddle.net/PauloSegundo/g15xakh5/


[#68062] Sunday, January 25, 2015, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
aiyannam

Total Points: 642
Total Questions: 96
Total Answers: 102

Location: Equatorial Guinea
Member since Sun, Feb 14, 2021
3 Years ago
;