<vxe-table
border
show-overflow
ref="xTable"  --------------------------------------------------------------------------------------------可根据此变量控制表格内容
class="vxe-table-element"
height="600"
:data="tableData"--------------------------------------------------------------------------------------表格绑定数据来源
:edit-rules="validRules"------------------------------------------------------------------------------验证规则(可不写--则行内不验证)
@cell-dblclick="dbclickFun"-------------------------------------------------------------------------单元格双击触发方法(可不写)
@edit-closed="saveFun"-----------------------------------------------------------------------------编辑状态关闭触发方法(可不写)
highlight-current-row-----------------------------------------------------------------------------------选中当前行高亮(可不写)
:edit-config="{trigger: 'dblclick', mode: 'row', showStatus: true,autoClear:onedit}"-----编辑设置(双击触发(可改成单击事件 或不写 手动触发),行事件(也可写成cell 则为单元格事件),显示状态,自动清除状态)
>
<vxe-table-column type="index" width="80">
<template v-slot:header="{ column }">
<span>序号</span>
<i class="el-icon-question"></i>
</template>
</vxe-table-column>
<vxe-table-column
field="name"
title="ElInput"
min-width="140"
:edit-render="{type: 'default'}"
>
<template v-slot:edit="scope">
<el-input v-model="scope.row.name" @input="$refs.xTable.updateStatus(scope)"></el-input>
</template>
</vxe-table-column>
<vxe-table-column field="age" title="ElInputNumber" :edit-render="{type: 'default'}">
<template v-slot:header="{ column }">
<span>{{ column.title }}</span>
<i class="el-icon-warning"></i>
</template>
<template v-slot:edit="{ row }">
<el-input-number v-model="row.age" :max="35" :min="18"></el-input-number>
</template>
</vxe-table-column>
<vxe-table-column field="sex" title="ElSelect" width="140" :edit-render="{type: 'default'}">
<template v-slot:edit="scope">
<el-select v-model="scope.row.sex" @change="sexupda(scope)">
<!--可以使用change事件进行属性间的控制-->
<el-option
v-for="item in sexList"
:key="item.value"
:label="item.label"
:value="item.value"
></el-option>
</el-select>
</template>
<template v-slot="{ row }">{{ getSelectLabel(row.sex) }}</template>
</vxe-table-column>
<vxe-table-column field="date" title="ElDatePicker" :edit-render="{type: 'default'}">
<template v-slot:edit="{ row }">
<el-date-picker
v-model="row.date"
type="date"
format="yyyy/MM/dd"
@change="dateupda(scope)"
></el-date-picker>
</template>
<template v-slot="{ row }">{{ formatDate(row.date, 'yyyy/MM/dd') }}</template>
</vxe-table-column>
<vxe-table-column field="date1" title="ElDatePicker" :edit-render="{type: 'default'}">
<template v-slot:edit="{ row }">
<el-date-picker v-model="row.date1" type="datetime" format="yyyy-MM-dd HH:mm:ss"></el-date-picker>
</template>
<template v-slot="{ row }">{{ formatDate(row.date1, 'yyyy-MM-dd HH:mm:ss') }}</template>
</vxe-table-column>
<vxe-table-column field="date2" title="ElTimePicker" :edit-render="{type: 'default'}">
<template v-slot:edit="{ row }">
<el-time-select
v-model="row.date2"
:picker-options="{start: '08:30', step: '00:15', end: '18:30'}"
></el-time-select>
</template>
</vxe-table-column>
<vxe-table-column field="rate" title="ElRate" :edit-render="{type: 'visible'}">
<template v-slot:edit="{ row }">
<el-rate v-model="row.rate"></el-rate>
</template>
</vxe-table-column>
<vxe-table-column field="describe" title="描述" :edit-render="{type: 'default'}">
<template v-slot:edit="scope">
<el-input v-model="scope.row.describe" @input="$refs.xTable.updateStatus(scope)"></el-input>
</template>
</vxe-table-column>
<vxe-table-column label="操作" width="100">
<template v-slot="scope">
<el-button size="mini" type="danger" @click="removeEvent(scope.row)">删除</el-button>
</template>
</vxe-table-column>
</vxe-table>
export default {
data() {
//自定义校验方法
const validatePass = (rule, value, callback) => {
if (value == "" || value == null) {
callback(new Error("good"));
} else {
callback();
}
};
return {
onedit: false,
regionList: [],
tableData: [],
sexList: [{ value: "0", label: "男" }, { value: "1", label: "女" }],
//验证和正常表单一样
validRules: {
name: [
{ required: true, message: "app.body.valid.rName" },
{ min: 3, max: 50, message: "名称长度在 3 到 50 个字符" }
],
sex: [{ required: true, message: "性别必须填写" }],
describe: [
{
validator: validatePass //自定义校验方法
}
]
}
};
},
methods: {
//新增数据
insertEvent(row) {
let record = {
sex: "1",
date: new Date(),
date1: new Date(),
name: "new",
describe: "GOOD"
};
this.$refs.xTable.insertAt(record, row);----------------------------------------------------------新增一行数据
// .then(({ row }) => this.$refs.xTable.setActiveCell(row, "sex"));--------------------------设置行处于编辑状态(设定焦点所在)
},
//单元格双击事件
dbclickFun(cell) {
this.onedit = false;
},
//保存数据
saveFun() {
var nowdata = this.$refs.xTable.getCurrentRow();-------------------------------------------获取当前行数据
if (nowdata != null) {
//走保存
alert(nowdata);
}
},
//下拉框改变
sexupda(scopevalue) {
scopevalue.row.describe = "改了改了";---------------------------------------------------------可更改其它内容
//this.onedit=true;
this.$refs.xTable.updateStatus(scopevalue);--------------------------------------------------更新状态
},
//时间框改变
dateupda(scopevalue) {
//this.onedit=true;
},
//格式化时间类型
formatDate(value, format) {
if (value != null && value != "") {
return this.$utils.dateToString(value, format);
}
},
//下拉框回显内容
getSelectLabel(value) {
let result = "";
if (value == "1") {
result = "女";
} else {
result = "男";
}
return result;
},
removeEvent(row) {
if (row.id) {---------------------------------------------------------------------实际应用时,可判断其它行属性(删除实际数据--走后台删除  删除临时数据则remove)
MessageBox.confirm("确定删除该数据?", "温馨提示", {
confirmButtonText: "确定",
cancelButtonText: "取消",
type: "warning"
})
.then(() => {
this.$refs.xTable.remove(row);
})
.catch(e => e);
} else {
this.$refs.xTable.remove(row);
}
}
}
};

vxe-table 可编辑表格 行内编辑以及验证 element-UI集成的更多相关文章

  1. datatables表格行内编辑的实现

    Datatables是一款jquery表格插件,它是一个高度灵活的工具,灵活就意味着很多功能需要自己去实现,比如说行内编辑功能. Datatables自己是没有行内编辑功能的,最简单的是通过modal ...

  2. VUE+Element UI实现简单的表格行内编辑效果

    原理是通过Css控制绑定的输入控件与显示值,在选中行样式下对控件进行隐藏或显示 <!DOCTYPE html> <html> <head> <meta cha ...

  3. js插件---JS表格组件BootstrapTable行内编辑解决方案x-editable

    js插件---JS表格组件BootstrapTable行内编辑解决方案x-editable 一.总结 一句话总结:bootstrap能够做为最火的框架,绝对不仅仅只有我看到的位置,它应该还有很多位置可 ...

  4. ASP.NET Aries 入门开发教程6:列表数据表格的格式化处理及行内编辑

    前言: 为了赶进度,周末也写文了! 前几篇讲完查询框和工具栏,这节讲表格数据相关的操作. 先看一下列表: 接下来我们有很多事情可以做. 1:格式化 - 键值的翻译 对于“启用”列,已经配置了格式化 # ...

  5. JS组件系列——BootstrapTable 行内编辑解决方案:x-editable

    前言:之前介绍bootstrapTable组件的时候有提到它的行内编辑功能,只不过为了展示功能,将此一笔带过了,罪过罪过!最近项目里面还是打算将行内编辑用起来,于是再次研究了下x-editable组件 ...

  6. [转]JS组件系列——BootstrapTable 行内编辑解决方案:x-editable

    本文转自:http://www.cnblogs.com/landeanfen/p/5821192.html 阅读目录 一.x-editable组件介绍 二.bootstrapTable行内编辑初始方案 ...

  7. bootstrap-editable实现bootstrap-table行内编辑

    bootstrap-editable行内编辑效果如下: 需要引入插件 列初始化代码,为可编辑的列添加editable属性: columns = [ { title: '文件名', field: 'Na ...

  8. BootStrap行内编辑

    Bootstrap行内编辑,这里下载了一个X-Editable的插件,在Nuget里面就可以搜到. 引用的js和css大致如下: @*.Jquery组件引用*@ <script src=&quo ...

  9. bootstrap editable 行内编辑

    除了那些bootstrap/bootstrap table的js , css之外,要额外添加editable的文件: <link href="../assets/css/bootstr ...

随机推荐

  1. QMap里面的值任然是一个QMap,在做循环插入的时候需要记得清空。

    这个问题是我以前的一个问题,当时由于有其他的事情去处理就忘记了,前段时间我的项目要进行集成测试了,为了避免这个缺陷,只能再把这个问题想起来了,再进行解决.有很多问题你觉得不应该发生,其实很多时候都是逻 ...

  2. arcgis for android100.x 禁止地图旋转

    by 蔡建良2019-5-16 关键类: com.esri.arcgisruntime.mapping.view.DefaultMapViewOnTouchListener DefaultMapVie ...

  3. (十四)SpringBoot之事务处理

    一.简介 ssh ssm都有事务管理service层通过applicationContext.xml配置,所有service方法都加上事务操作: 用来保证一致性,即service方法里的多个dao操作 ...

  4. java小工具:通过URL连接爬取资源(图片)

    java语言编写一个简单爬取网站图片工具,实现简单: 通过 java.net.HttpURLConnection 获取一个URL连接 HttpURLConnection 连接成功返回一个java.io ...

  5. JSP JSONArray使用遇坑!添加以下6个jar包

    1.JAR包简介 要使程序可以运行必须引入JSON-lib包,JSON-lib包同时依赖于以下的JAR包: commons-lang.jar commons-beanutils.jar commons ...

  6. ThinkPad T420i 上 Ubuntu 12.04 实现指纹识别登录

    ThinkPad T420i 上 Ubuntu 12.04 实现指纹识别登录 # add ppa add-apt-repository ppa:fingerprint/fprint # update ...

  7. Asp.Net Core 轻松学系列-3项目目录和文件作用介绍

    目录 前言 结语 前言     上一章介绍了 Asp.Net Core 的前世今生,并创建了一个控制台项目编译并运行成功,本章的内容介绍 .NETCore 的各种常用命令.Asp.Net Core M ...

  8. Sharing is only supported for boot loader classes because bootstrap classpath has been appended

    在idea里面运行项目,terminal里面报“Java HotSpot(TM) 64-Bit Server VM warning: Sharing is only supported for boo ...

  9. linux(centos)下安装supervisor进程管理工具

    在接触supervisor进程管理工具之前,使用springboot打包部署到linux服务器的流程是这样子的,如下图所示: 上图展示的就是最一般的流程,如果项目是小项目或者demo可以这样子去部署, ...

  10. [Python] For 嵌套循环打印图形 nested loop-练习题答案

    前一篇:[Python] For 嵌套循环打印图形 nested loop-练习题 [python的for循环嵌套打印如下图形] 图形一: 输出结果: ******* ******* ******* ...