Skip to content

Commit de5b2b1

Browse files
authored
fix: show/hide column menu reset order button disabled when column order is not changed (#1340)
Currently the reset column order button is always enabled even if you can not reset the column order. This is now fixed by tracking whether the column order has changed in comparison to the initial column order. If it has not changed, the button is disabled.
1 parent a6b52ea commit de5b2b1

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ export const MRT_ShowHideColumnsMenu = <TData extends MRT_RowData>({
3535
getLeftLeafColumns,
3636
getRightLeafColumns,
3737
getState,
38+
initialState,
3839
options: {
3940
enableColumnOrdering,
4041
enableColumnPinning,
@@ -79,6 +80,16 @@ export const MRT_ShowHideColumnsMenu = <TData extends MRT_RowData>({
7980
(col) => col.columnDef.columnDefType === 'group',
8081
);
8182

83+
const hasColumnOrderChanged = useMemo(
84+
() =>
85+
columnOrder.length !== initialState.columnOrder.length ||
86+
!columnOrder.every(
87+
(column, index) => column === initialState.columnOrder[index],
88+
),
89+
90+
[columnOrder, initialState.columnOrder],
91+
);
92+
8293
const [hoveredColumn, setHoveredColumn] = useState<MRT_Column<TData> | null>(
8394
null,
8495
);
@@ -120,6 +131,7 @@ export const MRT_ShowHideColumnsMenu = <TData extends MRT_RowData>({
120131
getDefaultColumnOrderIds(table.options, true),
121132
)
122133
}
134+
disabled={!hasColumnOrderChanged}
123135
>
124136
{localization.resetOrder}
125137
</Button>

0 commit comments

Comments
 (0)