bootstrap table復(fù)雜操作代碼
本文實例為大家分享了bootstrap table復(fù)雜操作,如何生成外層表格,如何填充表格內(nèi)容,供大家參考,具體內(nèi)容如下
1、先生成外層表格:

$('#tableActivity').bootstrapTable('destroy').bootstrapTable({
url:'',
detailView:true,
detailFormatter:"detailFormatter",//點擊展開預(yù)先執(zhí)行事件
cache: false,
height: 550,
showExport: true,
exportDataType: "all",
pagination: true,
pageSize: 10,
pageList: [10, 25, 50, 100],
search: true,
searchAlign:'left',
showRefresh: true,
showToggle: true,
showColumns: true,
toolbarAlign: 'right',
toolbar:"#toolbar",
buttonsAlign:'left',
clickToSelect: true,
idField:'',
columns: [
[
{
title:'編號',
field: 'index',
rowspan: 2,
align: 'center',
valign: 'middle'
}, {
title: '姓名',
field: 'userName',
rowspan: 2,
align: 'center',
valign: 'middle',
sortable: true
}, {
title: '講義',
colspan: 3,
align: 'center'
}, {
title: '視頻',
colspan: 3,
align: 'center'
}, {
title: '總完成情況',
colspan: 3,
align: 'center'
}
],
[
{
field: 'handoutCount',
title: '講義總數(shù)',
sortable: true,
align: 'center'
}, {
field: 'handoutComCount',
title: '完成數(shù)',
sortable: true,
align: 'center'
}, {
field: 'handoutCountDegree',
title: '完成率',
sortable: true,
align: 'center'
}, {
field: 'videoCount',
title: '視頻總數(shù)',
sortable: true,
align: 'center'
}, {
field: 'videoComCount',
title: '完成數(shù)',
sortable: true,
align: 'center'
}, {
field: 'videoCountDegree',
title: '完成率',
sortable: true,
align: 'center'
}, {
field: 'allCount',
title: '總數(shù)',
sortable: true,
align: 'center'
}, {
field: 'allComCount',
title: '總完成數(shù)',
sortable: true,
align: 'center'
}, {
field: 'allDegree',
title: '總完成率',
sortable: true,
align: 'center'
}
]
]
});
2、生成展開之后的表格內(nèi)容:
function detailFormatter(index, row) {
handoutColums=[];
handoutData=[];
videoColums=[];
videoData=[];
var html = [];
html.push('<div class="row">');
html.push('<div class="col-md-6">');
html.push('<table id="tableHandout'+index+'"></table>');
html.push('</div>');
html.push('<div class="col-md-6">');
html.push('<table id="tableVideo'+index+'"></table>');
html.push('</div>');
html.push('</div>');
handoutColums.push({
field: 'handoutIndex',title: '編號', sortable: true ,width: 150
},{
field: 'handoutName',title: '講義名稱', sortable: true ,width: 150
},{
field: 'degree',title: '完成度', sortable: true ,width: 150
});
videoColums.push({
field: 'videoIndex',title: '編號', sortable: true ,width: 150
},{
field: 'videoName',title: '視頻名稱', sortable: true ,width: 150
},{
field: 'degree',title: '完成度', sortable: true ,width: 150
});
$.each(row, function (key, value) {
if(key=="handout"){
$.each(value,function(index,handout){
var row = {};
row['handoutIndex'] = index+1;
row['handoutName']=handout.handoutName;
row['degree']=handout.degree;
handoutData.push(row);
});
}
if(key=="video"){
$.each(value,function(index,video){
var row = {};
row['videoIndex']=index+1;
row['videoName']=video.videoName;
row['degree']=video.degree;
videoData.push(row);
});
}
});
return html.join('');
}
3、填充表格內(nèi)容:
$('#tableActivity').on('expand-row.bs.table', function (e, index, row, $detail) {
initHandoutTable(handoutColums,handoutData,index);
initVideoTable(videoColums,videoData,index);
});
function initHandoutTable(colums,data,index){
$('#tableHandout'+index).bootstrapTable('destroy').bootstrapTable({
cache: false,
height: 200,
clickToSelect: true,
idField:'',
columns:colums,
data:data
});
}
function initVideoTable(colums,data,index){
$('#tableVideo'+index).bootstrapTable('destroy').bootstrapTable({
cache: false,
height: 200,
clickToSelect: true,
idField:'',
columns:colums,
data:data
});
}

如果大家還想深入學(xué)習(xí),可以點擊這里進行學(xué)習(xí),再為大家附兩個精彩的專題:Bootstrap學(xué)習(xí)教程 Bootstrap實戰(zhàn)教程 Bootstrap插件使用教程
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
js中數(shù)組解構(gòu)與對象解構(gòu)示例代碼
數(shù)組解構(gòu)是一種在 JavaScript 中從數(shù)組中提取值并將它們分配給變量的方式,在數(shù)組解構(gòu)中分為完全解構(gòu),不完全解構(gòu),解構(gòu)失敗以及解構(gòu)默認值,這篇文章主要介紹了js中數(shù)組解構(gòu)與對象解構(gòu),需要的朋友可以參考下2023-09-09
element plus表格的表頭和內(nèi)容居中的實現(xiàn)代碼
這篇文章主要介紹了element plus表格的表頭和內(nèi)容居中的實現(xiàn)代碼,本文給大家介紹的非常詳細,對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友參考下吧2024-01-01
fckeditor部署到weblogic出現(xiàn)xml無法讀取及樣式不能顯示問題的解決方法
這篇文章主要介紹了fckeditor部署到weblogic出現(xiàn)xml無法讀取及樣式不能顯示問題的解決方法,分析了問題出現(xiàn)的原因及相關(guān)配置文件設(shè)置技巧,需要的朋友可以參考下2017-03-03
微信小程序 數(shù)據(jù)緩存實現(xiàn)方法詳解
這篇文章主要介紹了微信小程序 數(shù)據(jù)緩存實現(xiàn)方法詳解,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下2019-08-08
Quasar Input:type="number" 去掉上下小箭頭 實現(xiàn)加減按鈕樣式功能
這篇文章主要介紹了Quasar Input:type="number" 去掉上下小箭頭 實現(xiàn)加減按鈕樣式,本文通過實例代碼給大家介紹的非常詳細,對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2020-04-04

