xxxxxxxxxx
1
<div class="d-flex justify-content-end mb-4">
2
<div data-mdb-input-init class="form-outline">
3
<input
4
data-mdb-search
5
data-mdb-target="#table_modal"
6
type="text"
7
id="search_modal"
8
class="form-control"
9
/>
10
<label class="form-label" for="search_modal">Search</label>
11
</div>
12
<button data-mdb-ripple-init class="btn btn-primary btn-sm ms-3" data-mdb-add-entry data-mdb-target="#table_modal">
13
<i class="fa fa-plus"></i>
14
</button>
15
</div>
16
<hr />
17
<div id="table_modal"></div>
xxxxxxxxxx
1
.table-editor_input-wrapper[data-mdb-field="id"] {
2
display: none;
3
}
xxxxxxxxxx
1
const advancedColumns = [
2
{
3
width: 50,
4
label: 'id',
5
field: 'id',
6
},
7
{
8
width: 100,
9
label: 'Company',
10
field: 'company',
11
},
12
{
13
width: 50,
14
sort: false,
15
defaultValue: 'Warsaw',
16
options: ['London', 'Warsaw', 'New York'],
17
inputType: 'select',
18
label: 'Office',
19
field: 'office',
20
},
21
{
22
width: 100,
23
inputType: 'number',
24
defaultValue: 1,
25
label: 'Employees',
26
field: 'employees',
27
},
28
{
29
width: 100,
30
defaultValue: false,
31
inputType: 'checkbox',
32
label: 'International',
33
field: 'international',
34
},
35
];
36
37
const advancedRows = [
38
{
39
id: 1,
40
company: 'A. Jonson Gallery',
41
office: 'London',
42
employees: 4,
43
international: false,
44
},
45
{
46
id: 2,
47
company: 'F.A. Architects',
48
office: 'London',
49
employees: 4,
50
international: false,
51
},
52
];
53
const options = {
54
mode: 'modal',
55
entries: 5,
56
entriesOptions: [5, 10, 15]
57
}
58
let id = 2;
59
const tableEl = document.getElementById('table_modal');
60
const tableModal = new TableEditor(
61
tableEl,
62
{ columns: advancedColumns, rows: advancedRows },
63
options
64
);
65
66
tableEl.addEventListener('add.mdb.tableEditor', (e) => {
67
console.log(e.row)
68
if (!e.row.id) {
69
e.preventDefault();
70
}
71
72
const idInput = document.querySelector('.table-editor_input-wrapper[data-mdb-field="id"] .table-editor__input')
73
id += 1;
74
idInput.value = id;
75
idInput.dispatchEvent(new Event('input'))
76
document.querySelector('.modal-save-button').click();
77
78
})
79
Console errors: 0