-
-
Notifications
You must be signed in to change notification settings - Fork 3k
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
[usePinColumns] Hook to pin/freeze columns #1510
Conversation
Wow. I have to say, this is a fantastic PR. Seriously. One of the best I've ever received for React Table. Can you start working on the docs? |
Thank You @tannerlinsley for appreciating, it will bring more motivation to me. Updated docs. |
Yeah, this is looking really good. Next steps would be to:
You have me thinking now when it comes to the Example section in the docs... all of them should just link to real examples. Thoughts? |
Yes, removing code from docs will make them cleaner, anyways we are having working examples for each functionality. |
Examples for these will make more sense with |
Why is that exactly? |
My bad absolute layout, is not necessary for basic implementation of pinning of columns, implemented an example of |
Hey @tannerlinsley , whenever you get a chance, please look into above and also #1522 |
This is also looking really good. Yeah that one case where the column has parent header groups is kinda wonky. Do you have an updated example that fixes that? |
Not sure that this can fixed via example only, it seems that some changes should be required in |
After giving this one some more thought, I think what this is actually doing is creating "sticky" columns... and that can get tricky really fast. There are at least a few ways to implement sticky columns in a table and I think I need to look into this more. I would rather not have to have the user build 3 separate tables elements to do this. BRB |
Here is a little codesandbox I'm playing around with: https://codesandbox.io/s/tannerlinsleyreact-table-column-ordering-qupnl Essentially, this plugin is simply a different variation of the Sticky is interesting. You can easily do sticky pinning on your own for a single column on either end, but any time you get multiple sticky columns that you want to "stack" up, you'll need some way to detect the size of the columns and programmatically set the left or right sticky positioning, eg. Honestly, I don't think that would be too difficult. All you would need to do is introduce a layoutEffect that can measure the dom before it paints and store the rendered column sizes in state. This seems to be rabbit hole-ing though. Thoughts? |
After some more thought, I am pretty sure I'd like to see this hook basically become an alternative to the Let's get the example tuned up to not do any fancy pinning or anything like that, just have it render the table normally (the columns will be rearranged) Then we can handle the "sticky" stuff (pun intended) in another hook. |
The reason why i created it with three segments was that each segment can have multiple columns and developers can define segments's minWidth maxWidth etc. so as to have each segment their scrollbar. And creating segments dont require any extra markup, the same header+row component can serve the purpose with some extra checks.
https://codesandbox.io/s/tannerlinsleyreact-table-column-ordering-ttc3s
Agree, later on we can provide a basic example with sticky, lets not cover that with this PR. Moreover, as the html structure is fully controlled by lib's user, so if they want they can create whatever suits them better. |
@tannerlinsley , after analyzing the problem, only For example, say |
I have written a following revamp of usePinColumns, do let me know your opinion - https://gist.github.com/gargroh/ab11066424a0bdc775fe0f7eeb451a16 |
Yes I believe you are correct about the header groups. Pinning columns would mean you need to first reorder the headers, then regroup them. This is why it needs to be done in the earliest hook. Reordering the headers. Like I said, try duplicating the setup of the |
@tannerlinsley any thoughts about it ? |
It's a bit better, but I still think that it needs to hook into the column order earlier so that the core can do all of the header rebuilding automatically. I would suggest looking at the new refactor for reducers and also how the column ordering hook works, then open a new WIP PR for discussion around this. Going to close this one for now. Let me know if you want to reopen with new code. |
No description provided.