我正在使用带有 vuejs 的 jquery-datatables。一切似乎都运行良好,但是当我尝试获取超过 500 条记录时,它会显示所有记录,但过滤器不起作用,并且表格顶部显示文本“表中没有可用数据”,然后显示所有记录。任何帮助将不胜感激。
这是代码:
<template>
<div>
<div class="content">
<div class="row">
<div class="col-sm-12">
<div class="card">
<div class="card-header">
<h4 class="card-title">Products</h4>
</div>
<div class="card-body">
<table class="table table-striped walla">
<thead>
<tr>
<th>#</th>
<th>Name</th>
<th>Category</th>
<th>Price</th>
<th>Quantity</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<tr v-for="product in tableData" :key="product.id">
<td>{{product.id}}</td>
<td>{{product.name}}</td>
<td>{{product.category}}</td>
<td>{{product.price | currency}}</td>
<td>{{product.quantity}}</td>
<td>
<button class="btn btn-success btn-sm" @click="editMode(product)"><i
class="fa fa-edit"></i></button>
<button class="btn btn-danger btn-sm" @click="deleteProduct(product.id)"><i
class="fa fa-trash"></i></button>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
</template>
<script>
export default {
data() {
return {
tableData: [],
add_product: false,
editing: false
}
},
created() {
this.initDatatable();
this.getProducts();
},
methods: {
getProducts() {
axios.get('products')
.then(res => this.tableData = res.data)
.catch(error => Exception.handle(error))
},
deleteProduct(id) {
axios.delete(`products/${id}`)
.then(res => {
for (let i = 0; i < this.tableData.length; i++) {
if (this.tableData[i].id == res.data) {
this.tableData.splice(i, 1);
}
}
})
.catch(error => console.log(error.response))
},
initDatatable() {
$('.walla').DataTable({
"pagingType": "full_numbers",
"lengthMenu": [
[10, 25, 50, -1],
[10, 25, 50, "All"]
],
order: [[0, 'asc'], [3, 'desc']],
responsive: true,
destroy: true,
retrieve: true,
autoFill: true,
colReorder: true,
});
},
editMode(product) {
this.$store.dispatch('updateProduct', product)
.then(() => {
this.editing = true;
this.add_product = true;
})
}
},
}
</script>