-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
[data grid] Make it possible to re-use row selection propagation logic for other columns #16824
Comments
Hey @toddsmith-adsk ... If I understand your requirements correctly you would be able to achieve this with a boolean column, right? You can also use a custom cell renderer to render a checkbox instead of the default. Not so sure about the requirement to propagate the state to parents/children. @MBilalShafi would you happen to know if we already have an example showcasing this? |
@michelengelen Yes, this will be a custom "boolean" column but instead of a checkbox I will use the Visibility and VisibilityOffI icons. My main question is about managing state. Is adding custom properties to apiRef.current.state a valid solution for the state management of custom grid features? Or do we need to manage a separate state object outside of the grid? |
Ok, so I understood correctly. Well, since the rows are a part of the state you would not really need to have your own part of the state. You can just access them from the API. The interesting part now is how we could build a parent child relation for the rows. |
This use-case is a bit unusual and pretty interesting too. I don't think we have a recipe for it already. @toddsmith-adsk Could you clarify a few things about your use-case?
I'll try to come-up with a recipe based on your needs.
Technically you could mutate the Data Grid's internal state, but I think it'd be better to keep the added functionality in the user-land for a better separation of concerns and avoiding unexpected side effects. |
Here is my use case with syncing a 3D viewer to a data grid with treeData. Ideally a user would not need the Model browser in the 3D viewer if the grid supported the same functionality to control visibility and selection. Default ViewVisibility ChangedSelection ChangedUse cases:
I need to implement the same behavior in the data grid and keep the visibility and selection with the 3D viewer in sync. Changing selection or visibility in the grid will update the 3D viewer and vice versa. Or you could close the Model browser and rely on the grid to change selection and/or visibility in the 3D viewer.
I have a basic custom checkbox column which is using the Visibility and VisibilityOff icons but I'm missing the state management and state propagation logic. |
Thank you for sharing detailed information about your use case, along with the screenshots. 🙏 The selection propagation feature is tightly integrated with the row selection state and is not designed to support multiple columns as per your requirements. Given this, the recommended approach would be to manage the state and propagation logic on the user side. You are welcome to reuse the internal logic while implementing your own abstraction or visibility handling. Having said that, the use case is quite interesting. I’ll keep this issue open with a If you encounter any challenges during implementation, feel free to reach out. I’d be happy to provide guidance or share a recipe that closely aligns with your use case. |
@MBilalShafi thank you for the follow up. The approach I've taken it to effectively duplicate the GRID_CHECKBOX_SELECTION_COL_DEF and associated logic and using a lot of interface merging. It's a lot of code but seems to be working. The interesting challenge is that, assuming I have a hook similar to useGridRowSelection, where do I get that sucker loaded? Grid slots seem to be the only viable solution to load my hook (i.e. inside a custom toolbar) because it must exist inside of the grid context. |
The problem in depth
I'm syncing a 3D viewer with the MUI data grid. Each row represent an element in the 3D viewer.
I use the selection column to sync selection of items in the 3D viewer and the data grid. But I also need to add another column to sync visibility. That means I need to track a visibility state per row just like selection does. I basically need to duplicate packages\x-data-grid\src\hooks\features\rowSelection but for visibility.
I can't have two seleciton columns acting independently because they would be bound to the same state property.
Also, I'm using the treeData feature of the data grid I also need to handle propagation of the visibility state to parents and children.
Can I extend the apiRef.current.state with more properties? Is that a supported feature?
Your environment
`npx @mui/envinfo`
Search keywords: state management
Order ID: 86253
The text was updated successfully, but these errors were encountered: