I'm trying to fill a datatable using vuejs v-for directive and ajax to get the data but the table is always showing "No data available in table" even though there are some data shown and also in the bottom says "Showing 0 to 0 of 0 entries". I guess this is because vuejs is reactive and the table can't recognize the changes maybe? I've been searching and trying for a while but with no solution found..
thanks a lot! :)
here's the template:
<div class="row">
<div class="col-sm-12">
<div class="box box-color box-bordered">
<div class="box-title">
<h3>
<i class="fa fa-table"></i>
</h3>
</div>
<div class="box-content nopadding">
<table id="suppliersTable" class="table table-hover table-nomargin table-bordered dataTable">
<thead>
<tr>
<th>Supplier #</th>
<th>Company</th>
<th class='hidden-1024'>Email</th>
<th class='hidden-480'>Phone</th>
<th class='hidden-480'>Fax</th>
<th class='hidden-480'>Mobile</th>
<th class='hidden-480'>City</th>
<th class='hidden-480'>Street</th>
<th class='hidden-480'>Postal Code</th>
<th class='hidden-480'>CR</th>
<th class='hidden-480'>Website</th>
<th class='hidden-480'>Notes</th>
</tr>
</thead>
<tbody>
<tr class="template" v-for="supplier in suppliers">
<td class='verticalAlignMiddle'>{{ supplier.Supplier_ID }}</td>
<td class='verticalAlignMiddle'>{{ supplier.Company }}</td>
<td class='verticalAlignMiddle hidden-1024'>{{ supplier.Email }}</td>
<td class='verticalAlignMiddle hidden-480'>{{ supplier.Phone }}</td>
<td class='verticalAlignMiddle hidden-480'>{{ supplier.Fax }}</td>
<td class='verticalAlignMiddle hidden-480'>{{ supplier.Mobile }}</td>
<td class='verticalAlignMiddle hidden-480'>{{ supplier.City_ID }}</td>
<td class='verticalAlignMiddle hidden-480'>{{ supplier.Street }}</td>
<td class='verticalAlignMiddle hidden-480'>{{ supplier.Postal_Code }}</td>
<td class='verticalAlignMiddle hidden-480'>{{ supplier.CR }}</td>
<td class='verticalAlignMiddle hidden-480'>{{ supplier.Website }}</td>
<td class='verticalAlignMiddle hidden-480'>{{ supplier.Notes }}</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
and the vue and ajax:
<script>
export default {
data() {
return {
suppliers: [],
}
},
methods: {
fetchSuppliers() {
this.$http.get('http://localhost/curemodules/public/suppliers/list')
.then(response => {
this.suppliers = JSON.parse(response.bodyText).data;
});
}
},
created() {
this.fetchSuppliers();
},
}