Sortable: Set groups by class?

Created on 26 Feb 2016  路  2Comments  路  Source: SortableJS/Sortable

Thank you for this awesome plugin! I have a question, and can't find the answer in the docs.

Can I use this plugin with multiple groups, selecting them by class? They are dynamically added, so I can't have pre-set IDs.

<ul class="group">
    <li>A</li>
    <li>B</li>
    <li>C</li>
</ul>
<ul class="group">
    <li>D</li>
    <li>E</li>
    <li>F</li>
</ul>

In the code above, I'd like to be able to sort any LI within any UL with a class of .group.

Most helpful comment

You have to init Sortable for each and every of your lists. Grab your lists by class name and start sortable in for loop for every element. It's that simple. ex. using jQuery

var el = $('.group');
    $(el).each(function (i,e) {
        var sortable = Sortable.create(e, {
            animation: 150,
            handle: '.drag-handle'
        });
    })

All 2 comments

You have to init Sortable for each and every of your lists. Grab your lists by class name and start sortable in for loop for every element. It's that simple. ex. using jQuery

var el = $('.group');
    $(el).each(function (i,e) {
        var sortable = Sortable.create(e, {
            animation: 150,
            handle: '.drag-handle'
        });
    })

Has anyone been able to implement this in the source (Dragula.js) file? I noticed the dragula plugin has it implemented. You can add an array as the first param.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

garygreen picture garygreen  路  3Comments

graemegeorge picture graemegeorge  路  4Comments

irfanlone picture irfanlone  路  3Comments

chrishaigy picture chrishaigy  路  3Comments

artaommahe picture artaommahe  路  4Comments