4

I'm trying to use global filtering on a datatable with an AJAX source as follows:

var usertable = $("#userstable").dataTable({
    "bProcessing": false,
    "bJQueryUI": false,
    "bAutoWidth": false,
    "bServerSide": true,
    "aLengthMenu": [[10, 30, 50, 100], [10, 30, 50, 100]],
    "iDisplayLength": 30,
    "sDom": '<"H"fl>t<"F"ip>',
    "sAjaxSource": "fetchmyusers.php",
    "sPaginationType": "full_numbers",
    "fnDrawCallback": function( oSettings ) {
        console.log('fnDrawCallback called');
    }
});

the datatable works fine along with its default sorting/filtering options. Now i want to display only those users who have registered in a specific time period. For that i take input from user for start-date and end-date and on click of a anchor i want to filter the users according to this date.

the jquery code for the same is:

$("#customdatefilter").on('click',function(e) {
    e.preventDefault();
    usertable.fnDraw();
    //console.log('redrawn');
});

Then I need to write a custom filtering function in the following manner:

$.fn.dataTableExt.afnFiltering.push(
    function( oSettings, aData, iDataIndex ) {
      console.log('filtering..');

      //filter data as per my input

      return true; 
      //in some cases false
});

But the problem here is this custom filter is never called. But the data redraw callback is executed successfully.

1) Does this type of custom filtering work with AJAX-sourced datatables??

2) Are any of my initialization options missing/wrong?

I found a similar query on their site but it did not help me.

OptimizedQuery
  • 1,262
  • 11
  • 21
Ankit Khedekar
  • 924
  • 1
  • 7
  • 26

1 Answers1

2

Referring to the https://datatables.net/forums/discussion/15952/afnfiltering-function-never-called#Comment_56134 I assume that custom filtering function will never work for server side processing mode.

jmarceli
  • 19,102
  • 6
  • 69
  • 67