多种情况下合并单元格(S-Table+Vue3)

合并单元格(S-Table+Vue3)

跨行合并:rowspan=“合并单元格的个数”
跨列合并:colspan="“合并单元格的个数”

第一列跨行合并单元格

template

<s-table
	ref="table"
	bordered
	:columns="columns"
	:data="loadData"
	:row-key="(record) => record.id"
	:scroll="{ x: 1500 }"
	:tool-config="toolConfig"
>
</s-table>

script

//初始化
	const columns = [
		{
			title: '姓名',
			dataIndex: 'name',
			key: 'name',
			customCell: (data) => {
				return { rowSpan: data.rowSpan || 0 }
			}
		},
		{
			title: '年龄',
			dataIndex: 'age',
			key: 'age'
		},
		{
			title: '住址',
			dataIndex: 'address',
			key: 'address'
		}
	]

const loadData = (parameter) => {
	return 方法.then((res) => {
		//设置假数据,如有可不设置
		res.records = [
					{
						key: 1,
						name: 'coisini',
						age: 24,
						address: '0510volleyball'
					},
					{
						key: 2,
						name: 'coisini',
						age: 245,
						address: '0510volleyballw'
					},
					{
						key: 3,
						name: '胡彦斌',
						age: 32,
						address: '西湖区湖底公园1号'
					},
					{
						key: 5,
						name: '胡彦斌',
						age: 32,
						address: '西湖区湖底公园1号'
					},
					{
						key: 4,
						name: '胡彦祖',
						age: 42,
						address: '西湖区湖底公园1号'
					},
					{
						key: 6,
						name: '胡彦祖',
						age: 42,
						address: '西湖区湖底公园1号'
					}
				]
				
		let startItem = res.records[0];
  		startItem.rowSpan = 1
  		res.records.forEach((item, index) => {
  			let nextItem = res.records[index + 1] || {};
			if (item['orgName'] === nextItem['orgName']) {
			   startItem.rowSpan++;
			} else {
			   startItem = nextItem;
			   startItem.rowSpan = 1;
			 }
		})
		return res
	})
	.catch((error) => {
		console.log(error)
	})
	.finally(() => {
		//...
	})
}

效果

在这里插入图片描述

多列跨行合并单元格

template

<s-table
	ref="table"
	bordered
	:columns="columns"
	:data="loadData"
	:row-key="(record) => record.id"
	:scroll="{ x: 1500 }"
	:tool-config="toolConfig"
>
</s-table>

script

	const columns = [
		{
			title: '姓名',
			dataIndex: 'name',
			key: 'name',
			customCell: (data) => {
				console.log(data, 'data')
				return { rowSpan: data.rowSpan || 0 }
			}
		},
		{
			title: '年龄',
			dataIndex: 'age',
			key: 'age',
			customCell: (data) => {
				console.log(data, 'data1')
				return { rowSpan: data.rowSpan1 || 0 }
			}
		},
		{
			title: '住址',
			dataIndex: 'address',
			key: 'address',
			customCell: (data) => {
				console.log(data, 'data2')
				return { rowSpan: data.rowSpan2 || 0 }
			}
		}
	]
	//loadData
const loadData = (parameter) => {
	return 方法.then((res) => {
		//设置假数据,如有可不设置
		res.records = [
					{
						key: 1,
						name: 'coisini',
						age: 24,
						address: '0510volleyball'
					},
					{
						key: 2,
						name: 'coisini',
						age: 245,
						address: '0510volleyballw'
					},
					{
						key: 3,
						name: '胡彦斌',
						age: 32,
						address: '西湖区湖底公园1号'
					},
					{
						key: 5,
						name: '胡彦斌',
						age: 321,
						address: '西湖区湖底公园1号'
					},
					{
						key: 4,
						name: '胡彦祖',
						age: 42,
						address: '西湖区湖底公园1号1'
					},
					{
						key: 6,
						name: '胡彦祖2',
						age: 42,
						address: '西湖区湖底公园1号'
					}
				]
				let startItem = []
				startItem['name'] = res.records[0]
				startItem['age'] = res.records[0]
				startItem['address'] = res.records[0]
				startItem['name'].rowSpan = 1
				startItem['age'].rowSpan1 = 1
				startItem['address'].rowSpan2 = 1
				res.records.forEach((item, index) => {
					let nextItem = res.records[index + 1] || {}
					if (item['name'] === nextItem['name']) {
						startItem['name'].rowSpan++
					} else {
						startItem['name'] = nextItem
						startItem['name'].rowSpan = 1
					}
					if (item['age'] === nextItem['age']) {
						startItem['age'].rowSpan1++
					} else {
						startItem['age'] = nextItem
						startItem['age'].rowSpan1 = 1
					}
					if (item['address'] === nextItem['address']) {
						startItem['address'].rowSpan2++
					} else {
						startItem['address'] = nextItem
						startItem['address'].rowSpan2 = 1
					}
				})
			return res
			})
			.catch((error) => {
				console.log(error)
			})
			.finally(() => {
				//...
			})
	}

效果图

在这里插入图片描述

多行合并可参考

antd-vue table跨行合并单元格

  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Coisini_甜柚か

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值