ant-design-vue/components/vc-table/demo/key.js

50 lines
1.2 KiB
JavaScript
Raw Normal View History

2018-03-27 11:43:22 +00:00
/* eslint-disable no-console,func-names,react/no-multi-comp */
2019-01-12 03:33:27 +00:00
import Table from '../index';
import '../assets/index.less';
2018-03-27 11:43:22 +00:00
export default {
2019-01-12 03:33:27 +00:00
data() {
2018-03-27 11:43:22 +00:00
return {
data: [{ a: '123' }, { a: 'cdd', b: 'edd' }, { a: '1333', c: 'eee', d: 2 }],
2019-01-12 03:33:27 +00:00
};
2018-03-27 11:43:22 +00:00
},
methods: {
2019-01-12 03:33:27 +00:00
remove(index) {
const rows = this.data;
rows.splice(index, 1);
this.data = rows;
2018-03-27 11:43:22 +00:00
},
2019-01-12 03:33:27 +00:00
handleClick(index) {
this.remove(index);
2018-03-27 11:43:22 +00:00
},
2019-01-12 03:33:27 +00:00
checkbox(a) {
return (
<label>
<input type="checkbox" />
{a}
</label>
);
2018-03-27 11:43:22 +00:00
},
2019-01-12 03:33:27 +00:00
renderAction(o, row, index) {
return (
<a href="javascript:;" onClick={() => this.handleClick(index)}>
Delete
</a>
);
2018-03-27 11:43:22 +00:00
},
},
2019-01-12 03:33:27 +00:00
render() {
2018-03-27 11:43:22 +00:00
const columns = [
2018-04-01 04:52:27 +00:00
{ title: 'title1', dataIndex: 'a', key: 'a', width: 100, customRender: this.checkbox },
2018-03-27 11:43:22 +00:00
{ title: 'title2', dataIndex: 'b', key: 'b', width: 100 },
{ title: 'title3', dataIndex: 'c', key: 'c', width: 200 },
2018-04-01 04:52:27 +00:00
{ title: 'Operations', dataIndex: '', key: 'x', customRender: this.renderAction },
2019-01-12 03:33:27 +00:00
];
return <Table columns={columns} data={this.data} class="table" rowKey={record => record.a} />;
2018-03-27 11:43:22 +00:00
},
2019-01-12 03:33:27 +00:00
};