Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to display tool tip for each cell?

How can I modify the code to display each cell information into a tooltip??

http://datatables.net/release-datatables/examples/advanced_init/events_post_init.html

$(document).ready(function() {
/*
* First step is to create title attributes for the rows in the table
* This isn't needed if the required 'title' attribute is already set in the HTML in the
* DOM
*/
$('#example tbody tr').each( function() {
var sTitle;
var nTds = $('td', this);
var sBrowser = $(nTds[1]).text();
var sGrade = $(nTds[4]).text();

if ( sGrade == "A" )
sTitle = sBrowser+' will provide a first class (A) level of CSS support.';
else if ( sGrade == "C" )
sTitle = sBrowser+' will provide a core (C) level of CSS support.';
else if ( sGrade == "X" )
sTitle = sBrowser+' does not provide CSS support or has a broken implementation. Block CSS.';
else
sTitle = sBrowser+' will provide an undefined level of CSS support.';

this.setAttribute( 'title', sTitle );
} );

/* Init DataTables */
var oTable = $('#example').dataTable();

/* Apply the tooltips */
oTable.$('tr').tooltip( {
"delay": 0,
"track": true,
"fade": 250
} );
} ); 
like image 594
user244394 Avatar asked Jul 03 '12 11:07

user244394


2 Answers

You can do

{ "sTitle": "...", ...
   'fnCreatedCell': function(nTd, sData, oData, iRow, iCol) {
        nTd.title = 'Some more information';
   }
}

in your column configuration. You can use all the row data easily like this. Of cause, this must not be missing:

oTable.$('td').tooltip( {
    "delay": 0,
    "track": true,
    "fade": 100
} );
like image 131
André B. Avatar answered Nov 16 '22 19:11

André B.


You can set title by simply setAttribute for each td

 $('#example tbody tr td').each( function() {
    this.setAttribute( 'title', $(this).text());
});

and call tooltip on td

oTable.$('td').tooltip( {
"delay": 0,
"track": true,
"fade": 250
} );
like image 2
Sunil Chavan Avatar answered Nov 16 '22 19:11

Sunil Chavan