antdv scopedSlots 动态合并表格行 customCell

1,097 阅读1分钟

antdv,在a-table表格中使用插槽,并且需要根据某一字段值的异同动态合并行,但是使用customRender合并却出现了问题。

根据需求写代码的时候,遇到了上面的问题。

搜索了一大圈,终于找到了一篇有用的文章,使用customCell来合并行,解决了问题。真心感谢大佬!blog.csdn.net/chenyuhang_…

const customCell = (record) => {
    var numrow = 1;
    if (record.rowNum) {
        numrow = record.rowNum
    } else {
        numrow = 0
    }
    record.row = numrow;
    return {
        style: {
            display: record.row === 0 ? 'none' : undefined,
        },
        //rowSpan行合并
        attrs: {
            rowSpan: numrow,
        }
    }
};
const columns = [
    。。。。。。
    {
        title: "风险等级",
        dataIndex: "riskLevel",
        width: 150,
        scopedSlots: {
            customRender: 'riskSlot',
        },
        customCell: customCell
    }
]