How is custom/date range filtering stored and how to disable it on other pages datatables?

How is custom/date range filtering stored and how to disable it on other pages datatables?

nicsoftnicsoft Posts: 37Questions: 0Answers: 0
edited August 2012 in DataTables 1.9
I am using DT on different pages of my site, all are loaded dynamically.

My use-case:

1. I click one menu link for the first page and the DT is loaded. When clicking this link, the table is created for the first time and I call a function which adds some filtering features:

oTable is global.

I'm creating the table like this:

[code]oTable = $('#mytable').dataTable( { /*options*/});[/code]

Then I call this function that adds the filter:

[code]function addSearch(){
$.fn.dataTableExt.afnFiltering.push(
function( oSettings, aData, iDataIndex ) {
/*Code for date range filtering */
.
.
})
}[/code]

Then I add some input fields for date range filtering into div mytable_filter that is rendered by DT (using jQuery prepend).

2. I go to another page. Now the datatable for this page is created:

[code]oTable = $('#myothertable').dataTable( { /*options*/});[/code]

I do not call addSearch because I don't need it for this table and of course I don't add the fileds in the mytable_filter div either.

Here somewhere I get the complaints that the input fields for the dates doesn't exist. Hence, the pushed filter function needs to be around somewhere and is trying to make the initial filtering.

How does this work (i.e. how is it stored and accessed by the second datatable?) and how can I make sure the new table on the second page doesn't care about this filtering? Is there a proper solution or am I doing something wrong?

This is my workaround (which I would like to change to any more proper solution or fix if I'm doing something wrong):

I added this to the beginning of the filter function:

[code]if( oSettings.nTable != document.getElementById( 'mytickettable' )){
return true;
}[/code]

By doing that, the filtering is only performed for 'mytickettable'
This discussion has been closed.