Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When using virtual rendering and column drag-and-drop sorting simultaneously, they don't work well together #5689

Open
2 tasks done
songchengen opened this issue Aug 2, 2024 · 3 comments

Comments

@songchengen
Copy link

songchengen commented Aug 2, 2024

TanStack Table version

v8.19.3

Framework/Library version

React V18.3.1; @tanstack/react-virtual V3.8.3; @dnd-kit/core v6.1.0

Describe the bug and the steps to reproduce it

  1. Slightly scroll the table body so that the scrollbar is not at the top.
  2. Try dragging the icon in the table header cell to sort.
  3. During the dragging process, slightly jiggle the mouse upwards. When you observe the scrollbar in the table body starting to scroll automatically, column sorting is no longer possible.
  4. You can only continue to drag and sort after refreshing the page.

Your Minimal, Reproducible Example - (Sandbox Highly Recommended)

https://stackblitz.com/edit/tanstack-table-vpkdmn?file=src%2Fmain.tsx

Screenshots or Videos (Optional)

No response

Do you intend to try to help solve this bug with your own PR?

No, because I do not know how

Terms & Code of Conduct

  • I agree to follow this project's Code of Conduct
  • I understand that if my bug cannot be reliable reproduced in a debuggable environment, it will probably not be fixed and this issue may even be closed.
@xHeaven
Copy link

xHeaven commented Aug 7, 2024

We are experiencing this exact same issue.

Our current workaround is setting the y to 0 on transform for both the header and the body so that none of them glitches upwards.

import { useSortable } from '@dnd-kit/sortable';
import { CSS } from '@dnd-kit/utilities';
import { Cell, flexRender } from '@tanstack/react-table';
import { cn } from '@/lib/shadcn-utils';

const DragAlongCell = ({ cell }: { cell: Cell<any, unknown> }) => {
  const { isDragging, setNodeRef, transform } = useSortable({
    id: cell.column.id
  });
  return (
    <div
      style={{
        transform: CSS.Translate.toString({ ...transform!, y: 0 }), // this is the "fix"
        width: `${cell?.column.getSize()}px`,
        minWidth: `${cell.column.columnDef.minSize}px`
      }}
      ref={setNodeRef}
      className={cn(
        'flex items-center relative transition-all transform duration-100 ease-linear py-1 px-3 text-sm w-full h-full',
        isDragging ? 'z-[1] opacity-80' : 'opacity-100'
      )}
    >
      <div className="w-full">{flexRender(cell.column.columnDef.cell, cell.getContext())}</div>
    </div>
  );
};

export default DragAlongCell;

@songchengen
Copy link
Author

I solved it in the same way and will optimize it later. I hope to achieve the effect of ag-grid.

@jayvhaile
Copy link

jayvhaile commented Aug 17, 2024

I solved it in the same way and will optimize it later. I hope to achieve the effect of ag-grid.

Could you please share the fix?, experiencing the same problem, i tried setting the y to 0 on transform but still same...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants