HTML
1
1
SCSS
xxxxxxxxxx
1
<style>
2
#app {
3
font-family: Roboto, Helvetica, Arial, sans-serif;
4
}
5
</style>
JS
xxxxxxxxxx
1
<template>
2
<MDBBtn @click="reloadDataset9" color="primary" class="mb-4">
3
Reload data
4
<MDBIcon icon="sync" class="ms-2" />
5
</MDBBtn>
6
<MDBDatatable :dataset="dataset9" :loading="loading9" @render="setActions" />
7
</template>
8
9
<script>
10
import { ref } from "vue";
11
import { MDBDatatable, MDBBtn, MDBIcon } from "mdb-vue-ui-kit";
12
13
export default {
14
name: "UsersDashboard",
15
components: {
16
MDBDatatable,
17
MDBBtn,
18
MDBIcon
19
},
20
setup() {
21
const dataset9 = ref({
22
columns: [
23
{ label: "ID", field: "userId" },
24
{ label: "Email", field: "email" },
25
{ label: "First Name", field: "firstName" },
26
{ label: "Last Name", field: "lastName" },
27
{ label: "Phone", field: "phone" },
28
{ label: "Contact", field: "contact", sort: false},
29
]
30
});
31
const loading9 = ref(false);
32
const reloadDataset9 = () => {
33
dataset9.value.rows = [];
34
loading9.value = true;
35
36
// timeout is for demonstration purposes only
37
setTimeout(() => {
38
fetch("http://localhost:8082/users")
39
.then(response => response.json())
40
.then(data => {
41
dataset9.value.rows = data.map(user => ({
42
...user,
43
// address: `${user.address.city}, ${user.address.street}`,
44
// company: user.company.name
45
contact: `
46
<button class="call-btn btn btn-outline-primary btn-floating btn-sm" data-mdb-user="${user.userId}"><i class="fa fa-phone"></i></button>
47
`
48
}));
49
loading9.value = false;
50
});
51
}, 2000);
52
};
53
54
const setActions = () => {
55
document.getElementsByClassName("call-btn").forEach(btn => {
56
btn.addEventListener("click", () => {
57
//console.log(`call ${btn.attributes["data-mdb-user"].value}`);
58
console.log(`call ${btn.attributes["data-mdb-user"].value}`);
59
});
60
});
61
};
62
63
return {
64
dataset9,
65
loading9,
66
reloadDataset9,
67
setActions,
68
};
69
}
70
};
71
</script>
72
73
<style scoped>
74
75
</style>
Console errors: 0