1

I need some help with getting some items to stay in place in a jquery UI sortable.

I know about JQuery sortable lists and fixed/locked items and it does work quite nicely, the problem is that this works fine if you're not adding items. If you add more items to the sortable you have to call .fixedsortable again and I'd like to avoid that. Here's an example of my setup:

<ul>
<li></li>
<li class="fixed"></li>
<li></li>
<li class="fixed"></li>
<li></li>
</ul>

I need the "fixed" class to remain in place when sorting.

1 Answer 1

1

You can make container element sortable so that you will not have to worry about new elements:

Demo

HTML:

<ul id="container">
    <li>1</li>
    <li class="fixed">2</li>
    <li>3</li>
    <li class="fixed">4</li>
    <li>5</li>
</ul>

JS:

 $("#container").sortable();
Sign up to request clarification or add additional context in comments.

5 Comments

my problem is that i need the class "fixed" to stay in place when reordering the other elements
but that way they still get moved when you drag around other elements
Sadly that one didn't work with dynamically added items either.
You simply need to recalculate correctIndex/correctItems arrays whenever you add a new item.
I have some progress with stackoverflow.com/questions/4299241/… . I managed to get the fixedsortable working fine, until I delete an item from the sortable. I tried doing .sortable("refresh") but that returns an error

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.