diff --git a/components/apolloTable/component/DragSorted.tsx b/components/apolloTable/component/DragSorted.tsx index 39806062a21a7b67fd3fa6aa6400b616ed2a60aa..2c745f11f2621e1efb0373a1d980b0fd0d305e2a 100644 --- a/components/apolloTable/component/DragSorted.tsx +++ b/components/apolloTable/component/DragSorted.tsx @@ -3,7 +3,7 @@ import classNames from 'classnames'; const DragSorted = (props: any) => { const { - className, style, columnName, orderNo, onDropFinish, onScroll, + className, style, columnName, orderNo, onDropFinish, onScroll, canDrag, } = props; // 长按计时器 const timer: any = useRef(null); @@ -142,7 +142,7 @@ const DragSorted = (props: any) => { const onMouseDown = useCallback( (e) => { // 没有拖拽回调,默认不支持拖拽事件 - if (!onDropFinish) { + if (!canDrag) { return; } // 不是左键点击不作处理 diff --git a/components/apolloTable/component/Table.tsx b/components/apolloTable/component/Table.tsx index e51e95672faa0083b7d56bb4cfc4fecb63c7fa5d..0a23587a961a50e226d1b5583684319da114dc45 100644 --- a/components/apolloTable/component/Table.tsx +++ b/components/apolloTable/component/Table.tsx @@ -292,6 +292,7 @@ export default class AirTable extends Component { this.grid4.scrollToCell({ columnIndex: showColumns.length - 1 }); } }; + // 拖拽滚动表格 onScrollHor = (direction: string, step: number) => { // 拖动超过视图范围,将表格左右滚动 if (this.grid4) { @@ -310,6 +311,51 @@ export default class AirTable extends Component { } } }; + // 拖拽排序回调 + onDragSorted = (dragColumn:any, dropColumn:any) => { + const { onDragSorted } = this.props; + const { columns } = this.state; + const newColumns:any[] = []; + columns.map((item) => { + if (dragColumn.orderNo > dropColumn.orderNo) { + if (item.orderNo >= dropColumn.orderNo && item.orderNo <= dragColumn.orderNo) { + if (item.columnName === dragColumn.columnName) { + newColumns.push({ + ...item, + orderNo: dropColumn.orderNo, + }); + } else { + newColumns.push({ + ...item, + orderNo: item.orderNo + 1, + }); + } + } else { + newColumns.push(item); + } + } else { + if (item.columnName === dragColumn.columnName) { + newColumns.push({ + ...item, + orderNo: dropColumn.orderNo - 1, + }); + } else if (item.orderNo >= dragColumn.orderNo && item.orderNo <= dropColumn.orderNo) { + newColumns.push({ + ...item, + orderNo: item.orderNo - 1, + }); + } else { + newColumns.push(item); + } + } + }); + newColumns.sort((a, b) => { + return a.orderNo - b.orderNo; + }); + if (typeof onDragSorted === 'function') { + onDragSorted(newColumns); + } + }; // 渲染表头 renderHeaderCell = ( { showColumns, position }: { showColumns: ColumnProps[]; position?: string }, @@ -332,11 +378,12 @@ export default class AirTable extends Component {