Missing info in documentation: how to extract newly ordered array to store preference / order ON THE SERVER #2169
mynona
started this conversation in
Show and tell
Replies: 1 comment
-
I 2nd this but I'm finding getting the data-id attribute of the element to be quite unclear within the store > set method. See below code: ` var testLocations = document.getElementById("test-locations");
` |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
There is definitely a very important part left out in the documentation:
Once a new order has been created on the client side you want to extract the new order because you might want to store it on the server and not only locally for a specific client.
It took me a while to figure it out and this comment guided me:
https://stackoverflow.com/questions/63569279/saving-and-resetting-order-in-sortablejs
When you initialise Sortable you must call the toArray method:
Additionally you must assign to each element (in my case those are Divs) the 'data-id' attribute:
<div class="some-class-definitions-bla-bla" data-id="12F19A45-9C45-426B-9535-19F6289A8DFB">
Html Button to trigger the JavaScript output to the console:
<button id="saveCurrOrder" class="mb-5">Print order</button>
Console output:
Sending to the server via POST:
This will generate the following request:
Important: this is just a quick and dirty example to provide an idea how this can be achieved. I am not familiar with JavaScript at all and it would be nice if experienced developers could post here improved versions.
Hope this will help others who stumble across the same problem :-)
Keywords: sortablejs server server-side value-list array
Beta Was this translation helpful? Give feedback.
All reactions