-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
[DataGridPro] Add column pinning #2946
Conversation
5db4295
to
a098166
Compare
db31477
to
68d632a
Compare
f6dcf2d
to
e696bfc
Compare
8ce25c8
to
d10936e
Compare
This pull request has conflicts, please resolve those before we can evaluate the pull request. |
If you switch If you pin a column both left and right, it pin it left and pin another random one right (the last one I suppose): https://codesandbox.io/s/datagridpro-v5-quick-start-forked-e6toc If you change the position of the pinned column it pins another-one and crashes: https://codesandbox.io/s/datagridpro-v5-quick-start-forked-f9m8z Otherwise, I tried playing with the pinned columns (hide them / change their position / ...) and it behave fine. |
The column pinning, different from the tree data, is opt-out. This prop is meant to allow users to completely disable the column pinning and have the grid as it was before this feature. I didn't invest time into making it to react to changes, it was created to be set initially and never changed.
Fixed.
It was crashing when hovering a row, but this was because your CodeSandbox was using old code. Here's the updated one: https://codesandbox.io/s/datagridpro-v5-quick-start-forked-f9m8z?file=/src/App.tsx I didn't fix the behavior of |
It's good for me |
packages/grid/_modules_/grid/hooks/features/columnPinning/useGridColumnPinning.tsx
Outdated
Show resolved
Hide resolved
Because of #3264 changed the argument passed to the |
Closes #193
Preview: https://deploy-preview-2946--material-ui-x.netlify.app/components/data-grid/columns/#column-pinning
Preview: https://deploy-preview-2946--material-ui-x.netlify.app/components/data-grid/demo/
How it was implemented
The virtualization is composed of 3 components: the viewport, the content and the render zone, where the rows are actually rendered. The render zone is also the part which is moved horizontally and vertically when the user scroll a certain amount. To render a determined set of rows and columns, a
RenderContext
object is given togetRows
with the indexes to render. The idea behind the column pinning is to make the render zone to never render a pinned column, while the pinned columns are rendered outside of it withposition: sticky
. To achieve that, I changed the main render context to begin rendering after the last left pinned column and to end rendering before the first right pinned column. Between the render zone, two render contexts are created to render only the pinned columns. One problem of this approach is that for each visible row, there're can be 3.MuiDataGrid-row
elements, so the hover styles doesn't work properly. To fix that, I'm manually adding the.Mui-hovered
class to the sibling row elements to make them appear as part of one single row.Props added
pinnedColumns
: controls which columns are pinned. It's an object of type:{ left?: string[]; right?: string[] }
.onPinnedColumnsChange
: fired whenever a column is pinned or unpinned. It receives an object containing the new pinned columns.disableColumnPinning
: allows to opt-out from the column pinning feature. It removes the buttons from the column menutrue
initialState.pinnedColumns
: allows to initialize the grid with some pinned columns. This prop should be used to avoid having to add anotheronPinnedColumnsChange
Future work