質問

I want to make something that makes much sense, but I think its not actually included in the jQueryUI.

I have a list of items, that are both sortable and selectable.

I can sort them one at a time, and I can select multiple items.

The question is, how can I sort multiple selected items together ?

I got this code atm,

$( "#centermainlist" ).sortable({
            scroll: false,
            handle: ".dots",
            appendTo: 'body',
            helper: 'clone',        
        });

what should I add, to make it sort all selected items ?

Thanks in advance :)

All the best, Alexander

役に立ちましたか?

解決

This functionality is not included in jQueryUI, so there's nothing you can just add to make it work the way you want. You will need to write your own code or search for plugins if you want to sort multiple items like that.

I imagine the reason this isn't in jQuery is due to the high number of situational variables involved. You're probably trying to do something like select three sequential items, then drag to move them all up or down - but this isn't the only possibility. What if the items selected aren't in a row? How do you handle that?

Example:

Item 1
Item 2 - selected
Item 3
Item 4 - selected
Item 5 - selected
Item 6

How do you move these items? Do you enforce the space in between the selected items? If so, do you stop moving items when the user moves Item 2 to the first position (since you have to keep the space)? Or in that case do you collapse them? Then do you remember that there was a hole if they move back down again? Maybe you just collapse them to begin with (easiest to implement, but maybe not the desired functionality)? Or maybe you enforce sequential selection for the move - if the items are all next to each other you can move them, if there are holes you can't?

So there are a lot of things to consider here. This is easy to implement with buttons (select items, click up or down buttons to move - just loop through and apply the move to each selected item) but much more difficult with drag reordering.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top