I want to create a reactive Datatable in my Laravel + Vue.js project. I'm using datatables.js
library to show my data. When I make an API call to get the data from db API returns me an array, so I want to populate that array in the datatable
. But it's working weird?
Here's API call:
methods: {
getUsers() {
axios.get('/api/users')
.then(response => {
if(response.status === 200) {
this.users = response.data.users;
console.log(this.users);
}
})
.catch(error => {
console.error(error);
});
}
},
mounted() {
$('#users-datatable-responsive').DataTable();
this.getUsers();
}
This is how I populating the data in the datatable
<tr v-for="user in users">
<td>@{{ user.fullname }}</td>
<td>@{{ user.phone }}</td>
<td>@{{ user.email }}</td>
</tr>
Searching and other features of a datatable aren't working. What's the workaround?
Edited:
mounted() {
let table = $('#users-datatable-responsive').DataTable({
language: this.dataTableOptions
});
this.getUsers();
table.rows().invalidate().draw();
}
This approach didn't work for me.