[置顶] element-ui 表格实现单元格可编辑的方法
2017-06-30 20:56
1431 查看
<template>
<el-table
:data="tableData"
border
@cell-mouse-enter="handleMouseEnter"
@cell-mouse-leave="handleMouseOut"
style="width: 100%">
<el-table-column
label="日期"
width="180">
<template scope="scope">
<span v-if="!scope.row.editFlag">{{ scope.row.name }}</span>
<span v-if="scope.row.editFlag" class="cell-edit-input"><el-input v-model="inputColumn1" placeholder="请输入内容"></el-input></span>
<span v-if="!scope.row.editFlag" style="margin-left:10px;" class="cell-icon" @click="handleEdit(scope.row)"> <i class="el-icon-edit"></i> </span>
<span v-if="scope.row.editFlag" style="margin-left:10px;" class="cell-icon" @click="handleSave(scope.row)"> <i class="el-icon-document"></i> </span>
</template>
</el-table-column>
</el-table>
</template>
<script>
export default{
data(){
return {
tableData:[
{
name:"test",
editeFlage:false
},
{
name:"test",
editeFlage:false
},
{
name:"test",
editeFlage:false
},
{
name:"test",
editeFlage:false
},
],
inputColumn1:""//第一列的输入框
}
},
methods:{
handleEdit:function(row){
//遍历数组改变editeFlag
},
handleSave:function(row){
//保存数据,向后台取数据
},
handleMouseEnter:function(row, column, cell, event){
cell.children[0].children[1].style.color="black";
},
handleMouseOut:function(row, column, cell, event){
cell.children[0].children[1].style.color="#ffffff";
}
}
}
</script>
<style>
.cell-edit-input .el-input, .el-input__inner {
width:100px;
}
.cell-icon{
cursor:pointer;
color:#fff;
}
</style>
<el-table
:data="tableData"
border
@cell-mouse-enter="handleMouseEnter"
@cell-mouse-leave="handleMouseOut"
style="width: 100%">
<el-table-column
label="日期"
width="180">
<template scope="scope">
<span v-if="!scope.row.editFlag">{{ scope.row.name }}</span>
<span v-if="scope.row.editFlag" class="cell-edit-input"><el-input v-model="inputColumn1" placeholder="请输入内容"></el-input></span>
<span v-if="!scope.row.editFlag" style="margin-left:10px;" class="cell-icon" @click="handleEdit(scope.row)"> <i class="el-icon-edit"></i> </span>
<span v-if="scope.row.editFlag" style="margin-left:10px;" class="cell-icon" @click="handleSave(scope.row)"> <i class="el-icon-document"></i> </span>
</template>
</el-table-column>
</el-table>
</template>
<script>
export default{
data(){
return {
tableData:[
{
name:"test",
editeFlage:false
},
{
name:"test",
editeFlage:false
},
{
name:"test",
editeFlage:false
},
{
name:"test",
editeFlage:false
},
],
inputColumn1:""//第一列的输入框
}
},
methods:{
handleEdit:function(row){
//遍历数组改变editeFlag
},
handleSave:function(row){
//保存数据,向后台取数据
},
handleMouseEnter:function(row, column, cell, event){
cell.children[0].children[1].style.color="black";
},
handleMouseOut:function(row, column, cell, event){
cell.children[0].children[1].style.color="#ffffff";
}
}
}
</script>
<style>
.cell-edit-input .el-input, .el-input__inner {
width:100px;
}
.cell-icon{
cursor:pointer;
color:#fff;
}
</style>
相关文章推荐
- element-ui 表格实现单元格可编辑的示例
- Element UI 中可展开表格手风琴效果实现(toggleRowExpansion方法的正确使用方式)
- 单击单元格实现可编辑的表格(学号和姓名下)
- JavaScript简单表格编辑功能实现方法
- vue+element-ui+ajax实现一个表格的实例
- 请教方法和例子:VS2003的datagrid控件,如何实现用鼠标拖动的方法选中任意区域的多个单元格,然后进行统一编辑??
- element-ui 表格数据时间格式化的方法
- FineUI大版本升级,外置ExtJS库、去AXD化、表格合计行、表格可编辑单元格的增删改、顶部菜单框架
- [置顶] 用Vue、element-ui、axios实现省市区三级联动
- 利用vue + element实现表格分页和前端搜索的方法
- JS实现控制表格单元格垂直对齐的方法
- 利用vue+elementUI实现部分引入组件的方法详解
- jQuery实现表格行上移下移和置顶的方法
- vue.js与element-ui实现菜单树形结构的解决方法
- 表格边框/单元格之间分隔线的隐藏实现方法
- JS实现控制表格内指定单元格内容对齐的方法
- 微信小程序实现一个可以编辑单元格的表格
- grid中显示blobImage上传的图片 通过本案例,我们实现blobImage上传的图片在grid表格中的显示。 grid的cellRender方法渲染单元格显示图片,例: 1 2 3 4 5
- vue2.0 使用element-ui里的upload组件实现图片预览效果方法