little issue with filtering
little issue with filtering
grobob
Posts: 13Questions: 0Answers: 0
Hi,
I found a little issue in the filtering.
If you move the cursor after begining to type, filtering don't work
Example : http://datatables.net/examples/example_zero_config.html
type "win" in the search field. It work well.
click with the mouse juste before the "w" in the search field
type "gecko " (then now in the search field you have "gecko win")
Filtering don't work, found 0 result (instead of 17)
type another space, and the push the BACKSPACE key, then filtering work good
It's not really important, i do not need you fix them, just report it ;-)
Thank you for your great work ! (and for the greatest 1.5 :D )
I found a little issue in the filtering.
If you move the cursor after begining to type, filtering don't work
Example : http://datatables.net/examples/example_zero_config.html
type "win" in the search field. It work well.
click with the mouse juste before the "w" in the search field
type "gecko " (then now in the search field you have "gecko win")
Filtering don't work, found 0 result (instead of 17)
type another space, and the push the BACKSPACE key, then filtering work good
It's not really important, i do not need you fix them, just report it ;-)
Thank you for your great work ! (and for the greatest 1.5 :D )
This discussion has been closed.
Replies
This is now fixed in the latest development version, and I'll release this shortly :-)
Allan
Using 1.5 beta 10 and pressing any key in the filter/search box will trigger the filter. This isn't really nice if you have a large dataset (slow) or using server-side processing (might trigger quite a lot of database queries).
Assume I've written a five character long word and want to adjust the first one, moving to the left with the left arrow key will trigger unnecessary 5 calls! If you don't want to read the different keycodes, just save the old value and compare it to the new. If they're the same, abort right away.
And a small question, is it possible to fool dataTables into filtering on the first run? I've tried setting the oPreviousSearch.sSearch option and sending it in, but I don't think that one is extracted on initalization.
EDIT: Aha, just editing dataTableSettings[0].oPreviousSearch.sSearch on the returned object is enough.
Really appreciate all the work you put into dataTables, it's working really great!
Could you add a delay timer for the search input (preferably with a configuration option to change the delay)? Some people are slow typers and I don't want to send a bunch of database queries just because they haven't finished typing.
There is already a plug-in API function which does exactly what you are looking for - specifically fnSetFilteringDelay(): http://datatables.net/plug-ins#api_fnSetFilteringDelay . All you need to do is call this function after you have initialised your table and either give it a timer value, or use the default (1/4 second). This will prevent your server's being DDOSed by your own applications!
Regards,
Allan
I've totally missed the plugin section, thanks for the heads up! :-)
[code] iDelay = (iDelay && (/^[0-9]+$/.test(iDelay))) ? iDelay : 250;
var $this = this, oTimerId, sPreviousSearch;
// Unfortunately there is no nFilter inside oSettings.
var anControl = $( 'div.dataTables_filter input:text' );
anControl.unbind( 'keyup' ).bind( 'keyup', function() {
var $$this = $this;
if (sPreviousSearch === null || sPreviousSearch != anControl.val()) {
window.clearTimeout(oTimerId);
sPreviousSearch = anControl.val();
oTimerId = window.setTimeout(function() {
$$this.fnFilter( anControl.val() );
}, iDelay);
}
});
return this;[/code]
That's a good idea - I like that. Thanks for sharing this with us.
Regards,
Allan
[code]jQuery.fn.dataTableExt.oApi.fnSetFilteringDelay = function ( oSettings, iDelay ) {
/*
* Type: Plugin for DataTables (www.datatables.net) JQuery plugin.
* Name: dataTableExt.oApi.fnSetFilteringDelay
* Version: 2.0.0
* Description: Enables filtration delay for keeping the browser more
* responsive while searching for a longer keyword.
* Inputs: object:oSettings - dataTables settings object
* integer:iDelay - delay in miliseconds
* Returns: JQuery
* Usage: $('#example').dataTable().fnSetFilteringDelay(250);
*
* Author: Zygimantas Berziunas (www.zygimantas.com) and Allan Jardine (v2)
* Created: 7/3/2009
* Language: Javascript
* License: GPL v2 or BSD 3 point style
* Contact: zygimantas.berziunas /AT\ hotmail.com
*/
var _that = this;
this.each( function ( i ) {
$.fn.dataTableExt.iApiIndex = i;
iDelay = (iDelay && (/^[0-9]+$/.test(iDelay))) ? iDelay : 250;
var $this = this, oTimerId, sPreviousSearch;
var anControl = $( 'input', _that.fnSettings().anFeatures.f );
anControl.unbind( 'keyup' ).bind( 'keyup', function() {
var $$this = $this;
if (sPreviousSearch === null || sPreviousSearch != anControl.val()) {
window.clearTimeout(oTimerId);
sPreviousSearch = anControl.val();
oTimerId = window.setTimeout(function() {
$.fn.dataTableExt.iApiIndex = i;
_that.fnFilter( anControl.val() );
}, iDelay);
}
});
return this;
} );
return this;
}[/code]
Thanks very much for the update. Sounds like a great idea to me. I've just updated the plug-in on the plug-ins page to v2.1.0 with your change.
Regards,
Allan
[code]jQuery.fn.dataTableExt.oApi.fnSetFilteringDelay = function ( oSettings, iDelay ) {
/*
* Type: Plugin for DataTables (www.datatables.net) JQuery plugin.
* Name: dataTableExt.oApi.fnSetFilteringDelay
* Version: 2.2.0
* Description: Enables filtration delay for keeping the browser more
* responsive while searching for a longer keyword.
* Inputs: object:oSettings - dataTables settings object
* integer:iDelay - delay in miliseconds
* Returns: JQuery
* Usage: $('#example').dataTable().fnSetFilteringDelay(250);
* Requires: DataTables 1.6.0+
*
* Author: Zygimantas Berziunas (www.zygimantas.com) and Allan Jardine (v2)
* Created: 7/3/2009
* Language: Javascript
* License: GPL v2 or BSD 3 point style
* Contact: zygimantas.berziunas /AT\ hotmail.com
*/
var _that = this;
this.each( function ( i ) {
$.fn.dataTableExt.iApiIndex = i;
var iDelay = (iDelay && (/^[0-9]+$/.test(iDelay)) ? iDelay : 250),
$this = this,
oTimerId = null,
sPreviousSearch = null,
anControl = $( 'input', _that.fnSettings().aanFeatures.f );
anControl.unbind( 'keyup' ).bind( 'keyup', function() {
var $$this = $this;
if (sPreviousSearch === null || sPreviousSearch != anControl.val()) {
window.clearTimeout(oTimerId);
sPreviousSearch = anControl.val();
oTimerId = window.setTimeout(function() {
$.fn.dataTableExt.iApiIndex = i;
_that.fnFilter( anControl.val() );
}, iDelay);
}
});
return this;
} );
return this;
}[/code]
Love it! Thanks for updating this plug-in (it's certainly one of the most popular ones). The plug-ins page now reflects the update.
Regards,
Allan
Calling console.log( _that.fnSettings() ) on line 28 returns a useable value: I can navigate the object in the console. When I console.log( _that.fnSettings().aanFeatures ), all I get is an empty array object with nothing to play around with.
I'm on Mac OS X 10.6.8, Chrome 14.0.803.0 dev, Safari 5.0.5 (6533.21.1) and Firefox 4.0.1.
Any kind of pointers appreciated!
François
Any clue ?
My mistake was to set fnSetFilteringDelay directly on the datatable() when using server side processing. That way fnSetFilteringDelay is trying to bind the events to the filter which isn't rendered at that point.
Add fnSetFilteringDelay inside your fnInitComplete event and you will be good.