ant-design-vue/components/vc-table/demo/column-resize.js

85 lines
1.9 KiB
JavaScript
Raw Normal View History

2018-03-26 11:05:40 +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';
import BaseMixin from '../../_util/BaseMixin';
2018-03-26 11:05:40 +00:00
const ResizeableTitle = (h, props, children) => {
2019-01-12 03:33:27 +00:00
console.log(props);
const { width, ...restProps } = props;
2018-03-26 11:05:40 +00:00
if (!width) {
2019-01-12 03:33:27 +00:00
return <th {...restProps}>{children}</th>;
2018-03-26 11:05:40 +00:00
}
return (
2019-01-12 03:33:27 +00:00
<th {...restProps} width={width}>
{children}
</th>
);
};
2018-03-26 11:05:40 +00:00
export default {
mixins: [BaseMixin],
2019-01-12 03:33:27 +00:00
data() {
2018-03-26 11:05:40 +00:00
return {
columns: [
{ title: 'title1', dataIndex: 'a', key: 'a', width: 100 },
{ id: '123', title: 'title2', dataIndex: 'b', key: 'b', width: 100 },
{ title: 'title3', dataIndex: 'c', key: 'c', width: 200 },
{
2019-01-12 03:33:27 +00:00
title: 'Operations',
dataIndex: '',
key: 'd',
customRender: () => {
return <a href="#">Operations</a>;
2018-03-26 11:05:40 +00:00
},
},
],
data: [
{ a: '123', key: '1' },
{ a: 'cdd', b: 'edd', key: '2' },
{ a: '1333', c: 'eee', d: 2, key: '3' },
],
components: {
header: {
cell: ResizeableTitle,
},
},
2019-01-12 03:33:27 +00:00
};
2018-03-26 11:05:40 +00:00
},
methods: {
2019-01-12 03:33:27 +00:00
handleResize(index) {
2018-03-26 11:05:40 +00:00
return (e, { size }) => {
this.setState(({ columns }) => {
2019-01-12 03:33:27 +00:00
const nextColumns = [...columns];
2018-03-26 11:05:40 +00:00
nextColumns[index] = {
...nextColumns[index],
width: size.width,
2019-01-12 03:33:27 +00:00
};
return { columns: nextColumns };
});
};
2018-03-26 11:05:40 +00:00
},
},
2019-01-12 03:33:27 +00:00
render() {
2018-03-26 11:05:40 +00:00
const columns = this.columns.map((col, index) => ({
...col,
2019-01-12 03:33:27 +00:00
customHeaderCell: column => ({
2018-04-03 14:18:18 +00:00
props: {
width: column.width,
},
on: {
resize: this.handleResize(index),
},
2018-03-26 11:05:40 +00:00
}),
2019-01-12 03:33:27 +00:00
}));
2018-03-26 11:05:40 +00:00
return (
<div>
<h2>Integrate with react-resizable</h2>
<Table components={this.components} columns={columns} data={this.data} />
</div>
2019-01-12 03:33:27 +00:00
);
2018-03-26 11:05:40 +00:00
},
2019-01-12 03:33:27 +00:00
};