xxxxxxxxxx
1
<div id="datatable" data-mdb-selectable="true" data-mdb-multi="true"></div>
xxxxxxxxxx
1
2
.datatable-inner.table-responsive {
3
overflow: visible !important;
4
}
5
6
.dropdown-menu.show {
7
z-index: 9999 !important;
8
}
xxxxxxxxxx
1
const basicData = {
2
columns: ['Name', 'Position', 'Office', 'Age', 'Start date', 'Salary'],
3
rows: [
4
["Tiger Nixon", "System Architect", "Edinburgh", "61", "2011/04/25", "$320,800"],
5
].map(row => {
6
const name = row.shift()
7
var dropdownItems = ""
8
row.map(item => {
9
dropdownItems += `<li class="dropdown-item">${item}</li>`;
10
})
11
const dropdown = `
12
<div class="d-flex">
13
<a
14
class="dropdown-toggle"
15
type="button"
16
id="dropdownMenuButton"
17
data-mdb-toggle="dropdown"
18
aria-expanded="false"
19
>
20
${name}
21
</a>
22
<ul class="dropdown-menu" aria-labelledby="dropdownMenuButton">
23
${dropdownItems}
24
</ul>
25
</div>`;
26
return [dropdown, ...row];
27
}),
28
};
29
30
const datatable = document.getElementById('datatable');
31
32
new mdb.Datatable(datatable, basicData);
33
34
datatable.addEventListener('selectRows.mdb.datatable', e => {
35
console.log(e.selectedRows, e.selectedIndexes, e.allSelected);
36
})
37
38
document.querySelectorAll('tr').forEach((row)=>{
39
row.querySelectorAll('td').forEach((field)=>{
40
if (field.innerHTML==='Tiger Nixon'){
41
row.querySelector('input').checked = true
42
}
43
})
44
})
Console errors: 0