diff --git a/components/apolloTable/component/DragSorted.tsx b/components/apolloTable/component/DragSorted.tsx new file mode 100644 index 0000000000000000000000000000000000000000..0fd5bc16b4aeb40fad2b0923bd63f76d1d252cd1 --- /dev/null +++ b/components/apolloTable/component/DragSorted.tsx @@ -0,0 +1,28 @@ +import React, { useCallback } from 'react'; +import { Draggable } from 'react-beautiful-dnd'; + +const DragSorted = (props) => { + // using useCallback is optional + const onBeforeCapture = useCallback(() => {}, []); + const onBeforeDragStart = useCallback(() => {}, []); + const onDragStart = useCallback(() => { + debugger; + }, []); + const onDragUpdate = useCallback(() => {}, []); + const onDragEnd = useCallback(() => {}, []); + + return ( + + {(provided, snapshot) => ( +
+ {props.children} +
+ )} +
+ ); +}; +export default DragSorted; diff --git a/components/apolloTable/component/Table.tsx b/components/apolloTable/component/Table.tsx index 04a35b81d8cd39e15b1e3be32a71101a1eb27cf9..b2628d1ce791ce86c0e45fd268b0709a1d501289 100644 --- a/components/apolloTable/component/Table.tsx +++ b/components/apolloTable/component/Table.tsx @@ -2,6 +2,7 @@ import React, { Component } from 'react'; import classNames from 'classnames'; import memoizeOne from 'memoize-one'; import { Empty, Spin } from 'antd'; +import { DragDropContext, Droppable } from 'react-beautiful-dnd'; import { ScrollSync, Grid, AutoSizer } from 'react-virtualized'; import { Resizable, ResizableBox } from 'react-resizable'; import _ from 'lodash'; @@ -11,6 +12,7 @@ import { TableProps, TableState, ColumnProps, RowProps } from './interface'; import Column from './Column'; import Cell from './Cell'; import LeftDragFixed from './DragFixed'; +import DragSorted from './DragSorted'; import { getMergeClassName, getMergeStyle } from '../utils/utils'; import { Consumer } from './context'; @@ -302,38 +304,40 @@ export default class AirTable extends Component { } = showColumns[columnIndex]; return (
- { - e.stopPropagation(); - }} + + { + e.stopPropagation(); + }} + /> + } + minConstraints={[100, 100]} + onResize={this.onResizeWidth} + onResizeStart={this.onResizeWidthStart} + onResizeStop={this.onResizeWidthStop.bind(this, columnName)} + draggableOpts={{ enableUserSelectHack: false }} + > + - } - minConstraints={[100, 100]} - onResize={this.onResizeWidth} - onResizeStart={this.onResizeWidthStart} - onResizeStop={this.onResizeWidthStop.bind(this, columnName)} - draggableOpts={{ enableUserSelectHack: false }} - > - - + +
); }; @@ -470,300 +474,344 @@ export default class AirTable extends Component { {({ onScroll, scrollLeft, scrollTop }: any) => { return ( -
{ - this.tableContainer = dom; - }} - > - {totalWidth > tableWidth && leftCount > 0 && ( -
- { - // 左侧表头 + + + {(provided, snapshot) => ( +
- { - this.grid1 = dom; - }} - className={styles.headerGrid} - columnWidth={this.getColumnWidth.bind(this, { - columns: showColumns, - showColumns: leftColumns, - })} - columnCount={leftCount} - width={leftWidth} - rowHeight={headerHeight} - rowCount={1} - height={headerHeight} - cellRenderer={this.renderHeaderCell.bind(this, { - showColumns: leftColumns, - })} - /> -
- } - { - // 左侧固定列 -
{ + this.tableContainer = dom; }} > - { - this.grid2 = dom; - }} - className={styles.sideGrid} - overscanRowCount={overscanRowCount} - cellRenderer={this.renderBodyCell.bind(this, { - showColumns: leftColumns, - showData: leftData, - position: 'left', - })} - columnWidth={this.getColumnWidth.bind(this, { - columns: showColumns, - showColumns: leftColumns, - })} - onScroll={(...arg: Array) => { - onScroll({ scrollTop: arg[0].scrollTop }); - this.onScroll(arg[0]); - }} - columnCount={leftCount} - width={leftWidth + scrollbarWidth} - rowHeight={rowHeight} - rowCount={rowCount} - height={totalHeight - scrollbarWidth} - scrollTop={scrollTop} - /> - - } - - )} - {canFixed && ( - - )} -
- - {({ width, height }: any) => { - return ( -
- { - // 中部表头 -
- { - this.grid3 = dom; + {totalWidth > tableWidth && leftCount > 0 && ( +
+ { + // 左侧表头 +
+ { + this.grid1 = dom; + }} + className={styles.headerGrid} + columnWidth={this.getColumnWidth.bind(this, { + columns: showColumns, + showColumns: leftColumns, + })} + columnCount={leftCount} + width={leftWidth} + rowHeight={headerHeight} + rowCount={1} + height={headerHeight} + cellRenderer={this.renderHeaderCell.bind(this, { + showColumns: leftColumns, + })} + /> +
+ } + { + // 左侧固定列 +
-
- } - { - // 中部内容 -
- {rowCount > 0 ? ( + > { - this.grid4 = dom; + this.grid2 = dom; }} - className={styles.centerGrid} - overscanColumnCount={overscanColumnCount} + className={styles.sideGrid} overscanRowCount={overscanRowCount} + cellRenderer={this.renderBodyCell.bind(this, { + showColumns: leftColumns, + showData: leftData, + position: 'left', + })} columnWidth={this.getColumnWidth.bind(this, { columns: showColumns, - showColumns, + showColumns: leftColumns, })} - columnCount={columnCount} - width={realWidth} - rowHeight={rowHeight} - rowCount={rowCount} onScroll={(...arg: Array) => { - onScroll(...arg); + onScroll({ scrollTop: arg[0].scrollTop }); this.onScroll(arg[0]); }} + columnCount={leftCount} + width={leftWidth + scrollbarWidth} + rowHeight={rowHeight} + rowCount={rowCount} + height={totalHeight - scrollbarWidth} scrollTop={scrollTop} - height={totalHeight} + /> + + } + + )} + {canFixed && ( + + )} +
+ + {({ width, height }: any) => { + return ( +
+ { + // 中部表头 +
+ { + this.grid3 = dom; + }} + className={styles.headerGrid} + overscanColumnCount={ + overscanColumnCount + } + columnWidth={this.getColumnWidth.bind( + this, + { + columns: showColumns, + showColumns, + }, + )} + columnCount={columnCount} + width={width} + rowHeight={headerHeight} + rowCount={1} + height={headerHeight} + scrollLeft={scrollLeft} + cellRenderer={this.renderHeaderCell.bind( + this, + { + showColumns, + }, + )} + /> +
+ } + { + // 中部内容 +
+ {rowCount > 0 ? ( + { + this.grid4 = dom; + }} + className={styles.centerGrid} + overscanColumnCount={ + overscanColumnCount + } + overscanRowCount={ + overscanRowCount + } + columnWidth={this.getColumnWidth.bind( + this, + { + columns: showColumns, + showColumns, + }, + )} + columnCount={columnCount} + width={realWidth} + rowHeight={rowHeight} + rowCount={rowCount} + onScroll={( + ...arg: Array + ) => { + onScroll(...arg); + this.onScroll(arg[0]); + }} + scrollTop={scrollTop} + height={totalHeight} + cellRenderer={this.renderBodyCell.bind( + this, + { + showColumns, + showData, + position: 'center', + }, + )} + /> + ) : ( + columnCount > 0 && + !loading && ( + + ) + )} + + } + + ); + }} + + + {totalWidth > tableWidth && rightCount > 0 && ( +
+ { + // 右侧表头 +
+ { + this.grid5 = dom; + }} + className={styles.headerGrid} + columnWidth={this.getColumnWidth.bind(this, { + columns: showColumns, + showColumns: rightColumns, + })} + columnCount={rightCount} + width={rightWidth} + rowHeight={headerHeight} + rowCount={1} + height={headerHeight} + cellRenderer={this.renderHeaderCell.bind(this, { + showColumns: rightColumns, + position: 'right', + })} + /> +
+ } + { + // 右侧固定列 +
+ { + this.grid6 = dom; + }} + className={styles.sideGrid} + overscanRowCount={overscanRowCount} cellRenderer={this.renderBodyCell.bind(this, { - showColumns, - showData, - position: 'center', + showColumns: rightColumns, + showData: rightData, + position: 'right', + })} + columnWidth={this.getColumnWidth.bind(this, { + columns: showColumns, + showColumns: rightColumns, })} + onScroll={(...arg: Array) => { + onScroll({ scrollTop: arg[0].scrollTop }); + this.onScroll(arg[0]); + }} + columnCount={rightCount} + width={rightWidth + scrollbarWidth} + rowHeight={rowHeight} + rowCount={rowCount} + height={totalHeight - scrollbarWidth} + scrollTop={scrollTop} /> - ) : ( - columnCount > 0 && - !loading && ( - - ) - )} - - } + + } + + )} +
+
+ {loading && (loadComp ? loadComp : )}
- ); - }} - -
- {totalWidth > tableWidth && rightCount > 0 && ( -
- { - // 右侧表头 -
- { - this.grid5 = dom; +
{ + this.widthHandleWrapper = dom; }} - className={styles.headerGrid} - columnWidth={this.getColumnWidth.bind(this, { - columns: showColumns, - showColumns: rightColumns, - })} - columnCount={rightCount} - width={rightWidth} - rowHeight={headerHeight} - rowCount={1} - height={headerHeight} - cellRenderer={this.renderHeaderCell.bind(this, { - showColumns: rightColumns, - position: 'right', - })} - /> -
- } - { - // 右侧固定列 -
- { - this.grid6 = dom; - }} - className={styles.sideGrid} - overscanRowCount={overscanRowCount} - cellRenderer={this.renderBodyCell.bind(this, { - showColumns: rightColumns, - showData: rightData, - position: 'right', - })} - columnWidth={this.getColumnWidth.bind(this, { - columns: showColumns, - showColumns: rightColumns, - })} - onScroll={(...arg: Array) => { - onScroll({ scrollTop: arg[0].scrollTop }); - this.onScroll(arg[0]); - }} - columnCount={rightCount} - width={rightWidth + scrollbarWidth} - rowHeight={rowHeight} - rowCount={rowCount} - height={totalHeight - scrollbarWidth} - scrollTop={scrollTop} - /> + > +
{ + this.widthHandle = dom; + }} + /> +
- } - - )} -
-
- {loading && (loadComp ? loadComp : )} -
-
{ - this.widthHandleWrapper = dom; - }} - > -
{ - this.widthHandle = dom; - }} - /> -
-
+ {provided.placeholder} +
+ )} + + ); }}