elment表格sort-method自定义排序功能

14 篇文章 1 订阅

在这里插入图片描述
在这里插入图片描述

点击排序箭头来调取接口进行数据排序

在el-table表格中写入
点击事件
@sort-change=“changeTableSort”
默认以什么单位进行倒序还是顺序排序,prop对应这字段
:default-sort = “{prop: ‘ptuid’, order: 'ascending '}”
在表格中要写入 :sortable="‘custom’"

<el-table 
			border
			stripe
			v-loading="loading" ref="multipleTable" :data="tableData"
			@selection-change="handleSelectionChange"
			tooltip-effect="dark" style="width: 100%"
			:default-sort = "{prop: 'ptuid', order: 'ascending '}"
			 @sort-change="changeTableSort">
				<el-table-column type="selection" width="50">
				</el-table-column>
				<el-table-column prop="ptuid" label="编号" width="70" :sortable="'custom'">
				</el-table-column>
				<el-table-column prop="pocketcode" label="垃圾袋二维码" >
				</el-table-column>
				<el-table-column prop="username" label="用户姓名" >
				</el-table-column>
				<el-table-column prop="ptutime" label="时间" :sortable="'custom'">
				</el-table-column> 
				
			</el-table>

在方法里点击方法中
打印出item
有order是降序还是升序,prop是所点击的字段名字。然后就可以根据 名字还是order还进行判断排序

changeTableSort(item){
				let that = this
				if(item.order == "ascending"){
					that.daoxun = 'false'
				}else if(item.order == "descending"){
					that.daoxun = 'true'
				}
				if(item.prop == "ptuid"){
					that.paixu = 0;
				}else if(item.prop == "ptutime"){
					that.paixu = 1;
				}
			},
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值