el-table 多级表头拖拽

本文介绍了如何使用ElementUI和sortable.js在Vue项目中实现多级表头的拖拽功能,包括父表头不可拖拽、序号固定、子表头跟随父表头移动等复杂要求。


场景

业务需求做多级表头拖拽,具体要求如下:
没有子表头的父表头不可拖拽,第一个序号不可拖拽,父表头拖拽换位,同一个父表头下的子表头拖拽时 子表头换位,不同父表头下子表头拖拽时子表头不变两个父表头换位。

一、代码

1.页面部分

我这里是多级表头的数据表格。使用了Element UI库来构建表格组件,并结合了sortable.js插件来实现表格列的拖拽排序功能。
在模板部分,使用了<el-table>组件来展示表格数据,通过v-for指令循环渲染表头列和子列。每一列都设置了相应的属性,如label、align、sortable等,在表格中显示对应的数据页面代码如下:

<template>
	<el-table :data="tableData" tooltip-effect="dark" class="financeTotalTwo financeTotal_spfcjhz"
		style="width: 100%" height="100%" :size="GLOBAL.tableSize" ref="multipleTable">
		<el-table-column type="index" width="80" label="序号" align="center"></el-table-column>
		<el-table-column
			v-for="(item, index) in titleList"
			v-if="item.show"
			:label="item.label"
			:align="item.align"
			:sortable="item.sortable"
			:prop="item.prop"
			:min-width="item.width"
			:class-name="(item.prop == 'cityName' ||item.prop == 'tjDate' || item.prop == 'whHouseUseName' ||item.prop == 'blockName' || item.prop =='districtName' ) ? 'disableDrag':'allowDrag'"
			:key="item.prop + index"
			class="allowDrag"
			>
			<template slot-scope="scope">
				<div>{
  
  { scope.row[item.prop] }}</div>
			</template>
			<el-table-column
				v-for="(zitem, zindex) in item.children"
				v-if="zitem.show && item.children.length >0"
				:label="zitem.label"
				:align="zitem.align"
				:sortable="zitem.sortable"
				:prop="zitem.prop"
				:min-width="zitem.width"
				class-name="zallowDrag"
				:class="'draggable'"
				:key="zitem.prop + zindex"
				>
				<template slot-scope="scope">
					<div class="finance_table_alignRight">{
  
  { scope.row[zitem.prop] }}&l
评论 3
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值