react antd table react-sortable-hoc DraggableBodyRow 拖拽及禁用指定行拖拽

发布时间 2023-12-07 20:01:40作者: 最好的年纪

原文地址:基于antd树形表格table的拖拽排序效果实现 - 掘金 (juejin.cn)

思路片段:

const DraggableBodyRow: React.FC<any> = ({ className, style, ...restProps }) => {
    const index = customInfoList.findIndex(
      ({ order: _index }) => _index === restProps['data-row-key'],
    );
    // 头两行禁用
    if ([0, 1].includes(index)) {
      return (
        <tr
          className={className}
          // style={isDrag ? { cursor: 'move', opacity, ...style } : { ...style }}
          // data-handler-id={handlerId}
          {...restProps}
        />
      );
    }

    return <SortableItem index={index} className={className} {...restProps} />;
  };