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: simplify logic for hiding/showing all columns within show/hide menu #1336

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

Conversation

fredericbahr
Copy link
Contributor

The functionality to show/hide all columns within the ShowHideColumnsMenu was implemented with a custom function which filters all columns and toggles the visibility of each column. This calls the onColumnVisibilityChange callback multiple times.

In my opinion this can be refactored to use the tables toggleAllColumnsVisible API, which results in only one call of onColumnVisibilityChange and makes the code easier to understand.

Fixes: #1277

The functionality to show/hide all columns within the ShowHideColumnsMenu was implemented with a custom function which filters all columns and toggles the visibility of each column. This calls the `onColumnVisibilityChange` callback multiple times.

In my opinion this can be refactored to use the tables `toggleAllColumnsVisible` API, which results in only one call of `onColumnVisibilityChange` and makes the code easier to understand.

Fixes: KevinVandy#1277
Copy link

vercel bot commented Dec 21, 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 Dec 21, 2024 4:55pm
material-react-table-storybook ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 21, 2024 4:55pm

@@ -45,12 +44,6 @@ export const MRT_ShowHideColumnsMenu = <TData extends MRT_RowData>({
} = table;
const { columnOrder, columnPinning, density } = getState();

const handleToggleAllColumns = (value?: boolean) => {
Copy link
Owner

Choose a reason for hiding this comment

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

I remember having good reasons for doing it this way. I think it had to do with hiding and showing grouped columns correctly. Will need to test further. At worst, may have to just use a table.setColumnVisibility(prev => /**/) call with the correct ids

Copy link
Contributor Author

Choose a reason for hiding this comment

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

When hiding all columns within the first grouping example the output is the same as on the official documentation:

image

But please test further to find some egde cases

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.

MRT_ShowHideColumnsMenu showAll / hideAll is poorly implemented
2 participants