300字范文,内容丰富有趣,生活中的好帮手!
300字范文 > 单元格横向 纵向合并Vue

单元格横向 纵向合并Vue

时间:2020-05-31 03:32:43

相关推荐

单元格横向 纵向合并Vue

//页面table 加入方法<el-table :span-method="objectSpanMethod">// 将获取的数据进行合并this.getMergeObj(this.tableData);/*** 获取合并对象* @param {Object} list 列表*/getMergeObj (list) {this.mergeObj = {}// 标记let mack = 0for (let key in list[0]) {this.mergeObj[key] = []mack = 0list.forEach((item, index) => {if (index === 0) {this.mergeObj[key].push(1)} else {if (item[key] === list[index - 1][key] && item[key]) {this.mergeObj[key][mack] += 1this.mergeObj[key].push(0)} else {mack = indexthis.mergeObj[key].push(1)}}})}console.log('-合并对象:', this.mergeObj)},// 单元格合并 纵向及横向合并 lable = ‘targetName / targetChildren’objectSpanMethod({ row, column, rowIndex, columnIndex }) {let col = 1;if(row.targetName == row.targetChildren && column.property === 'targetName'){col = 2;}if (row.targetName == row.targetChildren && column.property === 'targetChildren'){col = 0;}// 需要合并的行if (column.property === 'targetName' || column.property === 'targetChildren') {return {rowspan: this.mergeObj[column.property][rowIndex],colspan: col}} else {return { rowspan: 1, colspan: 1 }}//row:行对象,带有一行所有数据,column:列对象//rowIndex:行索引,columnIndex:列索引//加载表格时从(0,0)开始,(0,1)···(1,0),(1,1)···依次获取数据if(columnIndex===2){//每次走到第3列时给单元格加上rowspan和colspan属性const _row = this.tableData[rowIndex];//从处理完的数组里获取const _col = _row>0?1:0;return {rowspan:_row,colspan:_col //相当于给给表格加上rowspan,colspan属性}}},

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。