Skip to content

Commit ebc2ac0

Browse files
committed
add(inlineEditable): add the calcel btn to restore the title
1 parent a9d2978 commit ebc2ac0

File tree

1 file changed

+36
-4
lines changed

1 file changed

+36
-4
lines changed

src/views/example/table/inlineEditTable.vue

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,18 @@
3535

3636
<el-table-column min-width="300px" label="标题">
3737
<template slot-scope="scope">
38-
<el-input v-show="scope.row.edit" size="small" v-model="scope.row.title"></el-input>
39-
<span v-show="!scope.row.edit">{{ scope.row.title }}</span>
38+
<template v-if="scope.row.edit">
39+
<el-input class="edit-input" size="small" v-model="scope.row.title"></el-input>
40+
<el-button class='cancel-btn' size="small" icon="el-icon-refresh" type="warning" @click="cancelEdit(scope.row)">cancel</el-button>
41+
</template>
42+
<span v-else>{{ scope.row.title }}</span>
4043
</template>
4144
</el-table-column>
4245

4346
<el-table-column align="center" label="编辑" width="120">
4447
<template slot-scope="scope">
45-
<el-button :type="scope.row.edit?'success':'primary'" @click='scope.row.edit=!scope.row.edit' size="small" icon="edit">{{scope.row.edit?'完成':'编辑'}}</el-button>
48+
<el-button v-if="scope.row.edit" type="success" @click="confirmEdit(scope.row)" size="small" icon="el-icon-circle-check-outline">完成</el-button>
49+
<el-button v-else type="primary" @click='scope.row.edit=!scope.row.edit' size="small" icon="el-icon-edit">编辑</el-button>
4650
</template>
4751
</el-table-column>
4852

@@ -84,12 +88,40 @@ export default {
8488
fetchList(this.listQuery).then(response => {
8589
const items = response.data.items
8690
this.list = items.map(v => {
87-
this.$set(v, 'edit', false)
91+
this.$set(v, 'edit', false) // https://vuejs.org/v2/guide/reactivity.html
92+
v.originalTitle = v.title // will be used when user click the cancel botton
8893
return v
8994
})
9095
this.listLoading = false
9196
})
97+
},
98+
cancelEdit(row) {
99+
row.title = row.originalTitle
100+
row.edit = false
101+
this.$message({
102+
message: 'The title has been restored to the original value',
103+
type: 'warning'
104+
})
105+
},
106+
confirmEdit(row) {
107+
row.edit = false
108+
row.originalTitle = row.title
109+
this.$message({
110+
message: 'The title has been edited',
111+
type: 'success'
112+
})
92113
}
93114
}
94115
}
95116
</script>
117+
118+
<style scoped>
119+
.edit-input {
120+
padding-right: 100px;
121+
}
122+
.cancel-btn {
123+
position: absolute;
124+
right: 15px;
125+
top: 13px;
126+
}
127+
</style>

0 commit comments

Comments
 (0)