I'm using jQuery DataTables and I have been trying to add tooltips to the Header column of my datatables for the past 2 days to no avail.
I have used the example on the datatables website where tooltips were added to the row data, but that didn't work. I only see one tooltip, and it does not even get the title of the column.
Below is the code I have so far.
if (oTable != null) {
oTable.fnClearTable();
oTable.fnAddData(columnData);
} else {
oTable = $('#caseDataTable').dataTable({
"bDestroy": true,
"aaData": columnData,
"aoColumnDefs": columnNames,
bFilter: true,
bAutoWidth: true,
autoWidth: true,
"responsive": true,
dom: 'Bfltip',
buttons: [
{
extend: 'colvis',
postfixButtons: ['colvisRestore'],
collectionLayout: 'fixed two-column'
}
],
"fnDrawCallback": function() {
if (typeof oTable != 'undefined') {
$('.toggleCheckBox').bootstrapToggle({});
}
$('#caseDataTable thead tr').each(function () {
var sTitle;
var nTds = $('td', this);
var columnTitle= $(nTds[0]).text();
this.setAttribute('title', columnTitle);
});
/* Apply the tooltips */
$('#caseDataTable thead tr[title]').tooltip({
"delay": 0,
"track": true,
"fade": 250
});
}
});
}
There are multiple issues with your code:
th
elements and nottr
.initComplete
is a proper place to do this since you only need to do it once.My example below is for Bootstrap Tooltip. Adjust to your tooltip plugin accordingly.
I would try moving
outside of the fnDrawCallback