You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ant-design-vue/components/vc-table/demo/column-resize.js

77 lines
1.8 KiB

7 years ago
/* eslint-disable no-console,func-names,react/no-multi-comp */
import Table from '../index'
import '../assets/index.less'
import BaseMixin from '../../_util/BaseMixin'
const ResizeableTitle = (h, props, children) => {
console.log(props)
const { onResize, width, ...restProps } = props
if (!width) {
return <th {...restProps} >{children}</th>
}
return (
<th {...restProps} width={width}>{children}</th>
)
}
export default {
mixins: [BaseMixin],
data () {
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 },
{
title: 'Operations', dataIndex: '', key: 'd', render () {
return <a href='#'>Operations</a>
},
},
],
data: [
{ a: '123', key: '1' },
{ a: 'cdd', b: 'edd', key: '2' },
{ a: '1333', c: 'eee', d: 2, key: '3' },
],
components: {
header: {
cell: ResizeableTitle,
},
},
}
},
methods: {
handleResize (index) {
return (e, { size }) => {
this.setState(({ columns }) => {
const nextColumns = [...columns]
nextColumns[index] = {
...nextColumns[index],
width: size.width,
}
return { columns: nextColumns }
})
}
},
},
render () {
const columns = this.columns.map((col, index) => ({
...col,
7 years ago
customHeaderCell: (column) => ({
7 years ago
width: column.width,
onResize: this.handleResize(index),
}),
}))
return (
<div>
<h2>Integrate with react-resizable</h2>
<Table components={this.components} columns={columns} data={this.data} />
</div>
)
},
}