Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
127
rated 0 times [  131] [ 4]  / answers: 1 / hits: 23926  / 12 Years ago, thu, july 12, 2012, 12:00:00

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...'
}
);
}
});

More From » jquery

 Answers
76

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 :



// setup an array of the ids of tables that should be allowed
var allowFilter = ['productTable'];

$.fn.dataTableExt.afnFiltering.push(function(oSettings, aData, iDataIndex) {

// check if current table is part of the allow list
if ( $.inArray( oSettings.nTable.getAttribute('id'), allowFilter ) == -1 )
{
// if not table should be ignored
return true;
}
var checked = $('#instock').is(':checked');
var qntStock = 1;
var stockCol = 3;

if (!checked) {
return true;
}
if (checked && aData[stockCol] > qntStock) {
return true;
}

return false;
});

[#84314] Wednesday, July 11, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
morrismilom

Total Points: 230
Total Questions: 96
Total Answers: 114

Location: Mayotte
Member since Mon, Sep 12, 2022
2 Years ago
;