How to use tooltip with bProcessing & sAjaxSource ? cause oTable.fnGetNodes().length is 0

How to use tooltip with bProcessing & sAjaxSource ? cause oTable.fnGetNodes().length is 0

daniel_rdaniel_r Posts: 460Questions: 4Answers: 67
edited June 2011 in General
Hi, I have looked at the two examples

DataTables events (post-initialisation) example
and
DataTables events (pre-initialisation) example

But none of them, works in my case :(
I guess its case I use bProcessing & sAjaxSource , which cause my table to be loaded after some time,

So I cannot set the "title" data for the tr element the way the examples shows :/
also I cannot use the .tooltip( ... on each row... cause the rows appears after some delay...

So... how can I use the tooltip if I'm using the bProcessing & sAjaxSource in my table?

Thanks ahead,

Daniel.

Replies

  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin
    You need to use fnInitComplete - http://datatables.net/usage/callbacks#fnInitComplete - when using Ajax sourced data. Remember the 'A' in Ajax stands for Asynchronous - so the initialisation of the table would be complete before the data has loaded.

    Allan
  • daniel_rdaniel_r Posts: 460Questions: 4Answers: 67
    edited June 2011
    Found my answer in other post in the forum,

    ignore...
  • daniel_rdaniel_r Posts: 460Questions: 4Answers: 67
    edited June 2011
    sorry , The solution i found else where is not working :(

    Thx for the reply , but that applies only to the first page (I got pagination)

    to set the title of each row I used
    [code]"fnRowCallback": function( nRow, aData, iDisplayIndex ) {
    // set tr title.
    var title = aData[11];
    $(nRow).attr("title",title);
    return nRow;
    },
    [/code]
    and to apply the tooltip I used fnInitComplete
    [code]
    "fnInitComplete": function() {
    // Apply the tooltips
    $( oTable.fnGetNodes() ).tooltip( {
    "delay": 0,
    "track": true,
    "fade": 250
    } );
    [/code]

    Although alert($( oTable.fnGetNodes()).length); give me the right number of total rows in table (but there is only 10 in each page), it apply to the first page only, all the other pages got browser default ugly title

    Is there a callback of each page redraw?
    Cause if I use the fnDrawCallback it gives me each time the total number of the rows in the entire table and applying the .tooltip() inside fnDrawCallback will be too "heavy"
    So what is the right way to apply the tooltip when working with pagination?

    In other thread you said that a fnInitCallback should be used I think you meant fnInitComplete ?

    I also tried the live method of jquery
    but its not working well :/

    [code]
    "fnInitComplete": function() {
    $('#widgetTableID tbody tr').live("mouseover", function(event) {
    $(this).tooltip( {
    "delay": 0,
    "track": true,
    "fade": 250
    } );
    });
    }

    [/code]

    It apply the tooltip with a huge delay, and sometimes the default browser tooltip is back on working and the jquery tooltip os stops to work... its going on and off...



    Any ideas?

    Thanks ahead,

    Daniel.

    Thanks ahead,
    Daniel.
  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin
    fnDrawCallback is what you what: http://datatables.net/usage/callbacks#fnDrawCallback
    See also: http://datatables.net/faqs#events

    Allan
  • daniel_rdaniel_r Posts: 460Questions: 4Answers: 67
    But at other thread you said

    http://datatables.net/forums/comments.php?DiscussionID=712&page=1

    "with fnDrawCallback() the events are always added on each draw. Actually, this can be bad... for example if you click page forward then page back, the rows on your first page will now have two events assigned to them. Forwards/back again and you'll have three events on them, etc... "

    ?
  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin
    Yup - it sort of depends on how the tooltip plug-in works and how it adds events. Ideally if it used live events then you would only need one call to it and never need to worry about it again. That might or might not be the case. What I would suggest is fnInitComplete with fnGetNodes (a bit like this - but in fnInitComplete: http://datatables.net/release-datatables/examples/advanced_init/events_post_init.html ).

    Allan
This discussion has been closed.