elementui table 固定列_elementUI Table组件 如何设置合并列

本文介绍了如何使用ElementUI的Table组件来设置固定列并实现列合并。通过示例代码展示了如何处理数据并结合`span-method`属性实现合并效果,确保在表格中有效地展示重复月份的信息。
摘要由CSDN通过智能技术生成

效果图:

52aaba8923c0

image.png

代码如下:

:data="tableData"

style="width:200px"

:border="true"

:span-method="objectSpanMethod"

>

prop="month"

label="月份"

>

prop="year"

label="年份"

>

export default {

data() {

return {

tableData: [{"attendTrainingPersonnel":"全区区管干部必学,鼓励其他干部选学","month":4,"teacherMisassignments":"中央党校(国家行政学院)李志勇","title":"关于国家治理现代化的几个问题","typeName":"十九届四中全会精神轮训","year":2020},{"attendTrainingPersonnel":"全区区管干部必学,鼓励其他干部选学","month":4,"teacherMisassignments":"中央党校(国家行政学院)李志勇","title":"关于国家治理现代化的几个问题","typeName":"十九届四中全会精神轮训","year":2020}]

}

},

mounted(){

let tableData = this.tableData;

let tempDetailslistMonth = {};

tableData.map(item => {

if(tempDetailslistMonth[item.month]){

tempDetailslistMonth[item.month]++;

item.showMonth = false;

return item;

}

else{

tempDetailslistMonth[item.month] = 1;

item.showMonth = true;

return item;

}

});

this.tempDetailslistMonth = tempDetailslistMonth;

},

methods : {

objectSpanMethod({ row, column, rowIndex, columnIndex }) {

//rowIndex:行 columnIndex:列

let {tableData} = this;

if(columnIndex == 0){ //只对第一列的数据(月份)可能进行合并列

// 如果这个月已经展示了,就不要再展示了

if(row.showMonth){

return {

rowspan : this.tempDetailslistMonth[tableData[rowIndex].month],

colspan: 1

}

}

else{

return {

rowspan : 0,

colspan: 0

}

}

}

}

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值