afnFiltering function never called
afnFiltering function never called
First of all, thanks for the product - looks very thorough.
I'm trying to use the afnFiltering function to implement a customer filter but it seems that the function is never called despite my issuing the fnDraw() on the dataTable object. Is there any way to test whether the function gets called and that the failure of the filter code to actually filter out any rows is due to the code in the filter function itself? Here is the function as I have implemented it:
[code]
$.fn.dataTableExt.afnFiltering.push(
function( oSettings, aData, iDataIndex ) {
//alert('Custom filtering taking place NOW!!!');
var strFilters = new Array();
var boolReturn = true;
$("#ProductAccordion table:first thead tr td").each(function(index) {
strFilters[index] = '';
$(this).find("input[type='checkbox']:not('.allCheck')").each(function() {
if($(this).is(':checked')) {
strFilters[index] += '|' + $(this).attr('id');
}
});
if (strFilters[index] != '') {
strFilters[index] = strFilters[index].substr(1);
}
});
for (var i=0; i < strFilters.length; i++) {
var regExpCol = new RegExp(strFilters[i]);
boolReturn = boolReturn & regExpCol.test(aData[i]);
}
return boolReturn;
}
);
[/code]
The alert, even if uncommented, does not appear.
Tanks in advance.
I'm trying to use the afnFiltering function to implement a customer filter but it seems that the function is never called despite my issuing the fnDraw() on the dataTable object. Is there any way to test whether the function gets called and that the failure of the filter code to actually filter out any rows is due to the code in the filter function itself? Here is the function as I have implemented it:
[code]
$.fn.dataTableExt.afnFiltering.push(
function( oSettings, aData, iDataIndex ) {
//alert('Custom filtering taking place NOW!!!');
var strFilters = new Array();
var boolReturn = true;
$("#ProductAccordion table:first thead tr td").each(function(index) {
strFilters[index] = '';
$(this).find("input[type='checkbox']:not('.allCheck')").each(function() {
if($(this).is(':checked')) {
strFilters[index] += '|' + $(this).attr('id');
}
});
if (strFilters[index] != '') {
strFilters[index] = strFilters[index].substr(1);
}
});
for (var i=0; i < strFilters.length; i++) {
var regExpCol = new RegExp(strFilters[i]);
boolReturn = boolReturn & regExpCol.test(aData[i]);
}
return boolReturn;
}
);
[/code]
The alert, even if uncommented, does not appear.
Tanks in advance.
This discussion has been closed.
Replies
I am running in the exact same problem. Example of code:
[code]
oTable.dataTableExt.afnFiltering.push(
function (oSettings, aData, iDataIndex) {
alert('inside!');
return true;
}
);
alert(oTable.dataTableExt.afnFiltering.length + " filter pushed");
$input.change(function () {
alert('doing the call...');
oTable.fnDraw();
});
[/code]
The filtering function is correctly stored ("1 filter pushed"), but at fnDraw() (when I click on the specific $input) it does not even call that function.
Allan
I've found the problem:
After 10min I was able to get it to work so I suppose it was some kind of cache problem from the browser however I am not sure since I was in debug mode and I was really seeing no call even after the first alert() saying that the event was fired.
I was expecting it to filter all results but it doesn't do that at startup, we have to call fnDraw manually since the plugin is loaded after the table (I guess that's the reason).
Thank you for your fast answer.
Sounds about right to me. If the plug-in isn't available when the table is initialised, its certainly not going to run then :-)
Allan
I have a question, is there any other method that could make it without two calls (I mean the first fnDraw is done before the second that applies the plugin)?
I am using a customized version of columnFilter and the problem is that for each checkbox filter field, for example every checkbox, I am adding this:
[code]
//function fnCreateCheckbox()
//index = current aData position;
//oTable_ID = current ID of the table
oTable.dataTableExt.afnFiltering.push(
function (oSettings, aData, iDataIndex) {
if (oTable_ID != oSettings.sTableId)
return true;
switch (inputValue_Saved) {
case 'true':
return $(aData[index]).filter("input").is(":checked");
case 'false':
return !$(aData[index]).filter("input").is(":checked");
default:
return true;
}
}
);
[/code]
1. If I understand this correctly, even if this works (tested), it's adding a function to every DataTable fnDraw call?
2. Plus, (considering it's based on the columnFilter plugin) its initialization is made after the .dataTable(...) call. I did not find a way to NOT do a double call to fnDraw (I consider that .dataTable() make some kind of fnDraw call to display its content, which is normal).
How could I make it to not have a second call?
Because the other filters like the fnCreateInput seems to use fnFilter, and - at least on the server side mode - it doesn't do a second call to the database.
However it's still the columnFilter plugin, it's called AFTER .datatable(...), but still it does not do 2 calls.
It's the way I would like to work with my custom plugin.
How could I not be forced to make a call to fnDraw in order to filter the data?
I can't say about the column filter plug-in I'm afraid. That's third party and I don't know much about it.
Allan
[code]
$.fn.dataTableExt.afnFiltering.push(
function( oSettings, aData, iDataIndex ) {
var vMin = $("#slidMinVolt").slider("value");
var vMax = $("#slidMaxVolt").slider("value");
var vMinData = aData[6];
var vMaxData = aData[7];
var cMin = getNonLinearValue(intAllMinCap, intAllMaxCap, $("#slidMinCap").slider("value"));
var cMax = getNonLinearValue(intAllMinCap, intAllMaxCap, $("#slidMaxCap").slider("value"));
var cMinData = aData[8];
var cMaxData = aData[9];
if (
vMin <= vMinData &&
vMaxData <= vMax &&
cMin <= cMinData &&
cMaxData <= cMax
) {
return true;
}
return false;
}
);
[/code]
Im having the same problem, the filtering function successfully gets pushed into 'afnFiltering' array, but it's never been called when fnDraw is called. Could someone overcome this issue please explain as to what you did to solve this problem? Many thanks in advance.
Thanks,
Vaasugi.
Allan
Because I'm set to "bServerSide": true.
It looks like the assumption is that if I'm using server-side processing, I can't ALSO do client-side filtering. Is that right? Is there any (simple) way around that?
Thanks,
Ed
Allan