xxxxxxxxxx
1
<div class="form-outline mb-4">
2
<input
3
type="text"
4
class="form-control"
5
id="datatable-search-input"
6
/>
7
<label class="form-label" for="datatable-search-input">Search</label>
8
</div>
9
<div id="datatable">
10
</div>
1
1
xxxxxxxxxx
1
const data = {
2
columns: [
3
{ label: 'Name', field: 'name' },
4
'Position',
5
'Office',
6
],
7
rows: [
8
["Tiger Nixon", "System Architect", "Edinburgh", "61", "2011/04/25", "$320,800"],
9
["Garrett Winters", "Accountant", "Tokyo", "63", "2011/07/25", "$170,750"],
10
["Ashton Cox", "Junior Technical Author", "San Francisco", "66", "2009/01/12", "$86,000"],
11
["Cedric Kelly", "Senior Javascript Developer", "Edinburgh", "22", "2012/03/29", "$433,060"],
12
["Airi Satou", "Accountant", "Tokyo", "33", "2008/11/28", "$162,700"],
13
["Brielle Williamson", "Integration Specialist", "New York", "61", "2012/12/02", "$372,000"],
14
["Herrod Chandler", "Sales Assistant", "San Francisco", "59", "2012/08/06", "$137,500"],
15
["Rhona Davidson", "Integration Specialist", "Tokyo", "55", "2010/10/14", "$327,900"],
16
["Colleen Hurst", "Javascript Developer", "San Francisco", "39", "2009/09/15", "$205,500"],
17
["Sonya Frost", "Software Engineer", "Edinburgh", "23", "2008/12/13", "$103,600"],
18
["Jena Gaines", "Office Manager", "London", "30", "2008/12/19", "$90,560"],
19
["Quinn Flynn", "Support Lead", "Edinburgh", "22", "2013/03/03", "$342,000"],
20
["Charde Marshall", "Regional Director", "San Francisco", "36", "2008/10/16", "$470,600"],
21
["Haley Kennedy", "Senior Marketing Designer", "London", "43", "2012/12/18", "$313,500"]
22
],
23
};
24
25
const instance = new mdb.Datatable(document.getElementById('datatable'), data)
26
27
document.getElementById('datatable-search-input').addEventListener('input', (e) => {
28
instance.search(e.target.value);
29
const td = document.querySelector('td')
30
if (td.innerText === "No matching results found"){
31
td.setAttribute('colspan', 3)
32
td.style.textAlign = 'center'
33
}
34
});
Console errors: 0