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

Example: feat - grouping with single group column #915

Conversation

dangkhoa99
Copy link
Contributor

Hello @KevinVandy,

Currently, there is no single column group feature, I have made an example in the storybook.

Could you develop this into a library feature?

Reference: https://www.ag-grid.com/react-data-grid/grouping-single-group-column/

Copy link

vercel bot commented Jan 6, 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 Jan 6, 2024 1:31pm
material-react-table-storybook ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 6, 2024 1:31pm

@dangkhoa99 dangkhoa99 changed the title Feat/grouping with single group column Feat: grouping with single group column Jan 6, 2024
@dangkhoa99 dangkhoa99 changed the title Feat: grouping with single group column Example: feat - grouping with single group column Jan 6, 2024
@KevinVandy
Copy link
Owner

We can develop it, but I think we would have to add it to TanStack Table itself.

@dangkhoa99
Copy link
Contributor Author

dangkhoa99 commented Jan 6, 2024

I hope this feature will be released soon. For now, I'll use example code. When this feature is released, please tag me so I can know the information.

@dangkhoa99
Copy link
Contributor Author

Hi @KevinVandy, how can I get the total depth in the table?

@KevinVandy
Copy link
Owner

Hi @KevinVandy, how can I get the total depth in the table?

table.getExpandedDepth()

All other table instance apis listed here

https://www.material-react-table.com/docs/api/table-instance-apis

@KevinVandy
Copy link
Owner

wait, somehow I didn't even know that single column grouping was easily possible in TanStack Table. I thought you were asking me to make the feature, didn't realize you did it.

@dangkhoa99
Copy link
Contributor Author

In the example, I've tried it out, but I hope you can integrate it and make it easier to use in a table via the props of the useMaterialReactTable hook.

@KevinVandy
Copy link
Owner

I'll look into this tomorrow. Logic seems pretty good here. You can try and see what needs to be done in the MRT_TableBodyCell and MRT_TableBodyCellValue components before I do.

@dangkhoa99
Copy link
Contributor Author

Okay, I will try it.

@dangkhoa99
Copy link
Contributor Author

Hi @KevinVandy , can you review it?

@dangkhoa99
Copy link
Contributor Author

Implement showOpenedGroup prop, refer to ideas from the following link: https://www.ag-grid.com/react-data-grid/grouping-single-group-column/#showing-open-groups

@dangkhoa99
Copy link
Contributor Author

Implement addColumnToLeafNode state, refer to ideas from the following link: https://www.ag-grid.com/react-data-grid/grouping-single-group-column/#adding-values-to-leaf-nodes

@@ -357,6 +357,17 @@ export const tableOptions: TableOption[] = [
source: 'MRT',
type: 'boolean',
},
{
tableOption: 'enableGroupingSingleColumn',
Copy link
Owner

Choose a reason for hiding this comment

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

Could we instead just use the already existing groupedColumnMode option instead of adding this for the logic of whether to show a single column? Maybe not.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think we can use it.

@KevinVandy
Copy link
Owner

This is good work. I want to see if the implementation can be simplified though. Can this be done with no new state or options? Or just 1 new groupingDisplayMode option with a few variants? I'm still trying to dig through and understand your code. Trying to understand why the new state is needed

@dangkhoa99
Copy link
Contributor Author

You can split addColumnToLeafNode from state. Because I don't have much experience, I put it in the status for no special reason.

@dangkhoa99
Copy link
Contributor Author

dangkhoa99 commented Jan 6, 2024

About the showOpenedGroup option, I refer to AG-Grid (link) to implement this feature. You can edit it into a variation if you want.

@KevinVandy
Copy link
Owner

Closing in favor of #916 , but I branched that PR off of this branch, so you are getting credit for this feature

@KevinVandy KevinVandy closed this Jan 6, 2024
@dangkhoa99 dangkhoa99 mentioned this pull request Jan 7, 2024
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.

None yet

2 participants