使用vue和datatables進(jìn)行表格的服務(wù)器端分頁(yè)實(shí)例代碼
想法很簡(jiǎn)單,用vue生成表格的行,datatables生成分頁(yè)信息,不想過程曲折,特此記錄。
datatables端代碼:
$('#dataTables-example').DataTable({
responsive: true,
"serverSide" : true,
"ajax": function (data, callback, settings) {
postJson(
"/AccessControlSystem/user/selectByPrimary",
{'pageSize':data.length,'pageNo':data.start/data.length+1},
function(result){
callback({'draw':data.draw,'recordsTotal':userCount,'recordsFiltered':userCount,'data':[]});
$("#userList").html("");
getRoleForUser(result.data);
rendorUserList(result.data);
}
);
}
});
vue端代碼:
//用戶列表
var UserListComponent = Vue.extend({
template:
`<tbody id="userList">
<tr v-for="(user, index) in userList" v-bind:class="index%2==0?'odd':'even'">
<td>{{user.name}}</td>
<td>
<label v-for="role in user.roleList" class="checkbox-inline">
<input type="checkbox" v-bind:value="role.id" disabled v-model="role.checked">{{role.name}}
</label>
</td>
<td>{{user.createTime}}</td>
<td class="center"><button type="button" class="btn btn-primary btn-xs" v-on:click="editUser(user.id)">修改</button></td>
<td class="center"><button type="button" class="btn btn-primary btn-xs" v-on:click="deleteUser(user.id)">刪除</button></td>
</tr>
</tbody>`,
data: function () {
return {'userList':[]};
},
methods: {
editUser:function(id){},
deleteUser:function(id){}
}
});
function rendorUserList(userList){
var userListComponent = new UserListComponent();
userListComponent.userList = userList;
userListComponent.$mount('#userList');
}
重點(diǎn)在rendorUserList函數(shù)中,每次生成表格行不能復(fù)用已有的vue實(shí)例,需要先destroy,再重新生成vue實(shí)例,否則無法正常顯示第1頁(yè)后面的頁(yè)。
不知為何,希望懂原理的高手告知。
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- Vue+ElementUI table實(shí)現(xiàn)表格分頁(yè)
- Vue+element-ui 實(shí)現(xiàn)表格的分頁(yè)功能示例
- 利用vue和element-ui設(shè)置表格內(nèi)容分頁(yè)的實(shí)例
- 利用vue + element實(shí)現(xiàn)表格分頁(yè)和前端搜索的方法
- Vue Cli與BootStrap結(jié)合實(shí)現(xiàn)表格分頁(yè)功能
- vue.js表格分頁(yè)示例
- 基于Vue.js的表格分頁(yè)組件
- Vue+Element UI+Lumen實(shí)現(xiàn)通用表格分頁(yè)功能
- Vue組件庫(kù)ElementUI實(shí)現(xiàn)表格列表分頁(yè)效果
相關(guān)文章
如何修改element-ui日期下拉框datetimePicker的背景色樣式
這篇文章主要介紹了修改element-ui日期下拉框datetimePicker的背景色樣式的操作代碼,本文給大家介紹的非常詳細(xì),感興趣的朋友跟隨小編一起看看吧2024-07-07
vue props default Array或是Object的正確寫法說明
這篇文章主要介紹了vue props default Array或是Object的正確寫法說明,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2020-07-07
vue router 跳轉(zhuǎn)時(shí)打開新頁(yè)面的示例方法
這篇文章主要介紹了vue router 跳轉(zhuǎn)時(shí)打開新頁(yè)面的示例方法,本文通過示例代碼給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2019-07-07
vue-cli3+ts+webpack實(shí)現(xiàn)多入口多出口功能
這篇文章主要介紹了vue-cli3+ts+webpack實(shí)現(xiàn)多入口多出口功能,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2019-05-05
Element中table組件按照屬性執(zhí)行合并操作詳解
在我們?nèi)粘i_發(fā)中,表格業(yè)務(wù)基本是必不可少的,對(duì)于老手來說確實(shí)簡(jiǎn)單,家常便飯罷了,但是對(duì)于新手小白如何最快上手搞定需求呢?本文從思路開始著手,幫你快速搞定表格2022-11-11
從0搭建Vue3組件庫(kù)如何使用?glup?打包組件庫(kù)并實(shí)現(xiàn)按需加載
這篇文章主要介紹了從0搭建Vue3組件庫(kù)如何使用?glup?打包組件庫(kù)并實(shí)現(xiàn)按需加載,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2023-03-03
Vue.js+HighCharts實(shí)現(xiàn)動(dòng)態(tài)請(qǐng)求展示時(shí)序數(shù)據(jù)
這篇文章主要為大家詳細(xì)介紹了Vue.js+HighCharts實(shí)現(xiàn)動(dòng)態(tài)請(qǐng)求展示時(shí)序數(shù)據(jù),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-03-03

