setSort in listContext changes order if supplied with same SortPayload
See original GitHub issueWhat you were expecting:
When using the setSort
from listContext
it does not apply the correct values for repeated calls with the same object. I.e.
calling setSort({ field: 'myField', order: 'DESC' })
twice will set order
to ASC
.
Steps to reproduce:
I used the code of this page: https://marmelab.com/react-admin-demo/#/commands and added the setSort
in the handleChange
callback of TabbedDatagrid
:
const handleChange = useCallback(
(_event: React.ChangeEvent<{}>, value: any) => {
setFilters &&
setFilters(
{ ...filterValues, value: value },
displayedFilters,
false // no debounce, we want the filter to fire immediately
)
setSort({ field: 'myField', order: 'DESC' })
},
[displayedFilters, filterValues, setFilters]
)
Other information: Purpose: I want to adjust the sorting for each table when selected. Work-around was a check if the new sorting is different from the current one and only change if true.
let newSort: SortPayload =
value === myEnum.State1
? { field: 'myField', order: 'DESC' }
: { field: 'myOtherField', order: 'DESC' }
if (newSort.field != sort.field && newSort.order != sort.order) {
setSort(newSort)
}
Environment
- React-admin version: 4.5.3
- Last version that did not exhibit the issue (if applicable): n.a.
- React version: 18
- Browser: Chrome 107.0.5304.88
Issue Analytics
- State:
- Created 10 months ago
- Comments:8 (3 by maintainers)
Top Results From Across the Web
Sebastian Büchler sebastianbuechler - GitHub
Example of React Admin framework with JSON-Server. JavaScript ... setSort in listContext changes order if supplied with same SortPayload.
Read more >Using filter in a custom list in React Admin - Stack Overflow
Handle filtering, sorting and pagination on local data. * * Returns the data and callbacks expected by <ListContext>.
Read more >2D Sorting - Unity - Manual
Change the value of the Order in Layer to set the Renderer's priority among other Renderers within the same Sorting Layer.
Read more >Issues · marmelab/react-admin · GitHub
Reexport context related apis from react-admin isntead of relying on 3rd parties ... setSort in listContext changes order if supplied with same SortPayload...
Read more >Marmelab React-Admin Statistics & Issues - Codesti
setSort in listContext changes order if supplied with same SortPayload, closed, 8 ; NumberInput misinterprets zero-values (0 or 0.0) as type of string...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Nice! Thanks for sharing your code.
So I decided to implement the sophisticated approach outside of RA. Works like a charm and maybe it’s too much effort to integrate it into RA.