Is it possible to apply a certain filter to only one datatable? I have the following filter function that I am applying on document ready, I don't know if this is proper procedure, but as a side effect all dataTables will be affected by the filter. I would Like to affect only the $('#productTable'), but this selector appears to not have the desired effect.
//Filter Function in Stock
//$('#productTable').
$.fn.dataTableExt.afnFiltering.push(function(oSettings, aData, iDataIndex) {
var checked = $('#instock').is(':checked');
var qntStock = 1;
var stockCol = 3;
if (!checked) {
return true;
}
if (checked && aData[stockCol] > qntStock) {
return true;
}
return false;
});
Is it possible to apply a filter only to a particular table? How do I accomplish this?
EDIT:
dataTable initialization:
var oTable = $('#productTable').dataTable({
"aoColumnDefs": [{
"sClass": "my_class",
"aTargets": [4]
}],
"bAutoWidth": false,
"iDisplayLength": 100,
"fnDrawCallback": function() {
$("td.my_class").editable(function(value, settings)
{
return(value);
},
{
indicator : 'Save...',
tooltip : 'Click to Edit...'
}
);
}
});
You could create an array of tables to have the filter - then in your filter check if the current table is present in that array ... something like :
The following link will help in applying filter to data table. http://live.datatables.net/oyinin/3/edit#javascript,html
I have used it like this:
you can do something like this: add a parameter to the configuration:
and then, verify if your filter is active:
It turns out filtering is global and indeed you have to filter the table element... it's quite disappointing.
Haven't tried, but how about something like this ?
the idea came from this thread : 2 datatables & 2 filters on the same page
You can also try out my yadcf plugin for datatable , here its showcase url, its has 9 different types of filters + additional API functions that can help you load table pre filtered or add single filter for filtering multiple table and many other cool stuff..
This is what we do:
Basically store the existing filters in a TEMP variable and then revert it after we are done. Weird design descion on Allan's part to implement it like this. Ugly hack, but it works.