Skip to content

feat: Update to pin actions in show/hide columns menu #1423

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

Open
wants to merge 1 commit into
base: v3
Choose a base branch
from
Open
Show file tree
Hide file tree
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 @@ -522,6 +522,28 @@ export const tableOptions: TableOption[] = [
source: '',
type: 'boolean',
},
{
tableOption: 'enableColumnResetPins',
defaultValue: '',
description:
"Determines if 'Reset Pins' option is available in the Show/Hide columns menu.",
link: '/docs/guides/column-pinning#column-resize-mode',
linkText: 'MRT Column Pinning Docs',
required: false,
source: 'MRT',
type: 'boolean',
},
{
tableOption: 'enableColumnUnpinAll',
defaultValue: 'true',
description:
"Determines if 'Unpin All' option is available in the Show/Hide columns menu.",
link: '/docs/guides/column-pinning#column-resize-mode',
linkText: 'MRT Column Pinning Docs',
required: false,
source: 'MRT',
type: 'boolean',
},
{
tableOption: 'enableCellActions',
defaultValue: '',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ const Example = () => {
columns,
data,
enableColumnPinning: true,
enableColumnResetPins: true,
enableRowActions: true,
layoutMode: 'grid-no-grow', //constant column widths
renderRowActionMenuItems: () => [<MenuItem key="action">Action</MenuItem>],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ export const MRT_ShowHideColumnsMenu = <TData extends MRT_RowData>({
options: {
enableColumnOrdering,
enableColumnPinning,
enableColumnResetPins,
enableColumnUnpinAll,
enableHiding,
localization,
mrtTheme: { menuBackgroundColor },
Expand Down Expand Up @@ -136,14 +138,21 @@ export const MRT_ShowHideColumnsMenu = <TData extends MRT_RowData>({
{localization.resetOrder}
</Button>
)}
{enableColumnPinning && (
{enableColumnPinning && enableColumnUnpinAll && (
<Button
disabled={!getIsSomeColumnsPinned()}
onClick={() => table.resetColumnPinning(true)}
>
{localization.unpinAll}
</Button>
)}
{enableColumnPinning && enableColumnResetPins && (
<Button
onClick={() => table.resetColumnPinning()}
>
{localization.resetPins}
</Button>
)}
{enableHiding && (
<Button
disabled={getIsAllColumnsVisible()}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ export const useMRT_TableOptions: <TData extends MRT_RowData>(
enableColumnFilters = true,
enableColumnOrdering = false,
enableColumnPinning = false,
enableColumnResetPins = false,
enableColumnResizing = false,
enableColumnUnpinAll = true,
enableColumnVirtualization,
enableDensityToggle = true,
enableExpandAll = true,
Expand Down Expand Up @@ -192,7 +194,9 @@ export const useMRT_TableOptions: <TData extends MRT_RowData>(
enableColumnFilters,
enableColumnOrdering,
enableColumnPinning,
enableColumnResetPins,
enableColumnResizing,
enableColumnUnpinAll,
enableColumnVirtualization,
enableDensityToggle,
enableExpandAll,
Expand Down
1 change: 1 addition & 0 deletions packages/material-react-table/src/locales/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export const MRT_Localization_EN: MRT_Localization = {
pinToRight: 'Pin to right',
resetColumnSize: 'Reset column size',
resetOrder: 'Reset order',
resetPins: 'Reset pins',
rowActions: 'Row Actions',
rowNumber: '#',
rowNumbers: 'Row Numbers',
Expand Down
3 changes: 3 additions & 0 deletions packages/material-react-table/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ export interface MRT_Localization {
pinToRight: string;
resetColumnSize: string;
resetOrder: string;
resetPins: string;
rowActions: string;
rowNumber: string;
rowNumbers: string;
Expand Down Expand Up @@ -862,6 +863,8 @@ export interface MRT_TableOptions<TData extends MRT_RowData>
enableColumnDragging?: boolean;
enableColumnFilterModes?: boolean;
enableColumnOrdering?: boolean;
enableColumnResetPins?: boolean;
enableColumnUnpinAll?: boolean;
enableColumnVirtualization?: boolean;
enableDensityToggle?: boolean;
enableEditing?: ((row: MRT_Row<TData>) => boolean) | boolean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export const ColumnPinningInitial = () => (
columns={columns}
data={data}
enableColumnPinning
enableColumnResetPins
initialState={{ columnPinning: { left: ['email'], right: ['state'] } }}
/>
);
Expand Down