When will the table be updated really?

When will the table be updated really?

dadodado Posts: 17Questions: 0Answers: 0
edited September 2009 in General
Hi Allan,

because i failed to use your solutions in the other thread (i tried 2nd solution, but i don't know how to make it so i will try it later again) i scripted another part and have a general question about:

I bind a click to another table to get the results via fnReloadAjax. That works. But then i wanted to filter immediatly after the ajax call and the result was empty (No visible rows). So i start debugging and found, that the table have to be drawn later then a tought. Look at this piece of code:

[code]
$('.acc .question').click( function() {
ergebnisTab.fnReloadAjax(htmlbase + this.id.substr(1));
alert ('Filter');
filter();
} );

// and the relevant parts of init
ergebnisTab = $('#ergebnisse').dataTable( {
"aaSorting": [ ], // Prevent initial sorting
"oLanguage": {"sUrl": "js/de_DE.txt"},
"bPaginate": false,
"bLengthChange": false,
"bFilter": true,
"bSort": true,
"bInfo": true,
"bAutoWidth": true,
"bProcessing": true,
"bSortClasses": true,
"bStateSave": false,
"sDom": 'rit'
[...]
[/code]

When the alert rises, the table is empty and i got the "processing" div visible. Even in the filter() function the processing is still there and the table is empty. When i do a fnDraw right before the alert i got on the console:
oSettings.aoData[iRow] is undefined
fnUpdate()()jquery.d...es.min.js (Linie 141)
(?)()()ergebnisse-0.3.js (Linie 154)
F()()jquery-1...ed.min.js (Linie 19)
F()()jquery-1...ed.min.js (Linie 19)
[Break on this error] oSettings.aoData[iRow]._aData[iColumn]=s...n,aData:oSettings.aoData[iRow]._aData});

Will the table filled _after_ the bounded clickfunction returns?

Many thanks
Daniel

Replies

  • allanallan Posts: 61,743Questions: 1Answers: 10,111 Site admin
    Hi Daniel,

    In order to make a function happen after a the table has been reloaded, you can pass a third argument to fnReloadAjax() which will be run just after that table has been redrawn. Or you can just hack the plug-in code to run the function you want :-)

    Regards,
    Allan
  • dadodado Posts: 17Questions: 0Answers: 0
    Hi Allan,

    tried the third argument, but things gone worse...
    i rise an alert at the beginning of the filter function and now i get the alert BEFORE 'processing' gets visible.

    What's going wrong here?

    Thanks
    Daniel
  • allanallan Posts: 61,743Questions: 1Answers: 10,111 Site admin
    Hi Daniel,

    I'm not 100% sure what is happening here, but assuming you have the exact code from http://datatables.net/plug-ins/api#fnReloadAjax you can do something like:

    [code]
    oTable.fnReloadAjax( oTable.fnSettings().sAjaxSource, function () {
    oTable.fnFilter("filter applied");
    } );
    [/code]
    then the table will be filtered after the new Ajax data has been entered. Note that the first argument could be optimised to just pass in null, a small change would be needed to the plug-in to detect that.

    Allan
  • dadodado Posts: 17Questions: 0Answers: 0
    Hi Allen,

    _that_ was the clue! I called the function directly:
    ergebnisTab.fnReloadAjax(htmlbase + this.id.substr(1), filter());

    Now it looks like that:
    ergebnisTab.fnReloadAjax(htmlbase + this.id.substr(1), function() {filter();});

    Do you know why the time of proccessing differs? I thought, there is no difference between these two lines, but obviously i'm wrong.

    Thanks again
    Daniel
  • allanallan Posts: 61,743Questions: 1Answers: 10,111 Site admin
    Hi Daniel,

    Just a little misunderstanding in how Javascript works :-).

    [code]
    var a = filter(); /* This assigns the results of filter() to 'a' */
    var b = function () { return filter(); }; /* This assigns a function (which just happens to run filter when called, to 'b' */
    var c = b(); /* This assigns the return from the function 'b', to 'c' (in this case, it's returning the result of filter()!) */
    [/code]
    This is a fundamental of Javascript, and is one of this things which makes it so damn powerful :-) There are a number of good books available, DOM Scripting by Jeremy Keith for example is a good starting point if you are interesting in learning more.

    Regards,
    Allan
This discussion has been closed.