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. java——Byte類/包裝類的使用說明2. android studio實現(xiàn)簡單的計算器(無bug)3. python 讀txt文件,按‘,’分割每行數(shù)據(jù)操作4. python Selenium 庫的使用技巧5. android 控件同時監(jiān)聽單擊和雙擊實例6. python+pywinauto+lackey實現(xiàn)PC端exe自動化的示例代碼7. vue使用exif獲取圖片經(jīng)緯度的示例代碼8. python logging.info在終端沒輸出的解決9. 詳解android adb常見用法10. Python 忽略文件名編碼的方法
