How can I suppress client-side filtering?

How can I suppress client-side filtering?

jamesjburtjamesjburt Posts: 8Questions: 0Answers: 0
edited December 2011 in General
UPDATE 2:

After I posted this, I discovered the code (emplaced by a contractor) to create three filters. Why I never noticed this before also mystifies me (smile). So this explains why three iterations of the filter was performed on the client side prior to the AJAX submission. This effectively renders my suggestion #2 below to be invalid. The code already only performs as many iterations as filters exist. Suggestion #1 lives though! JB




UPDATE:

I discovered that we must invoke oTable.fnDraw(false) to suppress client-side filtering. This is not very well documented or explained, I had to trace the code to discover it. The problem is that fnDraw() defaults to fnDraw(true) if no parameter is included. fnDraw(true) then invokes the _fnReDraw() method instead of the _fnDraw() method. This causes client-side filtering to be triggered, and it must be completed BEFORE datatables continues to the step of making an AJAX request (which will replace the entire dataset anyway!)

SUGGESTION:

1. if bServerSide is set to true, make fnDraw() default to false. There is no reason to invoke client-side filtering, sorting etc if we are subsequently going to replace the entire data set with server-side data.

2. Modify _fnFlterCustom(). Have it check for the existence of filters BEFORE iterating the entire set of displayed rows three times. There is no reason to iterate the entire set of displayed rows three times to see if a filter should be applied when no filters even exist. Perhaps change the nesting of the loops?




I have a datatable that retrieves data from server-side. Search and filtering seem to work fine on the server side. However, I notice that the datatables.js library FIRST invokes a client-side filter before submitting the AJAX request for new data. When I have a large dataset already in the browser (say 600 rows) and request a new set that is small (say 5 rows) I can clearly see datatables.js iterating through all 600 rows three times each and checking to see if a filter should be applied. Only after that does it make an AJAX request for new data.

If I set "bFilter" to FALSE, client-side filtering stops, but none of the search parameters are included in the AJAX request.

If I set "bServerSide" to TRUE, I would expect the client-side filtering to stop, but it does not.



===========================================================
I Inserted Debug statements in datatables.js, and captured the output as it worked:
===========================================================

(Click on "All Clients", site loads 605 clients)

(Click on "5 Clients", site uses javascript to filter the 605 records on the client-side PRIOR to making the ajax request for 5 clients)

(Stop Script, and observe debug window, we can see that datatables was attempting to filter 605 clients by javascript client-side )

fnReDraw start
_fnReDraw invoking _fnSort
_fnSort start
_fnSort invoking _fnFilterComplete
_fnFilterComplete start
_fnFilterComplete invoking _fnFilter
_fnFilter start
_fnFilter end
_fnFilterComplete invoking _fnFilterCustom
_fnFilterCustom start
_fnFilterCustom, afnFilters.length =3 oSettings.aiDisplay.length =605
_fnFilterCustom i=0
_fnFilterCustom iDisIndex=0
_fnFilterCustom iDisIndex=1

< 2-72 removed for brevity >

_fnFilterCustom iDisIndex=73
_fnFilterCustom iDisIndex=74






===========================================================


[code]

oTable1 = $('#clients-grid').dataTable
({
"aoColumns":
[
{"mDataProp": "ACCOUNT_NUMBER", "sTitle": "Acct #"},
{"mDataProp": "INCEPTION_DT", "sTitle": "Inception Date"},
{"mDataProp": "NAME1", "sTitle": "Primary Client"},
{"mDataProp": "NAME2", "sTitle": "Secondary Client"}

],
"fnServerData": function (sSource, aoData, fnCallback) {
var arrColNames = new Array();
var objCols = this.fnSettings().aoColumns;

for(var i=0; i

Replies

  • allanallan Posts: 63,516Questions: 1Answers: 10,472 Site admin
    Related post with my comments here: http://datatables.net/forums/discussion/7825/fndraw-suggested-changes

    Allan
This discussion has been closed.