fnSetFilteringDelay does not work for me when i use "oLanguage" to initialize the datatables

fnSetFilteringDelay does not work for me when i use "oLanguage" to initialize the datatables

yanhangyanhang Posts: 3Questions: 0Answers: 0
edited September 2010 in Plug-ins
DataTables is the best plug-ins that I've seen, it is very useful for me, thanks a lot for authors

But I got a problem with fnSetFilteringDelay function yesterday, I think maybe it is a bug

If I don't use "oLanguage" to initialize the datatables, everything is ok, but when I use "oLanguage", everything is ok too but fnSetFilteringDelay dose not work.

I debug the code, find the variable "anControl" maybe is wrong, the reason maybe is oLanguage, I guess

please check that variable, it is different between use "oLanguage" to initialize the datatables and not.

The code which has problem is here:
[code]
otable_table = $("#htable_table").dataTable(
{
"oLanguage": {"sUrl": "../data/zh_ZH.txt"},//if remove this line, fnSetFilteringDelay works
"bJQueryUI": true,
"bStateSave": false,
"bPaginate": true,
"bAutoWidth": false,
"bProcessing": true,
"bServerSide": true,
"sPaginationType": "full_numbers",
"sAjaxSource": "test.ashx",
"aoColumnDefs":[
{"bVisible": false, "sName":"PK_DICT_TABLE", "aTargets":[0]},
{"bVisible": true, "sName":"DICT_TABLE_CODE", "aTargets":[1]},
{"bVisible": true, "sName":"DICT_TABLE_NAME", "aTargets":[2]},
{"bVisible": true, "sName":"DICT_TABLE_CLASS_NAME", "aTargets":[3]},
{"bVisible": true, "sName":"DICT_TABLE_MEMO", "aTargets":[4]},
{"bVisible": true, "sName":"DICT_TABLE_CATEGORY", "aTargets":[5]}
]
});
otable_table.fnSetFilteringDelay(500);}
[/code]

"zh_ZH.txt" is a language file that i use.
When I remove the line ""oLanguage": {"sUrl": "../data/zh_ZH.txt"},", everythink is ok.
"oLanguage" is a very useful option for me, so, thanks again for check this bug.

If the code is wrong, please reply me, thanks again

Replies

  • allanallan Posts: 63,687Questions: 1Answers: 10,500 Site admin
    Try doing it fnInitComplete. The reason being, the XHR is asynchronous, so the $().dataTable() function will complete before the language information has been retrieved - which of course is before it can add the filtering options, which in turn reply on the language.

    So fnInitComplete is the way forward I think: http://datatables.net/usage/callbacks#fnInitComplete

    Allan
  • yanhangyanhang Posts: 3Questions: 0Answers: 0
    thanks allan, you're right!

    use fnInitComplete callback, it works fine

    it seems not a bug, sorry~
  • max4evermax4ever Posts: 45Questions: 0Answers: 0
    i tried using fnInitComplete, and it still won't work, could you post your working code?
    big thanks
  • yanhangyanhang Posts: 3Questions: 0Answers: 0
    well,my code is here,it works fine, Allan is right, use fnInitComplete callback, I hope this is useful for you

    [code]
    otable_user = $("#htable_user").dataTable(
    {
    "oLanguage": {"sUrl": "../data/zh_ZH.txt"},
    "bJQueryUI": true,
    "bStateSave": false,
    "bPaginate": true,
    "bAutoWidth": false,
    "bProcessing": true,
    "bServerSide": true,
    "sPaginationType": "full_numbers",
    "fnInitComplete": function(){this.fnSetFilteringDelay(500);},//this is callback function
    "sAjaxSource": ajaxsource,
    "aaSorting": [[3,'desc']],
    "aoColumnDefs":[
    {"bVisible": false, "sName":"PK_USER", "aTargets":[0]},
    {"bVisible": true, "sName":"USER_PASSWORD", "aTargets":[1]},
    {"bVisible": false, "sName":"DR", "aTargets":[2]},
    {"bVisible": false, "sName":"TS", "aTargets":[3]},
    {"bVisible": true, "sName":"USER_CODE", "aTargets":[4]},
    {"bVisible": true, "sName":"USER_EMAIL", "aTargets":[5]},
    {"bVisible": true, "sName":"USER_ALLOWLOGIN", "aTargets":[6]},
    {"bVisible": true, "sName":"USER_STARTDATE", "aTargets":[7]},
    {"bVisible": true, "sName":"USER_ENDDATE", "aTargets":[8]}
    ]
    });
    [/code]
  • allanallan Posts: 63,687Questions: 1Answers: 10,500 Site admin
    The reason for this behaviour with sUrl is the asynchronous behaviour of the Ajax call to get the language file, and the way fnSetFilteringDelay works. DataTables can't render the DOM fully until it's got the language file (otherwise - what would it render :-) ), so the call to $().dataTable() will complete before the DOM is in the state you want. fnSetFilteringDelay works by removing the default filtering handle and putting in it's own - but the filtering handle isn't there yet, hence why it needs to go into fnInitComplete - which is fired when the table is fully initialised.

    Allan
  • max4evermax4ever Posts: 45Questions: 0Answers: 0
    i still get almost every key that i type in the search field, submitted with an ajax request(using firebug), even when changing the parameter 500miliseconds with 2000miliseconds
  • allanallan Posts: 63,687Questions: 1Answers: 10,500 Site admin
    Can you show us the code you are using please? Even better - a link... :)

    Allan
  • max4evermax4ever Posts: 45Questions: 0Answers: 0
    i can give you a link with user and password, just can't post it for everyone to read it, can't find the private message button

    here is my code (where /scripts/dataTables.addons.js contains the fnSetFilteringDelay() code from http://www.datatables.net/plug-ins/api )
    [code]
    ...






    ...


    <!--
    var oTable;
    $(document).ready(function() {
    ....

    var controller_name = "zona";

    oTable = $('#visualizzazione').dataTable(
    {
    "oLanguage": {
    "sUrl": "/lang/dataTables-it_IT.txt"
    },
    //"bStateSave": true,
    "aoColumns": [
    { "sName": "nome", "sWidth": "80%"},
    { "sName": "id", "sWidth": "20%", "bSortable": false, "bSearchable" :false } ],
    "aLengthMenu": [[5, 10, 25, 50, 100, -1], [5, 10, 25, 50, 100, "Tutti"]],
    "sPaginationType": "full_numbers",
    "bJQueryUI": true,
    "bProcessing": true,
    "bServerSide": true,
    "sAjaxSource": "/"+controller_name+"/ajax/",
    "fnDrawCallback": function ( oSettings ) {
    /* Need to redo the counters if filtered or sorted */

    for ( var i=0, iLen=oSettings.aiDisplay.length ; i
  • allanallan Posts: 63,687Questions: 1Answers: 10,500 Site admin
    Try replacing line 88 ( }).fnSetFilteringDelay(5000); ) with just "});" - i.e. don't call fnSetFilteringDelay twice.

    Allan
  • max4evermax4ever Posts: 45Questions: 0Answers: 0
    edited March 2011
    thanks allan, i tried that it won't work too,
    i just tested that even if i don't use a language file it still won't work

    is this order correct ?



    i mean, first dataTables, then the fnSetFilteringDelay script ?
  • allanallan Posts: 63,687Questions: 1Answers: 10,500 Site admin
    Yes that is correct.

    I'd suggest adding in a couple of console.log events to the fnSetFilteringDelay function and make sure that they show up in the console when you start typing.

    Allan
  • max4evermax4ever Posts: 45Questions: 0Answers: 0
    hey allan, thank you!
    i found the error, i had an old example or something because
    i had this line
    [code]anControl = $( 'table.dataTables input', _that.fnSettings().aanFeatures.f );[/code]

    instead of
    [code]
    anControl = $( 'input', _that.fnSettings().aanFeatures.f );
    [/code]

    cheers
This discussion has been closed.