vue element實現(xiàn)表格合并行數(shù)據(jù)
本文實例為大家分享了vue element實現(xiàn)表格合并行數(shù)據(jù)的具體代碼,供大家參考,具體內(nèi)容如下
支持不分頁的表格數(shù)據(jù),分頁的表格數(shù)據(jù)還有小bug
<template> <el-container> <el-main> <el-table :data='tableData' border :span-method='objectSpanMethod' //添加這個實現(xiàn)行數(shù)據(jù)合并 > <el-table-column label='序號' prop='id' align='center'></el-table-column> <el-table-column label='名字' prop='screenName' align='center'></el-table-column> <el-table-column label='時間1' prop='startTime' align='center'></el-table-column> <el-table-column label='時間2' prop='endTime' align='center'></el-table-column> </el-table> </el-main> </el-container></template><script>export default { name: 'Formtableyes', data() { return { //合并行 spanArr: [], //聲明一個數(shù)組 tableData: [ { id: 1, screenName: 'LHC', startTime: '12', endTime: '1231' }, { id: 1, screenName: 'LHC', startTime: '12', endTime: '123' } ] }; }, mounted: function() { this.tableDatas(); //加載數(shù)據(jù)就調(diào)用該方法 }, methods: { objectSpanMethod({ row, column, rowIndex, columnIndex }) { if (columnIndex === 0) { //合并第一列 const _row = this.spanArr[rowIndex]; const _col = _row > 0 ? 1 : 0; return { rowspan: _row, colspan: _col }; } if (columnIndex === 1) { //合并第二列 const _row = this.spanArr[rowIndex]; const _col = _row > 0 ? 1 : 0; return { rowspan: _row, colspan: _col }; } // if (columnIndex === 2) { //合并第三列 // const _row = this.spanArr[rowIndex]; // const _col = _row > 0 ? 1 : 0; // return { // rowspan: _row, // colspan: _col // }; // } }, tableDatas() { let contactDot = 0; this.tableData.forEach((item, index) => { item.index = index; if (index === 0) { this.spanArr.push(1); } else { if (item.id === this.tableData[index - 1].id) { this.spanArr[contactDot] += 1; this.spanArr.push(0); } else { this.spanArr.push(1); contactDot = index; } } }); }, }};</script><style scoped>.ptselect { width: 100%;}</style>
效果如下:
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持好吧啦網(wǎng)。
相關(guān)文章:
1. IntelliJ IDEA設(shè)置默認瀏覽器的方法2. HTTP協(xié)議常用的請求頭和響應(yīng)頭響應(yīng)詳解說明(學(xué)習(xí))3. idea設(shè)置提示不區(qū)分大小寫的方法4. docker容器調(diào)用yum報錯的解決辦法5. VMware中如何安裝Ubuntu6. CentOS郵件服務(wù)器搭建系列—— POP / IMAP 服務(wù)器的構(gòu)建( Dovecot )7. .NET SkiaSharp 生成二維碼驗證碼及指定區(qū)域截取方法實現(xiàn)8. IntelliJ IDEA創(chuàng)建web項目的方法9. django創(chuàng)建css文件夾的具體方法10. ASP.NET MVC通過勾選checkbox更改select的內(nèi)容
