xxxxxxxxxx
1
<div class="input-group">
2
<input type="text" id='input1' placeholder='name' aria-label="First name" class="form-control" />
3
<input type="text" id='input2' placeholder='position' aria-label="First name" class="form-control" />
4
<input type="text" id='input3' placeholder='office' aria-label="First name" class="form-control" />
5
<input type="text" id='input4' placeholder='age' aria-label="First name" class="form-control" />
6
</div>
7
8
<div id="datatable"></div>
9
10
xxxxxxxxxx
1
.form-outline {
2
width: 200px;
3
}
xxxxxxxxxx
1
const data = {
2
columns: [
3
{
4
label: 'Name',
5
field: 'name'
6
},
7
{
8
label: 'Position',
9
field: 'position'
10
},
11
{
12
label: 'Office',
13
field: 'office'
14
},
15
// every column must be an object, otherwise search won't work!
16
"Age",
17
// {
18
// label: 'Age',
19
// field: 'age'
20
// },
21
'Start date',
22
'Salary',
23
],
24
rows: [
25
["Tiger Nixon", "System Architect", "Edinburgh", "61", "2011/04/25", "$320,800"],
26
["Garrett Winters", "Accountant", "Tokyo", "63", "2011/07/25", "$170,750"],
27
["Ashton Cox", "Junior Technical Author", "San Francisco", "66", "2009/01/12", "$86,000"],
28
["Cedric Kelly", "Senior Javascript Developer", "Edinburgh", "22", "2012/03/29", "$433,060"],
29
["Airi Satou", "Accountant", "Tokyo", "33", "2008/11/28", "$162,700"],
30
["Brielle Williamson", "Integration Specialist", "New York", "61", "2012/12/02", "$372,000"],
31
["Herrod Chandler", "Sales Assistant", "San Francisco", "59", "2012/08/06", "$137,500"],
32
["Rhona Davidson", "Integration Specialist", "Tokyo", "55", "2010/10/14", "$327,900"],
33
["Colleen Hurst", "Javascript Developer", "San Francisco", "39", "2009/09/15", "$205,500"],
34
["Sonya Frost", "Software Engineer", "Edinburgh", "23", "2008/12/13", "$103,600"],
35
["Jena Gaines", "Office Manager", "London", "30", "2008/12/19", "$90,560"],
36
["Quinn Flynn", "Support Lead", "Edinburgh", "22", "2013/03/03", "$342,000"],
37
["Charde Marshall", "Regional Director", "San Francisco", "36", "2008/10/16", "$470,600"],
38
["Haley Kennedy", "Senior Marketing Designer", "London", "43", "2012/12/18", "$313,500"]
39
],
40
};
41
42
const allInputs = document.querySelectorAll('input')
43
const instance = new mdb.Datatable(document.getElementById('datatable'), data)
44
const advancedSearchInput = document.getElementById('advanced-search-input');
45
46
allInputs.forEach((input) => {
47
input.addEventListener('keyup', () => {
48
instance.search(input.value, input.placeholder)
49
})
50
})
51
52
53
Console errors: 0