Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

170
Views
SortableJS keep non draggable items fixed

I have a list created using SortableJS and has a few items which cannot be dragged and dropped. Here is an example of how it looks:

<ul id="user_selections">
    <li class="no_drag">Fixed</li>
    <li>Item 1</li>
    <li class="no_drag">Fixed</li>
    <li>Item 2</li>
    <li class="no_drag">Fixed</li>
    <li>Item 3</li>
    <li class="no_drag">Fixed</li>
</ul>

Class no_drag are the items that are fixed.

Now when I move Items 3 above Item 1 the structure should be like this:

<ul id="user_selections">
    <li class="no_drag">Fixed</li>
    <li>Item 3</li>
    <li class="no_drag">Fixed</li>
    <li>Item 1</li>
    <li class="no_drag">Fixed</li>
    <li>Item 2</li>
    <li class="no_drag">Fixed</li>
</ul>

Can anyone please help me how to achieve this kind of behaviour.

Here is the JS code I have tried:

var el = document.getElementById('user_selections');
if (el) {
    const sortable = Sortable.create(el, {
        filter: '.no_drag',
        onMove(evt, oe) {
            return evt.related.className.indexOf('no_drag') === -1;
        },
        preventOnFilter: false,
        onEnd: function(/**Event*/evt) {
            // Some ajax call to save the new indexes
        }
    });
}
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!