antdvue-Table首列合并

<a-table
                        :columns="noPmColumns"
                        :dataSource="sourceLeftData"
                        :loading="tableLoading"
                        :scroll="{  }"
                        rowKey="rowKeyInfo"
                        :showHeader="false"
                        :pagination="false"
                        size="middle"
                        bordered
                    >
                    </a-table>
noPmColumns:[
                {
                    title:"mpdGroup",
                    dataIndex:"mpdGroup",
                    width: 127,
                    align: "center",
                    customRender:(value, row, index)=>{
                        const obj = {
                            children: value,
                            attrs: {},
                        }; 
                        obj.attrs.rowSpan = row.mergeRowSpan;         
                        return obj
                    }
                },
                {
                    title:"eqpId",
                    dataIndex:"eqpId",
                    width: 127,
                    align: "center",
                },
                {
                    title:"chamberList",
                    dataIndex:"chamberList",
                    scopedSlots: { customRender: "action" },
                    align: "center",
                    customCell:function(record,index){
                        return {
                            style:{
                                padding:'1px !important'
                            }
                        }
                    }
                },
            ],
            sourceLeftData:[],

合并第一列的方法:
在请求到接口的list数据后,调用rowSpan方法

//getData代表请求过来的list
//dataIndex代表每一行的第一列的key名称
rowSpan(getData,dataIndex) {
            //过滤合并后现实的表格内容
            let arr = getData
                .reduce((result, item) => {
                //不存在则放入展示结果
                if (result.indexOf(item[dataIndex]) < 0) {
                    result.push(item[dataIndex]);
                }
                return result;
                }, [])
                //确定每个合并的合并行数
                .reduce((result, keys) => {
                    //计算出可以合并的数据
                    const children = getData.filter((item) => item[dataIndex] === keys);
                    result = result.concat(
                    //计算出合并行数
                        children.map((item, index) => ({
                        ...item,
                        [`mergeRowSpan`]: index === 0 ? children.length : 0,
                        }))
                    );
                    return result;
                }, []);
                console.log("arr",arr);
                //将最后展示的数据替换原数据
            this.sourceLeftData = arr;
            
        },
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值