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
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ export const MRT_ShowHideColumnsMenu = <TData extends MRT_RowData>({
}: MRT_ShowHideColumnsMenuProps<TData>) => {
const {
getAllColumns,
getAllLeafColumns,
getCenterLeafColumns,
getIsAllColumnsVisible,
getIsSomeColumnsPinned,
Expand All @@ -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

getAllLeafColumns()
.filter((col) => col.columnDef.enableHiding !== false)
.forEach((col) => col.toggleVisibility(value));
};

const allColumns = useMemo(() => {
const columns = getAllColumns();
if (
Expand Down Expand Up @@ -108,7 +101,7 @@ export const MRT_ShowHideColumnsMenu = <TData extends MRT_RowData>({
{enableHiding && (
<Button
disabled={!getIsSomeColumnsVisible()}
onClick={() => handleToggleAllColumns(false)}
onClick={() => table.toggleAllColumnsVisible(false)}
>
{localization.hideAll}
</Button>
Expand All @@ -135,7 +128,7 @@ export const MRT_ShowHideColumnsMenu = <TData extends MRT_RowData>({
{enableHiding && (
<Button
disabled={getIsAllColumnsVisible()}
onClick={() => handleToggleAllColumns(true)}
onClick={() => table.toggleAllColumnsVisible(true)}
>
{localization.showAll}
</Button>
Expand Down