Element-ui表格选中回显
先瞄一下,是不是你要的效果
然后,废话不多说,直接上代码啦
<template>
<div class>
<div class="projectData">
<el-table :data="tableData2" ref="multipleTable" :show-header="false" :border="false" style="width: 100%" @selection-change="handleSelectionChange">
<el-table-column type="selection" :reserve-selection="true" width="55"></el-table-column>
<el-table-column prop="spaceName" width="180"></el-table-column>
<el-table-column>
<template slot-scope="scope" v-if="scope.row.id==1||scope.row.id==3||scope.row.id==4">
<el-input
v-model="scope.row.spacePrice"
class="el-input_inner"
size="medium"
clearable
></el-input>
{{scope.row.spaceUnit}}
</template>
</el-table-column>
</el-table>
</div>
<el-button type="primary" @click="submitForm">确定</el-button>
</div>
</template> <script>
export default {
data() {
return {
tableData2: [],
multipleSelection: [],
listData:[],
};
},
methods: {
handleSelectionChange(val) {
this.multipleSelection = val;
for (var i = 0; i < this.multipleSelection.length; i++) {
this.multipleSelection[i].containSpace = 1;
}
},
// 初始化数据
projectManage(){
this.$axios.get("/clapi/materiel/mealSpaceRela/queryProjectManage?mealId="+this.message.id)
.then((response) => {
if(response.data.status.code == 200){
this.tableData2 = response.data.result;
this.listData = response.data.result
for ( let i = 0 ; i < this.listData.length ; i++ ){
if(this.listData[i].containSpace == 1){
//这是默认选中上的
this.$refs.multipleTable.toggleRowSelection(this.tableData2[i],true);
}
}
}
})
.catch(error => {
console.log(error);
});
},
// 保存
submitForm() {
// 数组为空的话,状态为0,输入框为0
if(this.multipleSelection.length == 0){
for (var i = 0; i < this.tableData2.length; i++) {
this.tableData2[i].containSpace = 0;
this.tableData2[i].spacePrice = 0;
}
this.$axios.post("/clapi/materiel/mealSpaceRela/editProjectManage",this.tableData2)
.then((response) => {
this.$message({
type: "success",
message: "保存成功!"
});
})
.catch((error) =>{
console.log(error);
});
}else{
//已选数据,其他输入的值为0
for(var n=0;n<this.multipleSelection.length;n++){
// 如果选中的数据为空默认为0
if(this.multipleSelection[n].spacePrice=='')this.multipleSelection[n].spacePrice=0;
}
this.$axios.post("/clapi/materiel/mealSpaceRela/editProjectManage",this.multipleSelection)
.then((response) => {
this.$message({
type: "success",
message: "保存成功!"
});
})
.catch((error) =>{
console.log(error);
});
} },
},
created() {
this.projectManage(); }
};
</script> <style scoped>
.projectData >>> .el-input__inner {
text-align: center;
} .projectData >>> .el-table--enable-row-hover .el-table__body tr:hover > td {
background: #fff!important;
} .projectData tr {
height: 60px !important;
}
.projectData {
margin-left: 80px;
}
.favour_checkbox {
height: 60px;
display: block;
} table,table th,table tr td {
border:1px solid red;
} .el-input_inner,
.el-select {
text-align: center;
width: 100px;
} </style>
若有不明白请加群号:复制 695182980 ,也可扫码,希望能帮助到大家。
Element-ui表格选中回显的更多相关文章
- element ui 表格提交时获取所有选中的checkbox的数据
<el-table ref="multipleTable" :data="appList" @selection-change="changeF ...
- ui.datepicker的回显问题
应用场景: 页面上有一些现有的输入框,需要调用日期插件,同时还要clone一份,动态添加到页面中,动态生成的输入框在调用datepicker的时候,click事件有效,但是选择的时间无法回显到对应的输 ...
- Element UI表格组件技巧:如何简洁实现跨页勾选、跨页统计功能
业务场景 在使用Element UI的Table组件时,常常面对这样的业务需求: 表格数据的每一项都要提供勾选框,当切换分页时,能够记忆所有页面勾选的数据,以实现批量提交不同页面勾选数据的功能.并且, ...
- vue element select多选回显
我们经常在使用 Element组件里面的 select多选 场景:添加账号的时候需要选择可见分公司(分公司为多选),添加成功之后可以编辑,需要回显添加时所提交的分公司 代码如下: 多选框: data( ...
- vue + element ui 表格自定义表头,提供线上demo
前言:工作中用到 vue+element ui 的前端框架,需要使用自定义表头,需要使用 re.转载请注明出处:https://www.cnblogs.com/yuxiaole/p/9710826.h ...
- 封装一个优雅的element ui表格组件
现在做后台系统用vue + elementUI 的越来越多,那element ui的 el-table 组件肯定也离不开.虽然element ui的table组件很好.但是表格和分页是分离的.每次写表 ...
- html option选中 回显 取值
1.html <select class="form-control" id="sex"> <option value="-1&qu ...
- element ui表格常用功能如:导出 新增 删除 多选 跨页多选 固定表头 多级表头 合并行列 等常见需求
<template> <div class="table-cooperte"> <el-table :data="tableData&quo ...
- vue2.0+Element UI 表格前端分页和后端分页
之前写过一篇博客,当时对element ui框架还不太了解,分页组件用 html + css 自己写的,比较麻烦,而且只提到了后端分页 (见 https://www.cnblogs.com/zdd20 ...
随机推荐
- jpa 使用笔记
1,嵌套类查询 List<Person> findByAddress_ZipCode(ZipCode zipCode); ZipCode是Address属性的内部属性. 2,jpa in ...
- [NOIP2015普及组]求和
题目 题目描述 一条狭长的纸带被均匀划分出了n个格子,格子编号从1到n.每个格子上都染了一种颜色color_i用[1,m]当中的一个整数表示),并且写了一个数字numberi. 定义一种特殊的三元组: ...
- git 使用过程中遇到的问题does not appear to be a git repository Could not read from remote respository
想把本地的git库上传到github上.github已经新建了一个public仓库,利用网站的命令 git Bash报错:does not appear to be a git repository ...
- 1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'groups)VALUES('1','hh','hh@163.com','Boss')' at line 1
mysql8.0版本 在已存在的表里插入一条数据 insert INTO api_user(id,username,email,groups)VALUES('1','hh','hh@163.com', ...
- redis 在 php 中的应用(Sorted-set篇)
本文为我阅读了 redis参考手册 之后编写,注意 php_redis 和 redis-cli 的区别(主要是返回值类型和参数用法) Redis 有序集合和集合一样也是string类型元素的集合,且不 ...
- c# 调用RDP和SSH实现远程登陆
1.ssh的登陆实现: windows平台可以安装OpenSSHforWindows 后,可以通过cmd 执行ssh的指令. 也可以在c#编程中实现ssh的登陆: var p = new System ...
- 快速安装 Laravel 5.7
$ git clone https://github.com/laravel/laravel.git $ cd laravel $ cp .env.example .env $ composer in ...
- 什么时候使用“RCC_APBXPeriph_AFIO”
什么时候需要开启复用时钟: (1)使用EXTI (2)重映射(用到外设的重映射功能时才需要使能AFIO的时钟) 举例:重映射USART2 USART2的TX/RX在PA.2/3.但是,PA.2已经被T ...
- Linux常用命令——网络命令
Linux常用命令——网络命令 Linux ifconfig 描述:查看设置网络IP 安装命令:yum -y install net-tools 语法:ifconfig 示例:ifconfig et ...
- vue引入JQ的方法
在vue中引入jq 用vue-cli脚手架工具构建项目成功后 当需要引入JQ,可用以下方法: 1.首先在package.json里的 dependencies加入"jquery" ...