ranganath589 / jquery-datatables-column-filter

Automatically exported from code.google.com/p/jquery-datatables-column-filter
0 stars 0 forks source link

Column Filter do not implement iFilteringDelay - code to implement #97

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?

The iFilteringDelay variable exists but it's never used. When input text search 
is used, each keypress starts an ajax search, which it's not desireable.

What is the expected output? What do you see instead?
To wait a certain time (in miliseconds) permiting to the user to finish his 
typing.

What version of the product are you using? On what operating system?
1.5.0 or below

Please provide any additional information below.

To solve, replace this piece of code:

// -- BEGIN 739 in version 1.5.0
                    if (fnServerDataOriginal != null) {
                        try {
                            fnServerDataOriginal(sSource, aoData, fnCallback, oTable.fnSettings()); //TODO: See Issue 18
                        } catch (ex) {
                            fnServerDataOriginal(sSource, aoData, fnCallback);
                        }
                    }
                    else {
                        $.getJSON(sSource, aoData, function (json) {
                            fnCallback(json)
                        });
                    }
// -- END 750

with this:

// -- BEGIN
                    if (fnServerDataOriginal != null) {
                        if (properties.iFilteringDelay != 0) {
                            if (oFunctionTimeout != null)
                                window.clearTimeout(oFunctionTimeout);
                                oFunctionTimeout = window.setTimeout(function () {
                                    try {
                                        fnServerDataOriginal(sSource, aoData, fnCallback, oTable.fnSettings()); //TODO: See Issue 18
                                    } catch (ex) {
                                        fnServerDataOriginal(sSource, aoData, fnCallback);
                                    }
                                }, properties.iFilteringDelay);
                        }
                    }
                    else {
                        if (properties.iFilteringDelay != 0) {
                            if (oFunctionTimeout != null)
                                window.clearTimeout(oFunctionTimeout);
                                oFunctionTimeout = window.setTimeout(function () {
                                    $.getJSON(sSource, aoData, function (json) {
                                        fnCallback(json)
                                    });
                                }, properties.iFilteringDelay);
                        }
                    }
// -- END

[]'s
Rafael Goulart from Brazil

Original issue reported on code.google.com by rafael...@gmail.com on 17 Sep 2012 at 8:47

GoogleCodeExporter commented 8 years ago
for some reason this isn't working for me, without digging too deep one thing i 
noticed is that it's contained within the if statement "if 
(oTable.fnSettings().oFeatures.bServerSide) {" - i'm wondering if it isn't 
working because the filtering is supposed to be taking place on the clientside 
(bserverside = false) any suggestions?

Original comment by peter.ur...@gmail.com on 21 Sep 2012 at 6:32

GoogleCodeExporter commented 8 years ago
iFilteringDelay only makes sense if your data is being requested via server 
side (bServerSide = true), doesn't it? 

The main purpose is to avoid to much requests to the server on each character 
typed...

Original comment by rafael...@gmail.com on 21 Sep 2012 at 6:49

GoogleCodeExporter commented 8 years ago
in my scenario the data is already at the client and i'm taking that data, 
filtering it, then creating graphs out of the remaining records - sometimes it 
can be thousands of records so it creeps along one character at a time when 
typing in the filter, hence my need for it on the clientside end of things!

Original comment by peter.ur...@gmail.com on 21 Sep 2012 at 10:05

GoogleCodeExporter commented 8 years ago
would you be able to suggest where i would implement this in a different spot 
so i can utilize it on the client end without bserverside set to true?

Original comment by peter.ur...@gmail.com on 25 Sep 2012 at 9:45

GoogleCodeExporter commented 8 years ago
The issue with this approach is that it delays your paging and sorting as well. 
 I used a third party plugin 
http://benalman.com/projects/jquery-throttle-debounce-plugin/ and changed the 
following

I changed line 135
from   

  input.keyup(function() {
to
  input.keyup($.debounce(650, function() {

and added a closing parenthesis on line 159. 

 I only did this on the text input at this time, I have it hard-coded for now but you could pass iFilteringDelay down to the fnCreateInput function

Original comment by fetters5@gmail.com on 23 Jan 2013 at 9:40

GoogleCodeExporter commented 8 years ago
Awesome - thanks to fetters5 - exactly what I was needing to do, and the first 
I'd heard of the debounce plugin for jquery.  Line numbers were slightly 
different in my version (1.5.3):

line 139:
                input.keyup($.debounce(650, function () { // Added 20140508 TMC

line 163 gets the extra closing paren:
                })); // Extra ) added 20140508 TMC

Original comment by t...@gmara.org on 8 May 2014 at 8:05