同一表格根据不同排序条件查询

本文介绍如何使用Element UI的表格组件实现数据排序,并通过调用后端接口动态加载排序后的数据。具体包括设置表格列属性、监听排序变化、发送HTTP请求获取排序数据等关键步骤。

1.template

<el-table ref="multipleTable" 
			  	:data="tableData" 
			  	tooltip-effect="dark" 
			  	@selection-change="handleSelectionChange"
			  	@sort-change='handleSortChange'
			  	:clearSort='clearSort()'>
      			
				 	<el-table-column
				      	v-for='(item,index) in tableList'
				        :prop="item.prop"
				        :label="item.label"
				        :width="item.width"
				        :key='index'
				        >
			        </el-table-column>

					<el-table-column  label="产品价格(元/g)" sortable ref="sortOne" width="133">
						<template slot-scope="scope">						        
					       {{ scope.row.PRICE}}
      					</template>
					</el-table-column>
					<el-table-column label="产品规格(g)"  sortable  ref="sortTwo" width="130">
							<template slot-scope="scope">						        
						       {{ scope.row.WEIGHT}}
	      					</template>
						</el-table-column>
</el-table>

2.method

handleSortChange(val){
	      			      		console.log(val)
	      		if(val.column==null){
	      			this.Sort('','',this.pageNo)
	      			return
	      		}
	      		if(val.column.label=='产品价格(元/g)'&&val.order=='descending'){
	      			this.Sort('PRICE',"desc",this.pageNo)
	      			this.productType='PRICE';
	      			this.sortOrder="desc";
	      		}
	      		if(val.column.label=='产品价格(元/g)'&&val.order=='ascending'){
	      			this.Sort('PRICE',"asc",this.pageNo)
	      			this.productType='PRICE';
	      			this.sortOrder="asc";
	      		}
	      		if(val.column.label=='产品规格(g)'&&val.order=='descending'){
	      	
	      			this.Sort('WEIGHT',"desc",this.pageNo)
	      			this.productType='WEIGHT';
	      			this.sortOrder="desc";
	      		}
	      		if(val.column.label=='产品规格(g)'&&val.order=="ascending"){
	      			this.Sort('WEIGHT',"asc",this.pageNo)
	      			this.productType='WEIGHT';
	      			this.sortOrder="asc";
	      		}
	      		console.log(val,'val>>>>>>>>>>>>>>')
	      	},

Sort(x,y,pageNO,pageSize){
	      		console.log(x,y,pageNO,pageSize)
	      		this.keepX=x
				  this.keepY=y
				  console.log(this.material)
				let parames = {
					"functionName": "preciousmetalbiz.service.PrdMetalService",
				    "methodName": "selectPmList",
				    "pageNo":pageNO,
				    "pageSize":10,
					
					"data": { // 查询条件
						prdCode: this.prdCode,						// 产品代码
						prdName: this.prdName,						// 产品名称
						weightStart: this.weightStart,		// 规格(开始)
						weightEnd: this.weightEnd,			// 规格(结束)
						priceStart: this.priceStart,	// 产品销售价格(开始)
						priceEnd: this.priceEnd,		// 产品销售价格(结束)
						material: this.material,				// 材质	
						companyName: this.companyName, 	
						branchCode:JSON.parse(sessionStorage.getItem('sessionData')).orgnCode,
	   					roleId:JSON.parse(sessionStorage.getItem('sessionData')).roleId,
						"order":x,
	        			"sort":y	
					}
				};
				this.http(JSON.stringify(parames))
				.then((res)=>{
					  if(res.data.errorCode!=undefined){
					this.$alert(res.data.errorMsg,'提示', {
					confirmButtonText: '确定',
					})
			    	}
						var list = res.data.basicInfoList;
						this.tableData = list;
						this.total = res.sumCount;
						
						setTimeout(()=>{
//                  this.setSelectRow();
					
                    }, 50)
				}).catch(error => {
					console.log(error);
				})
			},

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值