VUE系列——使用ElementUI的table表格重构穿梭框

前言

首先看一下ElementUI官网给的穿梭框例子

这个穿梭框不符合自己项目的需求,因为左边被选中的到了右边之后,左边的内容已经没有了

一、需求

 把左边选中的内容添加到右边之后,选中的内容继续保留到左边,选中的那几行变颜色

二、重构步骤

step1 使用官网给的table创建左右两个框以及中间的按钮

左边框:

<div class="table-container">
	<el-table
		ref="dxgrid"
		:data="currentPageData"
		highlight-current-row
		@current-change="lineClick"
		:row-style="setColor"
		height="100%"
		style="width: 100%; cursor:pointer;">
		<el-table-column
			prop="MC"
			label="名称"
			show-overflow-tooltip
			width="520">
		</el-table-column>
	</el-table>
</div>

注意:

el-table标签里需要包含 @current-change:row-style两个样式

右边框:

<div class="table-container">
	<el-table
		ref="yxgrid"
		:data="yxData"
		<el-table-column
			prop="MC"
			label="名称"
			show-overflow-tooltip
			width="450">
		</el-table-column>
		<el-table-column label="操 作">
			<template slot-scope="scope">
				<el-button
					size="mini"
					type="danger"
					@click="handleDelete(scope.$index, scope.row)">删除
				</el-button>
			</template>
		</el-table-column>
	</el-table>
</div>

中间按钮

<div class="select-to-right">
	<div class="select-right-singleSel" @click="singleSel()"></div>
	<div class="select-right-mutiSel" @click="mutiSel()"></div>
</div>

step2 设置变量

currentRowData: null,
currentPageData: [], //左边的数据需要从数据库查询
yxData: [],

step3 js里面写入方法

//选中一行
lineClick(val) {
	this.currentRowData = val;
},
//单选
singleSel() {
	if (JSON.stringify(this.yxData).indexOf(JSON.stringify(this.currentRowData)) == -1) {
		this.yxqyData.push(this.currentRowData);
	}
},
//选择整个页面
mutiSel() {
	this.currentPageData.forEach((item, index) => {
		if (JSON.stringify(this.yxData).indexOf(JSON.stringify(item)) == -1) {
			this.yxData.push(item);
			this.setColor(item, index)
		}
	})
},
//选中之后设置颜色
setColor({row, rowIndex}) {
	if (JSON.stringify(this.yxData).indexOf(JSON.stringify(row)) != -1) {
		return {
			color: 'red',
		}
	}
},

 扩展: ElementUI使用table时,选中某行或者鼠标移入某行时添加背景色

三、效果展示

OK,GAME OVER! 

更多精彩内容请关注:程序员高手之路

回复“vue项目”,免费获取以下项目视频教程

  • 33
    点赞
  • 28
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

前方一片光明

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

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

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

打赏作者

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

抵扣说明:

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

余额充值