SortableJS / Sortable

Reorderable drag-and-drop lists for modern browsers and touch devices. No jQuery or framework required.
https://sortablejs.github.io/Sortable/
MIT License
29.77k stars 3.7k forks source link

How to save order of multiple lists to localstorage? #2360

Open neviln opened 8 months ago

neviln commented 8 months ago

I've read the help page (https://github.com/SortableJS/Sortable?tab=readme-ov-file#store), which helped me learn how to save the order when using a single list, but didn't know how to apply it when using multiple lists. I also went through many of the previously posted issues, but am still lost. I did find one similar issue (https://github.com/SortableJS/Sortable/issues/568) but was not able to figure out where to insert the "store" portion of the code:

store: {
  get: function (sortable) {
    var order = localStorage.getItem(sortable.options.group.name);
    return order ? order.split("|") : [];
  },
  set: function (sortable) {
    var order = sortable.toArray();
    localStorage.setItem(sortable.options.group.name, order.join("|"));
  }
};

I made a sample JS Bin (https://jsbin.com/rakuzop/edit?html,js,output) and my goal is to be able to move items around between the 4 todo lists and have the order of all lists saved to localstorage. I tried to implement the solution @RubaXa suggested in issue 568, but wasn't able to get it to work. Currently, it only saves the order of 'Todo 4' list.

I'm new to JS and have been trying to get it working for weeks. Any help is greatly appreciated. Thank you