HTML
xxxxxxxxxx
1
<div id="datatable-custom"></div>
CSS
1
1
JS
xxxxxxxxxx
1
const customDatatable = document.getElementById('datatable-custom');
2
3
const setActions = () => {
4
document.getElementsByClassName('call-btn').forEach(btn => {
5
btn.addEventListener('click', () => {
6
console.log(`call ${btn.attributes['data-mdb-number'].value}`)
7
})
8
})
9
10
document.getElementsByClassName('message-btn').forEach(btn => {
11
btn.addEventListener('click', () => {
12
console.log(`send a message to ${btn.attributes['data-mdb-email'].value}`)
13
})
14
})
15
}
16
17
customDatatable.addEventListener('render.mdb.datatable', setActions);
18
19
new mdb.Datatable(customDatatable, {
20
columns: [
21
{ label: 'Title', field: 'title' },
22
{ label: 'Position', field: 'position' },
23
{ label: 'Office', field: 'office' },
24
{ label: 'Contact', field: 'contact' }
25
],
26
rows: [
27
{
28
url: '/users/detail/645fd2fb626ecdfe7f105480',
29
title: 'Beta',
30
position: 'System Architect',
31
office: 'Edinburgh',
32
phone: '+48000000000',
33
email: 'b@gmail.com',
34
},
35
{
36
url: '/users/detail/645fd2fb626ecdfe7f105481',
37
title: 'Alpha',
38
position: 'Software Engineer',
39
office: 'Edinburgh',
40
phone: '+53456123456',
41
email: 'a@gmail.com',
42
},
43
{
44
url: '/users/detail/645fd2fb626ecdfe7f105482',
45
title: 'Delta',
46
position: 'Regional Director',
47
office: 'London',
48
phone: '+42123432456',
49
email: 'c@gmail.com',
50
},
51
].map((row) => {
52
return {
53
...row,
54
title: `<a href="${row.url}" target="_blank">${row.title}<a/>`,
55
};
56
}),
57
58
}, {sortField: 'title', sortOrder: 'asc'});
Console errors: 0