AfnFiltering is never called for datatable with ajax source

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

datatable compatible works with default sort / filter options. Now I want to display only those users who are registered in a certain period of time. To do this, I take input from the user for the start and end dates and by clicking the binding, I want to filter users according to this date.

jquery code for it:

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

Then I need to write a custom filter function as follows:

 $.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 that this custom filter is never called. But the redraw data callback was successful.

1) Does this type of custom filtering work with AJAX source data?

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

I found a similar request on the site , but it didn’t help me.

+4
source share
1 answer

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

+2
source

Source: https://habr.com/ru/post/1502011/


All Articles