# table 在线表格编辑
onInit() {
//如果是企业版代码,代码生成器上选择编辑模式【表格行内编辑】就不用下面配置了
for (let index = 0; index < this.columns.length; index++) {
const column = this.columns[index];
if (column.field == 'Province') {
column.edit = { type: 'select', keep: true };
//同时可以给表格下拉框绑定选择事件
column.onChange = (row, col) => {
console.log(row.Province);
};
} else if (column.field == 'PhoneNo') {
column.edit = { type: 'text', keep: true };
}
}
//最后添加一行保存按钮
this.columns.push({
title: '操作', //按钮名称
field: '操作',
align: 'center',
width: 70,
fixed:'right',
render: (h, { row, column, index }) => {
return (
<div>
<el-button
onClick={($e) => {
//调用框架的保存方法,或者自己写接口保存
this.http.post('/api/Demo_Customer/update', { mainData: row }, true)
.then((x) => {
if (x.status) {
this.$message.info('保存成功');
return;
}
this.$message.error(x.message);
});
}}
style=" height:23px;padding: 0px 8px !important;"
size="small"
type="primary"
plain
>
保存
</el-button>
{/* 这里可以接着放按钮或者其他组件 */}
</div>
);
}
});
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51