123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132 |
- import React from 'react';
- import { withRouter } from 'react-router-dom';
- import { Button, Table } from 'antd';
- import { Resizable } from 'react-resizable';
- // class ResizeableTitle extends React.Component {
- // constructor(props) {
- // super(props);
- // }
- //
- // }
- const ResizeableTitle = (props) => {
- const { onResize, width, ...restProps } = props;
- if (!width) {
- return <th {...restProps} />;
- }
- return (
- <Resizable
- width={width}
- height={0}
- handle={
- <span
- className="react-resizable-handle"
- onClick={(e) => {
- e.stopPropagation();
- }}
- />
- }
- onResize={onResize}
- draggableOpts={{ enableUserSelectHack: false }}
- >
- <th {...restProps} />
- </Resizable>
- );
- };
- export default class List extends React.Component {
- state = {
- columns: [
- {
- title: 'Date',
- dataIndex: 'date',
- width: 200,
- },
- {
- title: 'Amount',
- dataIndex: 'amount',
- width: 100,
- sorter: (a, b) => a.amount - b.amount,
- },
- {
- title: 'Type',
- dataIndex: 'type',
- width: 100,
- },
- {
- title: 'Note',
- dataIndex: 'note',
- width: 100,
- },
- {
- title: 'Action',
- key: 'action',
- render: () => <a>Delete</a>,
- },
- ],
- };
- components = {
- header: {
- cell: ResizeableTitle,
- },
- };
- data = [
- {
- key: 0,
- date: '2018-02-11',
- amount: 120,
- type: 'income',
- note: 'transfer',
- },
- {
- key: 1,
- date: '2018-03-11',
- amount: 243,
- type: 'income',
- note: 'transfer',
- },
- {
- key: 2,
- date: '2018-04-11',
- amount: 98,
- type: 'income',
- note: 'transfer',
- },
- ];
- handleResize = (index) => (e, { size }) => {
- this.setState(({ columns }) => {
- const nextColumns = [...columns];
- nextColumns[index] = {
- ...nextColumns[index],
- width: size.width,
- };
- return { columns: nextColumns };
- });
- };
- render() {
- const columns = this.state.columns.map((col, index) => ({
- ...col,
- onHeaderCell: (column) => ({
- width: column.width,
- onResize: this.handleResize(index),
- }),
- }));
- return (
- <Table
- className={'list-wrapper'}
- bordered
- components={this.components}
- columns={columns}
- dataSource={this.data}
- />
- );
- }
- }
|