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)文章
基于Javascript實現(xiàn)文件實時加載進度的方法
不知道大家有沒有發(fā)現(xiàn)在現(xiàn)在的移動頁面上,有很多情況需要加載大量的資源。但是移動端的訪問速度和pc還是有很大的差距,有些時候需要一些取巧的方式來提升用戶體驗,而實時顯示加載進度就是其中一種。這篇文章就給大家分享了Javascript實現(xiàn)文件實時加載進度的方法。2016-10-10JavaScript設(shè)計模式之裝飾者模式定義與應(yīng)用示例
這篇文章主要介紹了JavaScript設(shè)計模式之裝飾者模式定義與應(yīng)用,結(jié)合實例形式分析了JavaScript裝飾者模式的原理、定義及應(yīng)用方法,需要的朋友可以參考下2018-07-07JavaScript中Object.values()的用法舉例
這篇文章主要給大家介紹了關(guān)于JavaScript中Object.values()的用法舉例,Object.values()是JavaScript中一個內(nèi)置的靜態(tài)函數(shù),用于返回一個對象中所有屬性值的數(shù)組,需要的朋友可以參考下2023-09-09