import React from 'react';
import { Table } from 'antd';
import {
SortableContainer,
SortableElement,
SortableHandle,
} from 'react-sortable-hoc';
const SortableItem = SortableElement((props: any) =>
);
const NewSortableContainer = SortableContainer((props: any) => (
));
export interface IProps {
tablesize?: any;
tableConfig?: any;
draggable?: boolean | (() => boolean);
handleOnSortEnd?: (oldIndex: number, newIndex: number) => void;
}
const Tables: React.FC = (props: IProps) => {
let { handleOnSortEnd, tablesize, tableConfig, draggable } = props;
const onSortEnd = (props: any) => {
const { oldIndex, newIndex } = props;
if (handleOnSortEnd && oldIndex !== newIndex)
handleOnSortEnd(oldIndex, newIndex);
};
const DragHandle = SortableHandle(() => (
));
const DraggableContainer = (props: any) => {
return (
);
};
const DraggableBodyRow = (props: any) => {
const { style, ...restProps } = props;
const { dataSource } = tableConfig;
const index = dataSource.findIndex(
(x: any) => x.key === restProps['data-row-key'],
);
return ;
};
if (draggable) {
tableConfig = {
...tableConfig,
columns: [
{
title: '',
dataIndex: 'sort',
width: 48,
className: 'drag-visible',
render: () => ,
},
...tableConfig.columns.filter(
(item: any) => item.filterType && item.filterType === true,
),
],
components: {
body: {
wrapper: DraggableContainer,
row: DraggableBodyRow,
},
},
};
}
return ;
};
export default Tables;