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

Fix: allow reordering pinned columns #1110

Open
wants to merge 1 commit into
base: v2
Choose a base branch
from

Conversation

knissley
Copy link

I noticed that while having enableColumnOrdering, enableColumnPinning, and enableColumnDragging enabled the reorder action didn't impact the order of the pinned columns from either the drag handle or from the columns menu.

Example:

column-pin-reordering.mov

I had two approaches in mind to fix this

  • Add a setState change in the event handler for MRT_TableHeadCellGrabHandle and MRT_ShowHideColumnsMenuItems to reorder the pins where appropriate (columns are able to pin and are pinned)
  • Add some logic within TanStack table which reconciles column ordering and column pins so that both pinning positions reflect the same column id order as in the column order state.

I thought the second approach might be more appropriate to ensure this behavior works across other potential reorder actions, and so that the aforementioned components can remain simpler and just continue to call setColumnOrder.

However I wasn't able to find the best place in TanStack Table's source code to address this, so I opted to make the change seen in this PR. I'm very open to figuring out the change in TanStack if you agree that's a better place to fix it, and especially if you have some pointers on where I might look to investigate this behavior there.

An example, with this change applied:

column-pin-reordering-fix.mov

I opted to not run this reordering when an unpinned column is dragged into the pinned column area, maintaining that action as just a form of calling pin on the column.

Use getIsPinned to determine pinning position

Revert accidental storybook changes
Copy link

vercel bot commented Apr 19, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
material-react-table ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 19, 2024 9:27pm
material-react-table-storybook ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 19, 2024 9:27pm

Copy link
Owner

@KevinVandy KevinVandy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There seems to be a lot of redundant code here. I think they're has to be a simpler way to implement this. Every kb of code kinda matters here. Is a whole new reorderColumnPinning function necessary?

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

Successfully merging this pull request may close these issues.

2 participants