<template>
<div class="box">
<el-button
class="addBtn"
type="primary "
@click="addRow"
size="small"
style="margin-bottom:10px;"
>增加</el-button
>
<el-table
:data="
tableData.slice((currentPage - 1) * pageSize, currentPage * pageSize)
"
border
class="el-table"
style="width: 100%;"
>
<el-table-column align="center" type="index" label="序号" width="80">
</el-table-column>
<el-table-column prop="sort" label="配置分类">
<template slot-scope="scope">
<el-input
@click="detail"
v-model="scope.row.sort"
:disabled="!scope.row.disabled"
></el-input>
</template>
</el-table-column>
<el-table-column prop="name" label="指标名称">
<template slot-scope="scope">
<el-input
@click="detail"
v-model="scope.row.name"
:disabled="!scope.row.disabled"
></el-input>
</template>
</el-table-column>
<el-table-column align="center" prop="depart" label="所属部门">
<template slot-scope="scope">
<el-input
v-model="scope.row.depart"
:disabled="!scope.row.disabled"
></el-input>
</template>
</el-table-column>
<el-table-column align="center" prop="creator" label="创建者">
<template slot-scope="scope">
<el-input
v-model="scope.row.creator"
:disabled="!scope.row.disabled"
></el-input>
</template>
</el-table-column>
<el-table-column align="center" prop="createDate" label="创建时间">
<template slot-scope="scope">
<el-input
v-model="scope.row.createDate"
:disabled="!scope.row.disabled"
></el-input>
</template>
</el-table-column>
<el-table-column align="center" prop="updater" label="更新者">
<template slot-scope="scope">
<el-input
v-model="scope.row.updater"
:disabled="!scope.row.disabled"
></el-input>
</template>
</el-table-column>
<el-table-column align="center" prop="updaterDate" label="更新时间">
<template slot-scope="scope">
<el-input
v-model="scope.row.updaterDate"
:disabled="!scope.row.disabled"
></el-input>
</template>
</el-table-column>
<el-table-column align="center" fixed="right" label="操作" width="200">
<template slot-scope="scope">
<el-button
v-if="scope.row.edit"
type="success"
size="mini"
@click="confirmEdit(scope.row)"
style="margin-left:0px;"
>保存
</el-button>

<el-button
v-if="scope.row.edit"
class="cancel-btn"
size="mini"
type="warning"
@click="cancelEdit(scope.$index, scope.row)"
style="margin-left:0px;"
>取消
</el-button>
<el-button
v-else
type="primary"
size="mini"
@click="startEdit(scope.row)"
style="margin-left:0px;"
>编辑
</el-button>
<el-button
@click="handleDelete(scope.$index, tableData)"
type="danger"
size="mini"
style="margin-left:0px;"
>
删除
</el-button>
</template>
</el-table-column>
</el-table>
<el-pagination
class="pagination"
align="center"
@size-change="handleSizeChange"
@current-change="handleCurrentChange"
:current-page="currentPage"
:page-sizes="[1, 5, 10, 20]"
:page-size="pageSize"
layout="total, prev, pager, next"
:total="tableData.length"
>
</el-pagination>
</div>
</template>

<script>
import data from "./data/index.js";
export default {
mixins: [data],
methods: {
// 增加行
addRow() {
let newLine = {
sort: this.sort,
name: this.name,
depart: this.depart,
creator: this.creator,
createDate: this.createDate,
updater: this.updater,
updaterDate: this.updaterDate,
edit: true, // 新增时处于可编辑状态,所以按钮是保存和取消
disabled: true // 打开编辑状态
};
this.tableData.unshift(newLine); // 移到第一行
},

// 编辑
startEdit(row) {
row.edit = !row.edit;
row.disabled = true;
},

// 保存
confirmEdit(row) {
//row.originalValue = row.address;
if (row.sort == null || row.name == null) {
this.$message({
message: "请输入分类名称与指标名称!",
type: "warning"
});
return false;
}
row.edit = false;
row.disabled = false;
//调取Api接口地址
//成功后
this.$message({
message: "修改成功!",
type: "success"
});
//失败后
// this.$message({
// message: "修改失败",
// type: "warning"
// });
// let name = this.params.name;
// const p = { ...row, name };
//
// // 调用更新方法
// updateXXXXx(p);
// this.$message({
// message: "已修改!",
// type: "success"
// });
// row.disabled = false;
// if (row.id === undefined) {
// // 重新加载该页面
// }
},

// 取消
cancelEdit(index, row) {
if (row.sort == null || row.name == null) {
return false;
}
//row.address = row.originalValue;
row.edit = false;
row.disabled = false;

if (row.id === undefined) {
debugger;
// 重新加载该页面
location.reload();
}
this.$message({
message: "已取消修改!",
type: "warning"
});
},
//删除
handleDelete(index, row) {
row.splice(index, 1);
this.$message({
message: "已删除!",
type: "success"
});
},
//表格分页
//列表分页
handleSizeChange(val) {
this.currentPage = 1;
this.pageSize = val;
},
handleCurrentChange(val) {
this.currentPage = val;
},
//指标点击事件
detail() {
this.$router.push({ path: "/targetWarn/detail" });
}
}
};
</script>

<style scoped>
.box {
padding: 20px;
}
.box .addBtn {
float: right;
}
</style>

el-table单元格新增、编辑、删除功能的更多相关文章

  1. C# DataGridView中指定的单元格不能编辑

    注意:DataGridView控件是从.NET Framework 2.0版本开始追加的. ReadOnly属性的使用 DataGridView内所有的单元格不能编辑 当DataGridView.Re ...

  2. [Swift通天遁地]二、表格表单-(7)电子邮件Mail:实现单元格左右滑动调出功能按钮

    ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...

  3. Devexpress WinForm GridControl实现单元格可编辑状态更改

    之前做项目的时候,需要实现这样的功能.在gridcontrol中,根据是否修改(checkbox)列的选中和未选中状态来联动另外一列的编辑状态.实现如下: private void gridView1 ...

  4. 【ABAP系列】SAP ABAP OOALV 动态设置单元格可否编辑

    公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[ABAP系列]SAP ABAP OOALV 动 ...

  5. excel设置单元格不可编辑

    把允许编辑的单元格选定,右键-设置单元格格式-保护,把锁定前的对钩去掉.再点工具-保护工作表.这样就可以只让你刚才设定的单元格允许编辑,其他不允许.

  6. Vue. 之 Element table 单元格内容隐藏

    Vue. 之 Element table 单元格内容隐藏 在table显示数据时,若某个单元格的内容过多,需要进行隐层,在这一列的单元格属性添加::show-overflow-tooltip=&quo ...

  7. Java poi导出设置 Excel某些单元格不可编辑

    小白的总结,大神勿喷:需要转载请说明出处,如果有什么问题,欢迎留言 一.需求: 1.某一列 .某一行或某些单元格不可编辑,其他列可以编辑 二.期间遇到的问题 1.无法设置成不可编辑 2.设置为不可编辑 ...

  8. vue+element-ui 实现table单元格点击编辑,并且按上下左右键单元格之间切换

    通过我的测试我发现两个两种方法来编辑单元格的内容 第一种点击编辑: 我是给td里添加一个input,将值赋值给input,当失去焦点的时候将input的值付给td原来的内容,然后将input删除, 代 ...

  9. ABAP ALV单个单元格状态编辑

    *&---------------------------------------------------------------------* *& Report  ZPPR0024 ...

  10. ABAP ALV单个单元格状态编辑-简单版本

    *&---------------------------------------------------------------------* *& Report  ZPPR0024 ...

随机推荐

  1. wchar用wcout输出正常cout是?

  2. 2 java程序入门

    1. 第一个java  class  { public static void main(String[] args) { System.out.println("Hello World!& ...

  3. [转]WPF中的导航框架

    有的时候,我们需要一个支持页面跳转的UI,例如文件浏览器,开始向导等.对于这样的界面,简单的可以使用ContentControl + ContentTemplateSelector的方式来实现,但是有 ...

  4. WPS Office for Mac如何修改Word文档文字排列?WPS office修改Word文档文字排列方向教程

    Word文档如何改变文字的排列方向?最新版WPS Office for Mac修复了文字排版相关的细节问题,可以更快捷的进行Word编辑,WPS Office在苹果电脑中如何修改Word文档文字排列方 ...

  5. 利用reduce方法,对数组中的json对象去重

    数组中的json对象去重 var arr = [{ "name": "ZYTX", "age": "Y13xG_4wQnOWK1Q ...

  6. mui框架页面每次加载操作

    最近在优化自己用mui开发的app,主要还是针对交互这块儿,这里简单给大家说一下问题点场景,就是我是通过动态添加底部tabBar的方法创建了一个底部可以切换的操作区域,代码如下: mui.init() ...

  7. 【转载】Visual Studio + VA 常用快捷键

    有过几年没怎么做window开发,发现回头再用VS忘记了好多快捷键,好记性真是不如烂笔头. 快捷键习惯设置:Tools->Options->Keyboard:Apply the follo ...

  8. Cucumber:启动类配置

    Cucumber:启动类配置 package com.steps; import cucumber.api.CucumberOptions; import cucumber.api.junit.Cuc ...

  9. NOIp2018集训test-10-4/test-10-5 (联考四day1/day2)

    这个day1稍微有点毒瘤吧?? DAY1 排列 以前总是把day1t1想太复杂了翻车,差不多往正解的方向想了一下感觉不可能这么复杂这可是noipday1t1啊一定有非常简单的方法然后翻车了?? 题目转 ...

  10. Oracle sql判断一个字段是否全数字 或含有中文

    update (select length(t.name), t.* -- name,length(name) from g_enterprise_info t where nvl2(translat ...