How do I limit a filter plugin on a page with multiple datatable controls?

How do I limit a filter plugin on a page with multiple datatable controls?

dhrobbinsdhrobbins Posts: 6Questions: 0Answers: 0
edited February 2010 in Plug-ins
Currently I'm working the filtering based on a range example and use afnFiltering array for my plug-in. I would like to limit the execution of the filter to just one of the tables, and not place a switch in plug-in that tests for the table I want to filter.

Maybe I should have tested better. It appears that the datatables are filtered separately. This brings me to the question of how do I apply a separate filter per table via the afnFiltering array. Am I misunderstanding the concept that $.fn.dataTableExt.afnFiltering.push() sets a global plug-in?

I have been reading the forums and have found that on $.fn.dataTableExt.iApiIndex is used to distinguish between tables created from the statement: $('.datatable').datatable(); My code uses a separate initialization for each table, and it appears that my plug-in is only assigned to the first data table. Am I correct in in assuming that they only way to assign different plug-ins to different tables is to use $('.datatable').datatable(); then the index of the table?


  • allanallan Posts: 55,114Questions: 1Answers: 8,654 Site admin
    Hi dhrobbins,

    Interesting question. You are quite right that afnFiltering is really applied globally at the moment (and it should in fact be assigned to all tables on a page). This a limitation of the current plug-in API - so it would be necessary to check to see if you are currently 'in' the table that you want to filter. I plan to make the pug-in structure much stronger in DataTables 2.0 (whenever that happens!), and so at the moment I'm sorry to say there is no easy way around this. Indeed, the ways to implement it could add significant complication, so it's going to require some thought!

    If this detection isn't working for you, please you could post an example. It would be interesting to see this in action.

This discussion has been closed.