trying to understand custom row filters
trying to understand custom row filters
I'm looking at the custom row filter example on the /development/filtering page and I have a question. (This is the filter function that filters between a min and max value if they exist).
1. Once this function is pushed onto $.fn.dataTableExt.afnFiltering does it run for every dataTable on the page, automatically, whenever the table is re-drawn?
2. If so, what if I have 3 datatables on the page and it is not appropriate to filter them all on a particular hard coded column?
3. What if I do not want a filter to run when the table is re-drawn but only when I call it? Is there a way to set a filter and call it later, and only on a particular dataTable and a particular column?
1. Once this function is pushed onto $.fn.dataTableExt.afnFiltering does it run for every dataTable on the page, automatically, whenever the table is re-drawn?
2. If so, what if I have 3 datatables on the page and it is not appropriate to filter them all on a particular hard coded column?
3. What if I do not want a filter to run when the table is re-drawn but only when I call it? Is there a way to set a filter and call it later, and only on a particular dataTable and a particular column?
This discussion has been closed.
Replies
It runs once for every row, every time a filter is required for the table.
> 2. If so, what if I have 3 datatables on the page and it is not appropriate to filter them all on a particular hard coded column?
I'm sorry to say that you are seeing a limitation of DataTables here.. The custom filters are global to all tables, rather than local to just one. This is very much something that needs to be addressed in future versions and something I plan to get started on development for as soon as I can.
Until then, what you need to do is check if the table being operated on is the one that you want to apply the filter to. oSettings.nTable is the table node - so if that is the table you want to apply your custom filter to, do the odic needed, otherwise just return true.
> 3. What if I do not want a filter to run when the table is re-drawn but only when I call it?
It will only be run when DataTables needs to do a filtering operation. Paging does not require a refuter, but sorting does (simply due to how the core currently works - again this will likely change in future versions).
Allan