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

57 lines
1.3 KiB
JavaScript
Raw Normal View History

2018-11-09 10:57:25 +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-11-09 10:57:25 +00:00
const data = [
{ key: 0, a: '123' },
{ key: 1, a: 'cdd', b: 'edd' },
{ key: 2, a: '1333', c: 'eee', d: 2 },
2019-01-12 03:33:27 +00:00
];
2018-11-09 10:57:25 +00:00
const columns = [
{ title: 'title 1', dataIndex: 'a', key: 'a', width: 100 },
{ title: 'title 2', dataIndex: 'b', key: 'b', width: 100 },
{ title: 'title 3', dataIndex: 'c', key: 'c', width: 200 },
2019-01-12 03:33:27 +00:00
];
2018-11-09 10:57:25 +00:00
export default {
methods: {
2019-01-12 03:33:27 +00:00
CustomExpandIcon(props) {
let text;
2018-11-09 10:57:25 +00:00
if (props.expanded) {
2019-01-12 03:33:27 +00:00
text = <span>&#8679; collapse</span>;
2018-11-09 10:57:25 +00:00
} else {
2019-01-12 03:33:27 +00:00
text = <span>&#8681; expand</span>;
2018-11-09 10:57:25 +00:00
}
return (
<a
2019-01-12 03:33:27 +00:00
class="expand-row-icon"
2018-11-09 10:57:25 +00:00
onClick={e => props.onExpand(props.record, e)}
style={{ color: 'blue', cursor: 'pointer' }}
2019-01-12 03:33:27 +00:00
>
{text}
</a>
);
2018-11-09 10:57:25 +00:00
},
2019-01-12 03:33:27 +00:00
onExpand(expanded, record) {
console.log('onExpand', expanded, record);
2018-11-09 10:57:25 +00:00
},
},
2019-01-12 03:33:27 +00:00
render() {
2018-11-09 10:57:25 +00:00
return (
<div>
<h2>expandIcon</h2>
<div>
<Table
columns={columns}
expandedRowRender={record => <p>extra: {record.a}</p>}
onExpand={this.onExpand}
expandIcon={this.CustomExpandIcon}
expandIconAsCell
data={data}
/>
</div>
</div>
2019-01-12 03:33:27 +00:00
);
2018-11-09 10:57:25 +00:00
},
2019-01-12 03:33:27 +00:00
};