|
@@ -1,23 +1,97 @@
|
|
|
import { Table, Popconfirm, Button } from 'antd';
|
|
|
+import { Resizable } from 'react-resizable';
|
|
|
+import './ProductList.less';
|
|
|
|
|
|
-const ProductList = ({ onDelete, products }) => {
|
|
|
- const columns = [
|
|
|
- {
|
|
|
- title: 'Name',
|
|
|
- dataIndex: 'name',
|
|
|
- },
|
|
|
- {
|
|
|
- title: 'Actions',
|
|
|
- render: (text, record) => {
|
|
|
- return (
|
|
|
- <Popconfirm title="Delete?" onConfirm={() => onDelete(record.id)}>
|
|
|
- <Button>Delete</Button>
|
|
|
- </Popconfirm>
|
|
|
- );
|
|
|
- },
|
|
|
+const ResizeableTitle = props => {
|
|
|
+ const { onResize, width, ...restProps } = props;
|
|
|
+
|
|
|
+ if (!width) {
|
|
|
+ return <th {...restProps} />;
|
|
|
+ }
|
|
|
+ // console.log(88888, width, props);
|
|
|
+ return (
|
|
|
+ <Resizable
|
|
|
+ width={width}
|
|
|
+ height={0}
|
|
|
+ handle={
|
|
|
+ <span
|
|
|
+ className="react-resizable-handle"
|
|
|
+ onClick={e => {
|
|
|
+ e.stopPropagation();
|
|
|
+ }}
|
|
|
+ />
|
|
|
+ }
|
|
|
+ onResize={onResize}
|
|
|
+ draggableOpts={{ enableUserSelectHack: false }}
|
|
|
+ >
|
|
|
+ <th {...restProps} />
|
|
|
+ </Resizable>
|
|
|
+ );
|
|
|
+};
|
|
|
+const components = {
|
|
|
+ header: {
|
|
|
+ cell: ResizeableTitle,
|
|
|
+ },
|
|
|
+};
|
|
|
+const ProductList = state => {
|
|
|
+ // setState
|
|
|
+ const { onDelete, products } = state;
|
|
|
+ // console.log(state);
|
|
|
+
|
|
|
+ let columns = [];
|
|
|
+ const handleResize = index => (e, { size }) => {
|
|
|
+ console.log(size);
|
|
|
+ console.log(setState);
|
|
|
+
|
|
|
+ const nextColumns = [...columns];
|
|
|
+ nextColumns[index] = {
|
|
|
+ ...nextColumns[index],
|
|
|
+ width: size.width,
|
|
|
+ };
|
|
|
+ columns = nextColumns;
|
|
|
+ };
|
|
|
+ for (let i = 0; i < 15; i++) {
|
|
|
+ columns.push({
|
|
|
+ title: `Name${i + 1}`,
|
|
|
+ dataIndex: `name${i + 1}`,
|
|
|
+ width: 100,
|
|
|
+ onHeaderCell: column => ({
|
|
|
+ width: column.width,
|
|
|
+ onResize: handleResize(i),
|
|
|
+ }),
|
|
|
+ });
|
|
|
+ }
|
|
|
+ columns[0].fixed = 'left';
|
|
|
+ columns.push({
|
|
|
+ title: 'Actions',
|
|
|
+ fixed: 'right',
|
|
|
+ render: (text, record) => {
|
|
|
+ return (
|
|
|
+ <Popconfirm title="Delete?" onConfirm={() => onDelete(record.id)}>
|
|
|
+ <Button>Delete</Button>
|
|
|
+ </Popconfirm>
|
|
|
+ );
|
|
|
},
|
|
|
- ];
|
|
|
- return <Table dataSource={products} columns={columns} />;
|
|
|
+ });
|
|
|
+
|
|
|
+ function setWidth() {
|
|
|
+ columns[2].width = columns[2].width * 1.1;
|
|
|
+ console.log(2131, columns[2]);
|
|
|
+ }
|
|
|
+
|
|
|
+ return (
|
|
|
+ <div>
|
|
|
+ <Button onClick={e => setWidth()}>12313</Button>
|
|
|
+ <Table
|
|
|
+ bordered
|
|
|
+ className={'tast'}
|
|
|
+ dataSource={products}
|
|
|
+ components={components}
|
|
|
+ scroll={{ x: 1600, y: 340 }}
|
|
|
+ columns={columns}
|
|
|
+ />
|
|
|
+ </div>
|
|
|
+ );
|
|
|
};
|
|
|
|
|
|
export default ProductList;
|