修改el-table-column type=“expand“展开行触发点-更多按钮触发

本文介绍如何在Vue的Element UI表格中,实现默认只展示前5项数据,点击'更多...'按钮可以展开所有字段。通过`:expand-row-keys`和`:row-key`属性配合,实现实时展开收起行功能。
摘要由CSDN通过智能技术生成

默认展开点

目标展开点

解决代码:

html部分:

				<el-table :row-class-name="tableRowClassName" size="small"
					:header-cell-style="{background:'#0069cf',color:'#ffffff','text-align':'center'}" :data="tableData"
					:expand-row-keys="expands" :row-key="getRowKeys" border style="width: 100%">
					<el-table-column type="expand" align="center">
						<template slot-scope="scope">
							<el-tag v-for="(item,index) in scope.row.tblNmList" :key="item" effect="plain">
								{{ item }} { {{scope.row.tblIdList[index]}} }
							</el-tag>
						</template>
					</el-table-column>
					<el-table-column align="center" prop="index" label="序号" width="80">
						<template slot-scope="scope">
							<span>{{(currentPage - 1) * pageSize + scope.$index + 1}}</span>
						</template>
					</el-table-column>


					<el-table-column align="left" prop="tblNmList" label="xxxxx" width="600">
						<template slot-scope="scope">
							<el-tag v-for="(item,index) in scope.row.tblNmList.slice(0, 5)" :key="item" effect="plain">
								{{ item }} { {{scope.row.tblIdList[index]}} }
							</el-tag>
							<!-- <el-tag @click="clickExpandMore(scope.row.id)" >
								更多...
							</el-tag> -->
							<el-button type="text" @click="clickExpandMore(scope.row.id)">更多...</el-button>
						</template>
					</el-table-column>
				</el-table>

js-data部分:

		expands: [],
		getRowKeys(row) {
			return row.id;
		}

js-method部分:

		handleExpandChange(row, expandedRows) {

			var index=that.expands.indexOf(row);
			if(index!=-1){
				that.expands.splice(index,1);
			}else{
				that.expands = [];
				that.expands.push(row);
			}

		},
		clickExpandMore(row){
			that.handleExpandChange(row);
		},

关键点属性::expand-row-keys="expands"  ,    :row-key="getRowKeys"

实现:默认显示字段内前5个信息,点击更多按钮,展开全部字段信息

效果图:

<u-modal :ref="`senPi`" :size="`huge`" :is-heading-slot-empty="true"> <template #title> <u-text :text="`报价详情`"></u-text> </template> <template #body> <u-linear-layout direction="vertical" wrap> <u-form :layout="`inline`" key="form_13"> <u-form-item :layout="`center`"> <template #label> <u-text :text="`供应商id`"></u-text> </template> <u-select :clearable="true" :placeholder="`请选择供应商id`" :dataSource="__select_20_handleDataSourceLoad()" :pageSize="50" :textField="`supplier.name`" :valueField="`supplier.name`" :pagination="true" :value.sync="filter2.supplierId" :emptyValueIsNull="true" key="select_20" > <template #option="current"></template> <template #renderFooter></template> </u-select> </u-form-item> <u-form-item :layout="`center`"> <template #label> <u-text :text="`最终供应商`"></u-text> </template> <u-select :clearable="true" :value.sync="filter2.finalSupplier" :placeholder="`请选择最终供应商`" :dataSource="$utils['EnumToList']({ concept: 'TypeAnnotation', typeKind: 'reference', typeNamespace: 'app.enums', typeName: 'Is_Final_Supplier', inferred: false, ruleMap: {}, typeArguments: [] })" :emptyValueIsNull="true" key="select_22" > <template #option="current"></template> <template #renderFooter></template> </u-select> </u-form-item> <u-form-item :layout="`center`" :labelSize="`auto`"> <u-button :color="`primary`" :text="`查 询`" @click="onQueryClick($event)"></u-button> </u-form-item> </u-form> <!-- 树形表格,支持折叠子表 --> <el-table :data="treeData" row-key="id" :tree-props="{ children: 'quotedPrices', hasChildren: 'hasChildren' }" border style="--cw-style-font-size: 10px; font-size: 10px; --table-view-th-padding: 1px; --table-view-td-padding: 1px; --table-cell-padding: 0px" > <!-- 展开--> <el-table-column type="expand" label="展开" width="50" :expandable="(row) => Array.isArray(row.quotedPrices) && row.quotedPrices.length > 0" :expanded="(row) => row.isExpanded" @expand-change="handleExpandChange" ></el-table-column> <el-table-column prop="materialApplyId" label="物料申请单id" width="150"></el-table-column> <el-table-column prop="supplierId" label="供应商id" width="150"></el-table-column> <el-table-column prop="finalSupplier" label="最终供应商" width="150"></el-table-column> <!-- 子表格:报价详情 --> <el-table-column label="报价详情" width="300"> <template #default="scope"> <el-table v-if="Array.isArray(scope.row.quotedPrices) && scope.row.quotedPrices.length > 0" :data="scope.row.quotedPrices" style="width: 100%; font-size: 10px;" border > <el-table-column prop="times" label="报价次数" width="100"></el-table-column> <el-table-column prop="price" label="报价价格" width="100"></el-table-column> <el-table-column prop="lastPrice" label="是否最终报价" width="100"></el-table-column> </el-table> </template> </el-table-column> </el-table> </u-linear-layout> </template> </u-modal>
最新发布
03-12
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值