国产成人精品亚洲777人妖,欧美日韩精品一区视频,最新亚洲国产,国产乱码精品一区二区亚洲

您的位置:首頁技術(shù)文章
文章詳情頁

vue element實現(xiàn)表格合并行數(shù)據(jù)

瀏覽:147日期:2022-10-22 15:37:19

本文實例為大家分享了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>

效果如下:

vue element實現(xiàn)表格合并行數(shù)據(jù)

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持好吧啦網(wǎng)。

標簽: Vue
相關(guān)文章:
主站蜘蛛池模板: 如皋市| 灵石县| 双城市| 商洛市| 萨迦县| 珲春市| 甘谷县| 大邑县| 搜索| 婺源县| 行唐县| 鹿邑县| 阳朔县| 安溪县| 全椒县| 东乡| 托克逊县| 黑山县| 和龙市| 江孜县| 桑植县| 漳平市| 丰台区| 喀喇| 新竹县| 嘉定区| 弥勒县| 大石桥市| 嘉义县| 梅河口市| 田林县| 陆丰市| 临邑县| 利津县| 寻乌县| 大港区| 南召县| 台南市| 炎陵县| 富锦市| 茂名市|