$.fn.dataTableExt.afnFiltering.push - What is this?

$.fn.dataTableExt.afnFiltering.push - What is this?

jnymrisjnymris Posts: 10Questions: 0Answers: 0
edited November 2011 in Plug-ins
Hello,
I'm trying to Impliment a filter by date range using the filtering plug-in (in the examples page on the website by: guillimon)
However i want this to be updated after button press now as far as i'm away $.fndataTableExt blah blah is a call to something inside dataTables correct?

I've tried replacing this with $('#mybutton').click and everything behond this is left the same but nothing is returned? not even an alert box which is what comes right after the function here's my code i'm using (Date value i'm trying to filter is the 5th Col along (so it would be 5 as programming counting starts from 0 any pointers as to where i'm going wrong?

[code] $(document).ready(function() {
$('#Details').dataTable({
"aaSorting": [[ 0, "desc" ]],
"sPaginationType": "full_numbers"
});
$('#mybutton').click(
function( oSettings, aData, iDataIndex ) {
alert("HI");
var iFini = document.getElementById('from_date').value;
var iFfin = document.getElementById('to_date').value;
var iStartDateCol = 3;
var iEndDateCol = 5;

iFini=iFini.substring(6,10) + iFini.substring(3,5)+ iFini.substring(0,2)
iFfin=iFfin.substring(6,10) + iFfin.substring(3,5)+ iFfin.substring(0,2)

var datofini=aData[iStartDateCol].substring(6,10) + aData[iStartDateCol].substring(3,5)+ aData[iStartDateCol].substring(0,2);
var datoffin=aData[iEndDateCol].substring(6,10) + aData[iEndDateCol].substring(3,5)+ aData[iEndDateCol].substring(0,2);

if ( iFini == "" && iFfin == "" )
{
return true;
}
else if ( iFini <= datofini && iFfin == "")
{
return true;
}
else if ( iFfin >= datoffin && iFini == "")
{
return true;
}
else if (iFini <= datofini && iFfin >= datoffin)
{
return true;
}
return false;
}
);
} );[/code]

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin
    $.fn.dataTableExt.afnFiltering is an array of functions, each of each perform a filtering operation on the table. The 'push' is added a new function to the array so that DataTables will process it.

    If you want to have a table take into account new filtering information which is available to your plug-in filter, just call fnDraw and DataTables will do a full redraw, refiltering the table.

    Allan
  • jnymrisjnymris Posts: 10Questions: 0Answers: 0
    Thanks Very Much Allan, however just by calling the fnDraw this will re-draw the table without the relevant fields being filtered out as the filter is not apart of the started DataTables I'm using an id of from_date and to_date to filter from and to date period so i don't understand how it will pull the values from that if i'm just using fnDraw I'm trying to do two things here really
    1) Get the values from the two divs (that works fine) then
    2) Filter DataTables based on these dates
  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin
    I just put together this example for another thread which I think will help here: http://live.datatables.net/oyinin/3/edit#javascript,html . You can either get the values in the filtering function, or you can cache the values just before you draw the table for a bit more speed (as I've done in the example).

    Allan
This discussion has been closed.