diff --git a/packages/ra-ui-materialui/src/list/Datagrid.tsx b/packages/ra-ui-materialui/src/list/Datagrid.tsx index 553e9b61f91..37fc93babc2 100644 --- a/packages/ra-ui-materialui/src/list/Datagrid.tsx +++ b/packages/ra-ui-materialui/src/list/Datagrid.tsx @@ -101,13 +101,15 @@ const Datagrid: FC = props => { event.stopPropagation(); const newField = event.currentTarget.dataset.field; const newOrder = - currentSort.field === newField && - event.currentTarget.dataset.order === 'ASC' - ? 'DESC' - : 'ASC'; + currentSort.field === newField + ? currentSort.order === 'ASC' + ? 'DESC' + : 'ASC' + : event.currentTarget.dataset.order; + setSort(newField, newOrder); }, - [currentSort.field, setSort] + [currentSort.field, currentSort.order, setSort] ); const handleSelectAll = useCallback(