Using tooltips with DataTables
Using tooltips with DataTables
jaredgerber
Posts: 40Questions: 10Answers: 0
in DataTables
I can't seem to get my tooltip to fire on my table. I haven't seen any examples or questions about this for quite a while -- am I doing something wrong here?
var table = "";
$(document).ready(function()
{
$('#agent tbody tr').each( function() {
var sTitle;
var nTds = $('td', this);
var sTip = $(nTds[1]).text();
sTitle = sTip+' is the Agent.';
this.setAttribute( 'title', sTitle );
} );
/* Init DataTables */
$("#pleasewait").show();
table = $('#agent').dataTable( {
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "php/processList.php?list=agent&has_form=true"
} );
/* Apply the tooltips */
$('#agent tbody tr[title]').tooltip( {
"delay": 0,
"track": true,
"fade": 250
} );
This question has accepted answers - jump to:
This discussion has been closed.
Answers
You are using server-side processing, so
tooltip
(and the title attributes) and being set on cells that don't yet exist (since the table data won't have loaded in this case). You could do those actions in the fnDrawCallback function since it will run for every page.Allan
Ahhh -- ok -- I'm getting it. Again, slowly :-)
I got it to work, but how do I apply style -- like on this example?
https://datatables.net/beta/1.9/examples/advanced_init/events_post_init.html
I'm looking to apply a little css and add multiple lines of information (e.g., 5 other fields) on the popup -- will this method work for that?
That example uses this tooltip library (it was the first one I found from Googling back when I wrote that example). If it isn't being styled then you probably need to include the tooltip's stylesheet. As for its capabilities you would need to refer to its documentation.
Allan
Ok -- so I finished this cool new BIG hover popup using bootstrap tooltip -- yayy -- it's pretty. And it works with bServerSide enabled.
I'm successfully loading data from the TD cells into the tooltip; however, I need access to other fields that are not in the dataTable cells. What would be the best approach for this? Should I hide the whole title string in the dataTable somewhere then transfer it to the TR title after the dataTable loads? Is there a more efficient way to do it? Can I just load the title into the TR when initializing the dataTable?
Sample here:
http://174.120.222.66/~opes/agent/rpt_agent.php
You could use the
DT_RowAttr
option to return the title attribute you want in the JSON data. Note you need to be using the nightly version of DataTables for this - it will be in 1.10.5 which is due for release next week.Allan
So ... just hold tight for now? Nightly?
Personally I'd use the nightly - but it is up to you :-).
Allan
Ok - I get it. It's like beta.
Sort of. A beta implies a particular milestone. The nightly however is a build of the very latest changes that I've made. It is possible that buys are included by mistake as a result, although it is (generally...) rare. The nightly contains all changes to date.
Allan
Nice. Nightlys it is :-)
I'm trying to use the DT_RowAttr to create a unique title for each row. I created a field agent.title that looks like this:
It's the 2nd value in the data shown in the data below.
And I'd like to pass that as the title for each TR. I can see I can make the DT_RowAttr setting in the first array, but how to I get it from the columns into the title of the TR?
Here is my header data:
Your JSON data doesn't include
DT_RowAttr
for each row.In this example click the Ajax load tab just below the table. You will see each object contains
DT_RowId
. The same principle applies forDT_RowAttr
.Allan
Ohhh -- I need the Object format for this function to work.