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
2 Answers
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');
3 Comments
Joel Joseph
this not a ideal option as some of the items may get deleted in sever and when the next time client loads data the order is a mess
Umesh
Why would sorting would be mess if the items are changed? Even if you are getting new list from back-end, the sort order will be applied to it after getting it from back-end only
Joel Joseph
idand when at client side, the order changes, make api call to server including sending back the server sideidand at server update the order of that item