When a user opens the page they are shown a list, which they can reorder thanks to angulars drag&drop. The problem ofcourse is that the front-end order changed but not the back-end order. What would be the best way to keep track of the order of this list? So that when the user revisits they are shown the order in which they left it
How to save order of Angular reordered list that I get from the back-end
1.3k Views Asked by user3261212 At
2
There are 2 best solutions below
3

I believe that the sorting matters only on front-end because no matter what you get from back-end, you sort it on front-end using different sort order options.
If I understand correctly, you want to 'store' the sort order within session so that when user comes back to that page, you can get the list from back-end and sort it based on 'last sort order' stored.
You can use browser session storage for this purpose, if your application doesn't have any app state.
// setting it
window.sessionStorage.setItem('sortOrder', 'sortByDate');
// getting it
const sortOrder = window.sessionStorage.getItem('sortOrder');
The best would be to add
order
property to whatever entity you are fetching from the backend, and update that property accordingly every time user rearranges itemsYou could also update order value of all items at once eg. after clicking
apply
on FE - bonus apply/revert changes feature