R1ND3R
asked on
Order jQuery UI Sortable through An Array
I am using jQuery's Sortable UI (http://jqueryui.com/demos/sortable/#option-connectWith) for part of a quiz I am creating that will ask the user to sort list items in the correct order.
I have managed to save a users selection by iterating through my list items and storing the class names for each item as a comma-delimited string.
Is there a way for me to be able to parse an array of values to jQuery Sortable plugin in order to sort my list in order as presented within the array?
I have managed to save a users selection by iterating through my list items and storing the class names for each item as a comma-delimited string.
Is there a way for me to be able to parse an array of values to jQuery Sortable plugin in order to sort my list in order as presented within the array?
Sorry I do not get what you are trying to do, please elaborate
ASKER
I basically would like to pass array of values to the jQuery Sortable plugin. The plugin is applied to the following list:
As you can see, from the code above, when a user views the page they have to sort the items in correct order. I am using the "class" attribute as values to store to a variable in a comma-delimited string format on button click.
The values a user submits to a variable could be: "b, a, d , c". I have already created this functionality by iterating through all <li> in jQuery and storing them.
All I would like to be able to do is be able to reorder the list items by passing the variable containing "b, a, d , c" to some function.
<script>
$(function() {
$( "#sortable" ).sortable();
$( "#sortable" ).disableSelection();
});
</script>
<ul id="sortable">
<li class="b">Item 2</li>
<li class="d">Item 4</li>
<li class="a">Item 1</li>
<li class="c">Item 3</li>
</ul>
As you can see, from the code above, when a user views the page they have to sort the items in correct order. I am using the "class" attribute as values to store to a variable in a comma-delimited string format on button click.
The values a user submits to a variable could be: "b, a, d , c". I have already created this functionality by iterating through all <li> in jQuery and storing them.
All I would like to be able to do is be able to reorder the list items by passing the variable containing "b, a, d , c" to some function.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks for your help mplungjan. Using your info has actually helped me with another part of my site.
I also managed to find through your StackOverflow like a related post that I found very useful: http://stackoverflow.com/questions/2858121/convert-javascript-comma-separated-string-into-an-array
I also managed to find through your StackOverflow like a related post that I found very useful: http://stackoverflow.com/questions/2858121/convert-javascript-comma-separated-string-into-an-array
ASKER
The reply didn't fully solve my issue. But the link provided me with some good info to look into.
Great - I am not sure, however how the fiddle did not help you to fully achieve your goal of having the li's sorted initially.