fully custom filtering
fully custom filtering
![cosborn](https://secure.gravatar.com/avatar/86fa99c3c60f5637567410f1e621e4eb/?default=https%3A%2F%2Fvanillicon.com%2F86fa99c3c60f5637567410f1e621e4eb_200.png&rating=g&size=120)
I want to implement fully-custom filtering, but as far as I can tell the only custom filtering options are hamstrung in strange ways:
- I can implicitly change the behavior of per-column filtering by modifying the value that standard filtering sees (ofnSearch), but standard filtering logic still applies to the resulting string
- I can add a fully custom row-based filter (afnFiltering), but it has serious flaws: it's global, so it won't work easily for multi-table pages, and it's in addition to the standard filtering, so if I want to replace the standard filtering I need to disable and replace the entire input element.
What I really want to do is provide my own mapping from search input text to filtering function. That is, I convert the search string to a function which returns true or false when applied to each row, just like the afnFiltering functions but NOT global and INSTEAD of the standard filtering.
I'd be happy to implement this as a plugin, but from reading the code I can't find any suitable extension points. I think what I want is a way to intercept _fnFilterCreateSearch and perhaps also to disabuse _fnFilter of the assumption that longer search strings are more restrictive.
Are there any pointers you can give me?
Thanks!
- I can implicitly change the behavior of per-column filtering by modifying the value that standard filtering sees (ofnSearch), but standard filtering logic still applies to the resulting string
- I can add a fully custom row-based filter (afnFiltering), but it has serious flaws: it's global, so it won't work easily for multi-table pages, and it's in addition to the standard filtering, so if I want to replace the standard filtering I need to disable and replace the entire input element.
What I really want to do is provide my own mapping from search input text to filtering function. That is, I convert the search string to a function which returns true or false when applied to each row, just like the afnFiltering functions but NOT global and INSTEAD of the standard filtering.
I'd be happy to implement this as a plugin, but from reading the code I can't find any suitable extension points. I think what I want is a way to intercept _fnFilterCreateSearch and perhaps also to disabuse _fnFilter of the assumption that longer search strings are more restrictive.
Are there any pointers you can give me?
Thanks!
This discussion has been closed.
Replies
Having said that, custom filtering can currently be done using custom row filters ( http://datatables.net/development/filtering ), and not making use of the built in filtering. Its not quite as efficient (since DataTables can't optimise external code!), but you can use that to do some fairly advanced filtering. However, as you say, its global, so not suitable for all situations.
Bottom line, I'm afraid DataTables isn't quite as flexible in this regard as I'd like it to be - at the moment you'd need to hack around on the core.
Allan
- in the filter input's change handler, generate a custom row filter function and add it to the $.fn.dataTableExt.afnFiltering array, then run filtering by calling fnFilter('').
- in the table's fnDrawCallback, remove the custom row filter function from the afnFiltering array so it doesn't affect future filter options or other tables on the same page
I'll revisit this when the 1.11 enhancements are available, but until then it appears to get the job done.
it's ok. what i found easy was to simply reset all custom filters to their default values before going off to the server to retrieve data again and it works as expected.