Multiple Filters
Multiple Filters
Link to test case: https://jsfiddle.net/BeerusDev/phncg5t7/47/
Link to relevant post: https://datatables.net/forums/discussion/comment/67893/#Comment_67893
Hello,
I have three tables, the first two I want to apply individual filters too, in the myTable1 I want the filter to only show Items when this condition is true:
if(bdayBool === "Yes"){
return true;
}
in my second table, I only want to show items when the following condition is true:
if(hireBool === "Yes"){
return true;
}
When I apply the first filter to the first table, it works fine, but when I create a new filter search, to apply a filter to the second table. Nothing shows? So in my test case I have the second filter commented out.
This question has accepted answers - jump to:
Answers
This search plugin is going to run for every table. You are returning true for myTable1. Even though you don't specifically have a return statement for other conditions the value will be the same as false. So for the other tables it will be false - filtering out all the rows. There are lots of ways you can fix this. Here is one:
Kevin
This still only applies to the first table. So I am confused how I am going to have no filter applied to the third table.
I mistakenly put the
return true
on line 11 - inside theif ( settings.sTableId === 'myTable1' ) { .. }
. It should be outside between lines 11 and 12. You need to do the same and move your second if statement after the first if block.Kevin
Fixed that but still cannot get the filter for myTable 2 to work as well -.-.
Anything after the last return true; is unreachable.
https://jsfiddle.net/BeerusDev/phncg5t7/70/
As I said you need to move it outside the
if ( settings.sTableId === 'myTable1' ) { .. }
block. Also for that tablesearchData[4]
doesn't exists, ie,var hireBool = searchData[4];
will be undefined. This is the third column in that table so usesearchData[2]
.https://jsfiddle.net/x4eo7fmc/
Kevin
Oh my goodness, I had it right, I was just assuming the searchdata was pulling from the object not the columns... I just had a brain fart, thanks for the clarification Kevin.
The search plugin docs explain the parameters. The forth has the original data for the row if you need to access data not placed in a table column.
Kevin
Thanks!