Multiple data tables override global filtering

Multiple data tables override global filtering

eggmatterseggmatters Posts: 3Questions: 1Answers: 0
edited September 2013 in General
Sorry, can't provide a link or a fiddle. Just wanted to point out what appears to be a design flaw with datatables "afnFiltering" extension. We have an application which implements two datatables. They are rendered in seperate views but, the application is built in Backbone so all of the JS is loaded at once.
What happens is, regardless of which table your looking at, when the filter is engaged, it calls both filters for both tables sequentially, overwriting eachother and thus returning no data. The filter evaluates a page element and attempts to match. The workaround is in both filters, check for the existence of the attribute we're interested in and evaluate the current row. The implementation is as follows:

[code]
$.fn.dataTableExt.afnFiltering.push(function(oSettings, aData, iDataIndex) {
category = aData[2];

if (typeof($("#category-filter").val()) !== 'undefined' ) { //this element may not exist on the view that's being rendered
if($("#category-filter").val() == ""){
return true;
}else if($("#category-filter").val() == category){
return true;
}
return false;
} else if (typeof($("#category-select").val()) !== 'undefined') { //this element may not exist on the view that's being rendered
if($("#category-select").val() == ""){
return true;
}else if($("#category-select").val() == category){
return true;
}
return false;
}
return false;
});
[/code]

This has to be written in for both tables. One uses the element "category-filter" and the other uses "category-select." I would call this a bug as this method is executed in two places even though we're only rendering one table. I realized the documentation statest that, [quote] The standard DataTables distribution presents a global filter for rapid searching of all information in the table [/quote] but I didn't assume it was truly "global" Isn't that something that should be avoided?

Just wanted to point this out. Sorry I can't provide a link or a fiddle, the data is coming from a secure db and the application is firewalled as well. I would have to mock up an entire backbone app to provide a fiddle and well, they're not paying me to do that right now.

Thanks!

Replies

  • eggmatterseggmatters Posts: 3Questions: 1Answers: 0
    Bump on this. One other effect of the "global" filtering is that if you filter on one table and then go to view another, the filtering for the last table still applies.
This discussion has been closed.