Changing the sort behavior for jquery sort

I have a sort, as a second example on this page:

http://jqueryui.com/demos/sortable/items.html

Sorting is a combination of goals:

  • Those that can be raised and regrouped
  • Disabled items that cannot be picked up (but are reset tasks).

The problem is how the component interprets my intent when sorting. As an example, taking the first element from the following list and dragging it to the fourth position will look like this:

ABCXX ==> BCXAX

Here X denotes disabled items.

In my application, I would like the sorting behavior to be different. When the target is captured and placed above the disabled element (X), then the list should not be moved to place the target, but instead the target and the disabled element should change positions.

Using the same example as before (drag from 1st to 4th):

ABCXX ==> XBCAX

If the return target is normal (i.e. not disabled), the behavior should be the same as before (drag from 1st to 3rd):

ABCXX ==> BCAXX

Think about it, because you want to redirect meetings on the calendar, when you select one of them and send it on an empty date, you do not want other meetings to be shuffled for one day.

+6
source share
2 answers

I compiled jsfiddle with the desired functionality.

Basically, I get attached to the sortable change function, and I check to see if the element just passed in the helper is disabled. If so, I move this item to where the helper started.

Here is jsfiddle http://jsfiddle.net/YjhzR/3/

Hope this helps!

Update:

http://jsfiddle.net/YjhzR/6/

+2
source

This will not be the answer to your question, but I think you should not force the use of a ready-made solution if it does not fit.

I think you should create your own control to save the elements and use jquery-ui draggables to implement the behavior. Your usecase differs from the example in some basic logic of behavior.

It would be useful in the future if you get more requirements.

+5
source

Source: https://habr.com/ru/post/900979/


All Articles