xxxxxxxxxx
1
<div class="input-group mb-4">
2
<input type="text" class="form-control" id="datatable-search-input"/>
3
<button class="btn btn-primary" id="datatable-search-button" type="button">
4
<i class="fa fa-search"></i>
5
</button>
6
</div>
7
<div id="datatable">
8
</div>
1
1
xxxxxxxxxx
1
const data = {
2
columns: [
3
{
4
label: 'Name',
5
field: 'name'
6
},
7
'Position',
8
'Office',
9
'Age',
10
'Start date',
11
'Salary',
12
],
13
rows: [
14
["Tiger Nixon", "System Architect", "Edinburgh", "61", "2011/04/25", "$320,800"],
15
["Garrett Winters", "Accountant", "Tokyo", "63", "2011/07/25", "$170,750"],
16
["Ashton Cox", "Junior Technical Author", "San Francisco", "66", "2009/01/12", "$86,000"],
17
["Cedric Kelly", "Senior Javascript Developer", "Edinburgh", "22", "2012/03/29", "$433,060"],
18
["Airi Satou", "Accountant", "Tokyo", "33", "2008/11/28", "$162,700"],
19
["Brielle Williamson", "Integration Specialist", "New York", "61", "2012/12/02", "$372,000"],
20
["Herrod Chandler", "Sales Assistant", "San Francisco", "59", "2012/08/06", "$137,500"],
21
["Rhona Davidson", "Integration Specialist", "Tokyo", "55", "2010/10/14", "$327,900"],
22
["Colleen Hurst", "Javascript Developer", "San Francisco", "39", "2009/09/15", "$205,500"],
23
["Sonya Frost", "Software Engineer", "Edinburgh", "23", "2008/12/13", "$103,600"],
24
["Jena Gaines", "Office Manager", "London", "30", "2008/12/19", "$90,560"],
25
["Quinn Flynn", "Support Lead", "Edinburgh", "22", "2013/03/03", "$342,000"],
26
["Charde Marshall", "Regional Director", "San Francisco", "36", "2008/10/16", "$470,600"],
27
["Haley Kennedy", "Senior Marketing Designer", "London", "43", "2012/12/18", "$313,500"]
28
],
29
};
30
const input = document.getElementById('datatable-search-input')
31
const instance = new mdb.Datatable(document.getElementById('datatable'), data)
32
33
const search = async (value) => {
34
instance.update(
35
{ rows: [] },
36
{ loading: true }
37
);
38
39
// your search here
40
41
await setTimeout(() => {
42
instance.update(
43
{ rows: data.rows },
44
{ loading: false }
45
)
46
}, 2000)
47
}
48
49
document.getElementById('datatable-search-button').addEventListener('click', (e) => {
50
search();
51
});
52
53
input.addEventListener('keydown', (e) => {
54
if (e.keyCode === 13) {
55
search(e.target.value);
56
}
57
})
Console errors: 0