0

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

user3261212
  • 391
  • 2
  • 15
  • when the frontend order is changed you should make a api call and change the same in server too – Joel Joseph Dec 05 '19 at 07:52
  • each item you got from server should have an `id` and when at client side, the order changes, make api call to server including sending back the server side `id` and at server update the order of that item – Idrees Khan Dec 05 '19 at 07:57

2 Answers2

2

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 items

You could also update order value of all items at once eg. after clicking apply on FE - bonus apply/revert changes feature

Antoniossss
  • 31,590
  • 6
  • 57
  • 99
0

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');
Umesh
  • 2,704
  • 19
  • 21
  • 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 – Joel Joseph Dec 05 '19 at 07:55
  • 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 – Umesh Dec 05 '19 at 07:56
  • https://stackoverflow.com/questions/326634/sorting-on-the-server-or-on-the-client – Joel Joseph Dec 05 '19 at 08:03