Skip to content

Commit 154f93e

Browse files
committed
release v2.3.0 - visibleInShowHideMenu
1 parent 8d50579 commit 154f93e

File tree

8 files changed

+100
-10
lines changed

8 files changed

+100
-10
lines changed

apps/material-react-table-docs/components/prop-tables/columnOptions.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -599,4 +599,14 @@ export const columnOptions: ColumnOption[] = [
599599
required: false,
600600
type: '',
601601
},
602+
{
603+
columnOption: 'visibleInShowHideMenu',
604+
defaultValue: 'true',
605+
description: 'Set to false if you want to hide a column from the show/hide menu.',
606+
link: '/docs/guides/column-hiding#hide-column-from-show-hide-menu',
607+
linkText: 'MRT Column Hiding Docs',
608+
source: 'MRT',
609+
required: false,
610+
type: 'boolean',
611+
},
602612
];

apps/material-react-table-docs/pages/changelog.mdx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ import Head from 'next/head';
1212

1313
### Version 2
1414

15+
#### Version 2.3.0 - 2024-01-02
16+
17+
- Added new `visibleInShowHideMenu` column option to allow for columns to be hidden from the show/hide columns menu, regardless of column visibility state.
18+
- Fixed bug where the Show All button in the show/hide columns menu did not properly skip columns with `enableHiding: false` set.
19+
- Fixed bug where creatingRow did not work with virtualization enabled.
20+
1521
#### Version 2.2.0 - 2024-01-01
1622

1723
- Added new `useMRT_Rows`, `useMRT_ColumnVirtualizer`, and `useMRT_RowVirtualizer` hooks to allow for more advanced use cases for headless mode.

apps/material-react-table-docs/pages/docs/guides/column-hiding.mdx

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import Example from '../../../examples/disable-column-hiding';
1414

1515
## Column Hiding Feature Guide
1616

17-
The column hiding feature is enabled by default and allows the user to hide data columns from either the column actions menu or the columns menu.
17+
The column hiding feature is enabled by default and allows the user to hide data columns from either the column actions menu or the show/hide columns menu.
1818

1919
### Relevant Table Options
2020

@@ -24,7 +24,9 @@ The column hiding feature is enabled by default and allows the user to hide data
2424

2525
### Relevant Column Options
2626

27-
<ColumnOptionsTable onlyOptions={new Set(['enableHiding'])} />
27+
<ColumnOptionsTable
28+
onlyOptions={new Set(['enableHiding', 'visibleInShowHideMenu'])}
29+
/>
2830

2931
### Relevant State
3032

@@ -82,7 +84,7 @@ const table = useMaterialReactTable({
8284

8385
Alternatively, you can disable hiding specific columns by setting the `enableHiding` column option to `false` per column.
8486

85-
If you want to hide certain columns by default, you can specify an column visibility in the `initialState.columnVisibility` table option. This can also be useful for making the column hiding state persistent.
87+
If you want to hide certain columns by default, you can specify column visibility in the `initialState.columnVisibility` table option.
8688

8789
<Example />
8890

@@ -104,4 +106,38 @@ const table = useMaterialReactTable({
104106

105107
See the [Display Columns Feature Guide](/docs/guides/display-columns#display-column-definition-options-prop) for a more in depth explanation of the `displayColumnsOptions` table option.
106108

109+
### Hide Column From Show Hide Menu
110+
111+
> New in v2.3.0
112+
113+
By default, all columns are visible in the column show hide menu that is opened from the columns button in the toolbar internal actions button. You can hide a column from this menu by setting the `visibleInShowHideMenu` column option to `false`.
114+
115+
```jsx
116+
const columns = [
117+
{
118+
accessorKey: 'uuid',
119+
header: 'UUID',
120+
visibleInShowHideMenu: false, //hide this column from the show hide menu, but still show the column in the table
121+
},
122+
];
123+
124+
const table = useMaterialReactTable({
125+
columns,
126+
data,
127+
displayColumnDefOptions: {
128+
'mrt-row-actions': {
129+
visibleInShowHideMenu: false, //hide the built-in row actions column from the show hide menu
130+
},
131+
},
132+
});
133+
```
134+
135+
### Custom Columns Menu
136+
137+
The `MRT_ShowHideColumnsMenu` component is one of the few MRT components that is pretty opinionated and not easily customizable. Instead of trying to customize the menu with overrides, it might be easier for you to just build your own new button and menu from scratch using the Table and Column Instance APIs.
138+
139+
Adding your own Toolbar Buttons is covered in the [Toolbar Guide](/docs/guides/toolbar-customization#customize-built-in-internal-toolbar-button-area)
140+
141+
If all you want to do is customize the buttons above the columns menu, you can import and use the `MRT_ShowHideColumnsMenuItems` component from material react table, which is a component that renders the columns in the list with the toggle switches, but then render your own buttons in the top or bottom of the menu itself.
142+
107143
View Extra Storybook **[Examples](https://www.material-react-table.dev/?path=/story/features-column-hiding-examples)**

packages/material-react-table/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"version": "2.2.0",
2+
"version": "2.3.0",
33
"license": "MIT",
44
"name": "material-react-table",
55
"description": "A fully featured Material UI V5 implementation of TanStack React Table V8, written from the ground up in TypeScript.",

packages/material-react-table/src/menus/MRT_ShowHideColumnsMenu.tsx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,13 @@ export const MRT_ShowHideColumnsMenu = <TData extends MRT_RowData>({
4040
enableHiding,
4141
localization,
4242
},
43-
toggleAllColumnsVisible,
4443
} = table;
4544
const { columnOrder, columnPinning, density } = getState();
4645

47-
const hideAllColumns = () => {
46+
const handleToggleAllColumns = (value?: boolean) => {
4847
getAllLeafColumns()
4948
.filter((col) => col.columnDef.enableHiding !== false)
50-
.forEach((col) => col.toggleVisibility(false));
49+
.forEach((col) => col.toggleVisibility(value));
5150
};
5251

5352
const allColumns = useMemo(() => {
@@ -99,7 +98,7 @@ export const MRT_ShowHideColumnsMenu = <TData extends MRT_RowData>({
9998
{enableHiding && (
10099
<Button
101100
disabled={!getIsSomeColumnsVisible()}
102-
onClick={hideAllColumns}
101+
onClick={() => handleToggleAllColumns(false)}
103102
>
104103
{localization.hideAll}
105104
</Button>
@@ -126,7 +125,7 @@ export const MRT_ShowHideColumnsMenu = <TData extends MRT_RowData>({
126125
{enableHiding && (
127126
<Button
128127
disabled={getIsAllColumnsVisible()}
129-
onClick={() => toggleAllColumnsVisible(true)}
128+
onClick={() => handleToggleAllColumns(true)}
130129
>
131130
{localization.showAll}
132131
</Button>

packages/material-react-table/src/menus/MRT_ShowHideColumnsMenuItems.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,8 @@ export const MRT_ShowHideColumnsMenuItems = <TData extends MRT_RowData>({
8989
}
9090
};
9191

92-
if (!columnDef.header) return null;
92+
if (!columnDef.header || columnDef.visibleInShowHideMenu === false)
93+
return null;
9394

9495
return (
9596
<>

packages/material-react-table/src/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -579,6 +579,7 @@ export type MRT_ColumnDef<TData extends MRT_RowData, TValue = unknown> = Omit<
579579
table: MRT_TableInstance<TData>;
580580
}) => ReactNode[];
581581
sortingFn?: MRT_SortingFn<TData>;
582+
visibleInShowHideMenu?: boolean;
582583
};
583584

584585
export type MRT_DisplayColumnDef<

packages/material-react-table/stories/features/ColumnHiding.stories.tsx

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,3 +166,40 @@ export const ColumnHidingWithHeaderGroups = () => (
166166
data={data}
167167
/>
168168
);
169+
export const ColumnHidingColumnsNotVisibleInShowHide = () => (
170+
<MaterialReactTable
171+
columns={[
172+
{
173+
accessorKey: 'firstName',
174+
header: 'First Name',
175+
visibleInShowHideMenu: false,
176+
},
177+
{
178+
accessorKey: 'lastName',
179+
header: 'Last Name',
180+
visibleInShowHideMenu: false,
181+
},
182+
{
183+
accessorKey: 'address',
184+
header: 'Address',
185+
},
186+
{
187+
accessorKey: 'state',
188+
header: 'State',
189+
},
190+
{
191+
accessorKey: 'zip',
192+
header: 'Zip',
193+
},
194+
{
195+
accessorKey: 'email',
196+
header: 'Email Address',
197+
},
198+
{
199+
accessorKey: 'phoneNumber',
200+
header: 'Phone Number',
201+
},
202+
]}
203+
data={data}
204+
/>
205+
);

0 commit comments

Comments
 (0)