HTML
xxxxxxxxxx
1
<p>
2
Upon page load, the tooltip appears in the pencil icon (black background, white text).
3
</p>
4
<p>
5
As soon as you sort on a column, the tooltip disappears (goes to browser default).
6
</p>
7
<div id="datatable" data-mdb-loading="true"></div>
CSS
1
1
JS
xxxxxxxxxx
1
const columns = [
2
3
{ label: 'Username', field: 'username' },
4
{ label: 'Website', field: 'website' },
5
{ label: 'Actions', field: 'actions', sort: false },
6
];
7
8
const asyncTable = new mdb.Datatable(
9
document.getElementById('datatable'),
10
{ columns, },
11
{ loading: true }
12
);
13
14
fetch('https://jsonplaceholder.typicode.com/users')
15
.then((response) => response.json())
16
.then((data) => {
17
asyncTable.update(
18
{
19
rows: data.map((user) => ({
20
...user,
21
address: `${user.address.city}, ${user.address.street}`,
22
company: user.company.name,
23
actions: `
24
<a href="#" onClick="titleAddEditOpenModal(${user.company.name});"><i class="fa-solid fa-pencil" data-mdb-toggle="tooltip" title="Edit"></i></a>
25
`,
26
})),
27
},
28
{ loading: false }
29
);
30
reinitializeToolTips();
31
});
32
33
34
function reinitializeToolTips(){
35
const tooltips = document.querySelectorAll('[data-mdb-toggle="tooltip"]')
36
tooltips.forEach((tooltip) => {
37
const tooltipInstance = new mdb.Tooltip(tooltip);
38
});
39
}
40
41
document.addEventListener('render.mdb.datatable', ()=>{
42
reinitializeToolTips();
43
})
Console errors: 0