elementui:el-table支持搜索、切换分页多选功能,以及数据回显

server/2025/2/8 9:16:07/

1、el-table相关代码,需注意:row-key="(row) => { return row.id }" 以及 :reserve-selection="true"

   <div class="boxList"><div class="search-form"><!-- 搜索表单 --><el-form :inline="true" :model="form" ref="form"><el-form-item label="名称" prop="name"><el-inputv-model="form.name"placeholder="请输入名称"></el-input></el-form-item><el-form-item label="专业" prop="major"><el-inputv-model="form.major"placeholder="请输入专业"></el-input></el-form-item><!-- 操作按钮 --><el-form-item><el-button type="primary" @click="handleQuery">查询</el-button><el-button type="warning" @click="resetForm">重置</el-button></el-form-item></el-form></div><el-tableref="table":data="newtableData"border@selection-change="selectionChangeHandle"row-class-name="disable-selection"height="300"style="width: 100%"><el-table-columntype="selection"width="50"fixed:reserve-selection="true"align="center"/><el-table-column prop="name" label="姓名"></el-table-column><el-table-column prop="major" label="专业"></el-table-column><el-table-column prop="deptName" label="部门"></el-table-column></el-table><!-- 分页 --><div class="pagination"><el-paginationbackgroundlayout="total, sizes, prev, pager, next":total="page.total":current-page="page.current":page-size="page.size"@size-change="handleSizeChange"@current-change="handleCurrentChange"></el-pagination></div><divstyle="display: flex;align-items: center;margin-top: 14px;font-size: 14px;margin-left: 3px;">完成时间:<!-- <el-date-pickerclearablev-model="form.date"type="datetime"value-format="YYYY-MM-DD HH:mm:ss":placeholder="请选择日期"style="width: 36%"></el-date-picker> --><el-inputtype="Number"v-model="form.workTime":placeholder="'请输入'"clearablestyle="width: 36%"><template #append>分钟</template></el-input></div><div style="display: flex; justify-content: flex-end"><el-button type="primary" @click="onYunxing">运行 </el-button></div></div>

2、获取原数据列表和已选数据,注意// 回显已选中的行,$nextTick那段代码

    //获取列表async getUserDataAllListApi() {let params = {size: this.page.size,current: this.page.current,name: this.form.name,major: this.form.major,};let { data } = await repairTools.getUserDataAllList(params);this.page.size = data.size;this.page.total = data.total;this.newtableData = data.records;},//回填人员async getGroupUserDataListApi() {let params = {taskIds: this.schemeAllData.idList,taskLruName: this.schemeAllData.taskLruName,};let { data } = await repairTools.getGroupUserDataList(params);this.checkAll = data.data;// 回显已选中的行this.$nextTick(() => {this.newtableData.forEach((row) => {const isChecked = this.checkAll.some((checkRow) => checkRow.id === row.id);if (isChecked) {this.$refs.table.toggleRowSelection(row, true);}});});},

3、table点击selection-change可以动态获取数据是否有变动

    //选中selectionChangeHandle(selected) {console.log('99999999999选中',selected)this.newSelected = selected;this.newtableData.forEach((row) => {row.ruleselected = selected.includes(row);});},

4、有关分页事件

    handleSizeChange(val) {this.page.size = val;this.tabClick();},handleCurrentChange(val) {this.page.current = val;this.tabClick();},

5、通过异步来定义调用接口的前后顺序

    //点击tabasync tabClick() {if (this.activeName == "type2") {await  this.getUserDataAllListApi();await  this.getGroupUserDataListApi();} },

6、搜索和重置

   // 查询方法handleQuery() {this.tabClick();},// 重置表单resetForm() {this.$refs.form.resetFields();this.form.name = "";this.form.major = "";this.tabClick();},

7、完成代码

<!-- 方案优化 -->
<template><!-- fullscreen --><el-dialog:show-close="!run_disabled":title="schemeOptimization_open.onlyShow ? '维修方案详情' : '待修清单'"v-model="schemeOptimization_open.open"append-to-bodycenterclass="schemeOptimization"width="55%"@closed="closed"@opened="opened"><div><div class="WarWoundInfo pad"><el-tabsv-model="activeName"@tab-click="tabClick":before-leave="beforeLeave"stretch><el-tab-pane:label="schemeOptimization_open.onlyShow ? '维修方案详情' : '待修清单'"name="type1">11</el-tab-pane><el-tab-pane label="人员参数" name="type2"><div class="boxList"><div class="search-form"><!-- 搜索表单 --><el-form :inline="true" :model="form" ref="form"><el-form-item label="名称" prop="name"><el-inputv-model="form.name"placeholder="请输入名称"></el-input></el-form-item><el-form-item label="专业" prop="major"><el-inputv-model="form.major"placeholder="请输入专业"></el-input></el-form-item><!-- 操作按钮 --><el-form-item><el-button type="primary" @click="handleQuery">查询</el-button><el-button type="warning" @click="resetForm">重置</el-button></el-form-item></el-form></div><el-tableref="table":data="newtableData"border@selection-change="selectionChangeHandle"row-class-name="disable-selection"height="300"style="width: 100%"><el-table-columntype="selection"width="50"fixed:reserve-selection="true"align="center"/><el-table-column prop="name" label="姓名"></el-table-column><el-table-column prop="major" label="专业"></el-table-column><el-table-column prop="deptName" label="部门"></el-table-column></el-table><!-- 分页 --><div class="pagination"><el-paginationbackgroundlayout="total, sizes, prev, pager, next":total="page.total":current-page="page.current":page-size="page.size"@size-change="handleSizeChange"@current-change="handleCurrentChange"></el-pagination></div><divstyle="display: flex;align-items: center;margin-top: 14px;font-size: 14px;margin-left: 3px;">完成时间:<!-- <el-date-pickerclearablev-model="form.date"type="datetime"value-format="YYYY-MM-DD HH:mm:ss":placeholder="请选择日期"style="width: 36%"></el-date-picker> --><el-inputtype="Number"v-model="form.workTime":placeholder="'请输入'"clearablestyle="width: 36%"><template #append>分钟</template></el-input></div><div style="display: flex; justify-content: flex-end"><el-button type="primary" @click="onYunxing">运行 </el-button></div></div></el-tab-pane></el-tabs></div><divv-show="schemeOptimization_open.onlyShow &&this.schemeData.type.sub_type == '人员限制下时间最短'"style="display: flex; justify-content: center; height: 50px"><el-buttonsize="small"type="primary"style="height: 30px"@click="goTo_schemeOptimization">方案优化</el-button></div><divv-show="!schemeOptimization_open.onlyShow"style="width: max-content; margin: 0 auto; height: 50px"><el-buttonv-show="activeName === 'type2'":disabled="run_disabled"size="small"style="margin: 0 20px; padding: 9px 25px; height: 30px"@click="resave">重置</el-button><el-button:disabled="run_disabled"size="small"style="padding: 9px 25px; height: 30px"type="success"@click="run">运行</el-button><!-- <el-button type="primary" size="small" style="margin-left: 0;padding: 9px 25px">保存</el-button> --></div></div></template><script>
import EchartTreeDialog from "./EchartTreeDialog.vue";
import EchartGanttDialog from "./EchartGanttDialog.vue";
import MaintenanceResourceTable from "./MaintenanceResourceTable.vue";
// { getRepairResources }
import repairTools from "@/api/basicData/repairTools";export default {name: "SchemeOptimization",props: {},components: { EchartTreeDialog, EchartGanttDialog, MaintenanceResourceTable },data() {return {newSelected: [],form: {name: null,major: null,},page: {size: 10,current: 1,total: null,},newtableData: [],};},mounted() {// this.getUserDataAllListApi();},watch: {schemeAllData: {deep: true,immediate: true,handler(a) {if (a) {}},},},methods: {//运行async onYunxing() {let arr = [];this.newSelected.forEach((i) => {arr.push(i.id);});let params = {workTime: this.form.workTime,userIdList: arr,taskIds: this.schemeAllData.idList,taskLruName: this.schemeAllData.taskLruName,};let { data } =await this.$API.repairTask.warWoundReport.getGeneticWorkData(params);if (data.code != 200) {this.$message.error(data.msg);} else {this.$message.success(data.msg);// eslint-disable-next-line vue/no-mutating-propsthis.schemeOptimization_open.open = false;}},//点击tabasync tabClick() {if (this.activeName == "type2") {await  this.getUserDataAllListApi();await  this.getGroupUserDataListApi();} },//回填人员async getGroupUserDataListApi() {let params = {taskIds: this.schemeAllData.idList,taskLruName: this.schemeAllData.taskLruName,};let { data } = await repairTools.getGroupUserDataList(params);this.checkAll = data.data;// 回显已选中的行this.$nextTick(() => {this.newtableData.forEach((row) => {const isChecked = this.checkAll.some((checkRow) => checkRow.id === row.id);if (isChecked) {this.$refs.table.toggleRowSelection(row, true);}});});},//获取列表async getUserDataAllListApi() {let params = {size: this.page.size,current: this.page.current,name: this.form.name,major: this.form.major,};let { data } = await repairTools.getUserDataAllList(params);this.page.size = data.size;this.page.total = data.total;this.newtableData = data.records;},// 查询方法handleQuery() {this.tabClick();},// 重置表单resetForm() {this.$refs.form.resetFields();this.form.name = "";this.form.major = "";this.tabClick();},//选中selectionChangeHandle(selected) {console.log('99999999999选中',selected)this.newSelected = selected;this.newtableData.forEach((row) => {row.ruleselected = selected.includes(row);});},handleSizeChange(val) {this.page.size = val;this.tabClick();},handleCurrentChange(val) {this.page.current = val;this.tabClick();},},
};
</script>

8、效果如下


http://www.ppmy.cn/server/165907.html

相关文章

论文解读 | NeurIPS'24 Spotlight ChronoMagic-Bench 评估文本到视频生成的质变幅度评估基准...

点击蓝字 关注我们 AI TIME欢迎每一位AI爱好者的加入&#xff01; 点击 阅读原文 观看作者讲解回放&#xff01; 作者简介 袁盛海&#xff0c;北京大学硕士一年级学生 内容简介 本文提出了一种新颖的文本到视频&#xff08;T2V&#xff09;生成基准ChronoMagic-Bench&#xff0…

【Python】第七弹---Python基础进阶:深入字典操作与文件处理技巧

✨个人主页&#xff1a; 熬夜学编程的小林 &#x1f497;系列专栏&#xff1a; 【C语言详解】 【数据结构详解】【C详解】【Linux系统编程】【MySQL】【Python】 目录 1、字典 1.1、字典是什么 1.2、创建字典 1.3、查找 key 1.4、新增/修改元素 1.5、删除元素 1.6、遍历…

比节流防抖更优的选择(特定情况)

在这里以react、shadcn为例&#xff0c;此处例子展示的特定情况为&#xff1a;删除按钮 disableduseState禁用 以下代码的设置可以保证按钮点击后立即禁用 const [isRemoving,setIsRemoving] useState(false); <AlertDialogActiondisabled{isRemoving}//默认可点击onCli…

[Harmonyos]相机功能开发基础知识篇(持续更新)

系列文章目录 【HarmonyOS】纯血鸿蒙真实项目开发—经验总结贴 文章目录 系列文章目录前言一、曝光三要素&#xff1f;1.什么是“曝光2.光圈&#xff08;Aperture&#xff09;——控制进光量和背景虚化- - -光圈的影响 3.快门速度&#xff08;Shutter Speed&#xff09;——控…

springboot配置redis

文章目录 前置依赖配置yml 配置自定义配置&#xff08;非必要&#xff09;正常使用 前置 你使用的是 springboot 项目&#xff0c;使用 yml 来进行配置&#xff0c;properties 同理 依赖配置 <dependency><groupId>org.springframework.boot</groupId><…

苹果再度砍掉AR眼镜项目?AR真的是伪风口吗?

曾经&#xff0c;AR游戏一度异常火热&#xff0c;宝可梦go让多少人不惜翻墙都要去玩&#xff0c;但是也没过去几年&#xff0c;苹果被曝出再度砍掉了AR眼镜项目&#xff0c;面对着市场的变化&#xff0c;让人不禁想问AR真的是伪风口吗&#xff1f; 一、苹果再度砍掉AR眼镜项目&…

python编程-类结构,lambda语法,原始字符串

一个类的基本结构包括以下部分&#xff1a; 类名&#xff1a;用来描述具有相同属性和方法的对象的集合。 属性&#xff1a;类变量或实例变量&#xff0c;用于处理类及其实例对象的相关数据。 方法&#xff1a;在类中定义的函数&#xff0c;用于执行特定操作。 构造器&#xff…

【JS】element-ui table展示勾选状态

element-ui table 我将勾选的值存在multipleSelection中&#xff0c;在表格更新后&#xff0c;再遍历&#xff0c;来展示勾选状态。这样可行吗&#xff1f; 在使用 Element UI 的 el-table 组件时&#xff0c;将勾选的值存储在 multipleSelection 中&#xff0c;然后在表格更新…