-
-
Notifications
You must be signed in to change notification settings - Fork 5.3k
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 sorting a list using a <Datagrid> inside a <ReferenceManyField> #5094
Conversation
bc8cf45
to
cad17fe
Compare
We should not introduce breaking changes at this stage. I suggest you fix the bug without renaming the arguments, and open an issue for the renaming and flag it with the breaking change tag. We'll address it for 4.0. |
const newOrder = | ||
currentSort.field === newField && currentSort.order === 'ASC' | ||
? 'DESC' | ||
: 'ASC'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The default sort order can de defined on a per field basis. You must rely on the data-order
attribute.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The value of the data-order
attribute should be the same as the value of the currentSort.order
because the <Datagrid>
controls the <DatagridHeaderCell>
which has no internal logic. But I made the change because it's more understandable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this new piece of code, if the user clicks on the header of a column that isn't yet used for sorting (thus currentSort.field !== newField
), the sort order defaults to the ASC
sort order. In the previous piece of code, the sort order defaulted to event.currentTarget.dataset.order
. That's a breaking change.
You see, developers can customize the default sort order for a field using the sortByOrder
prop on a Field - and that prop is stored in the header dataset. If you don't use that value, you're breaking the sortByOrder
feature.
See https://marmelab.com/react-admin/List.html#specify-sort-order
const newOrder = | ||
currentSort.field === newField && currentSort.order === 'ASC' | ||
? 'DESC' | ||
: 'ASC'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this new piece of code, if the user clicks on the header of a column that isn't yet used for sorting (thus currentSort.field !== newField
), the sort order defaults to the ASC
sort order. In the previous piece of code, the sort order defaulted to event.currentTarget.dataset.order
. That's a breaking change.
You see, developers can customize the default sort order for a field using the sortByOrder
prop on a Field - and that prop is stored in the header dataset. If you don't use that value, you're breaking the sortByOrder
feature.
See https://marmelab.com/react-admin/List.html#specify-sort-order
… confusion (sort should be an object including field)
b3a829a
to
d635a3f
Compare
Fixes #5059
Several bugs are fixed:
ASC
andDESC
orders inside<ReferenceManyField>
and<ReferenceArrayField>
I introduced a new prop named
field
in the<DatagridHeaderCell>
which contains the same data as the prop namedsort
which is now deprecated.This renaming is motivated by the confusion introduced by two similar names (sort in
<Datagrid>
and sort in<DatagridHeaderCell>
) containing different content. The first one contains an object{ field: 'id', order: 'ASC' }
namedsort
and the second one{ sort: 'id', order: 'ASC' }
.Todo
<DatagridHeaderCell>
<Datagrid>
<Datagrid>
to query the right orderScreenshots