1

I'm using http://johnny.github.io/jquery-sortable/ not Jquery UI sortable.

My full code is here: http://jsfiddle.net/shankardevy/XwkxH/2/

jQuery('.draggable').sortable({
  onDrop: function (item, container, _super) {
    console.log($('.draggable').sortable("serialize").get());
    _super(item, container)
  }
})

My problem is that in the above code, sortable('serialize') as documented in http://johnny.github.io/jquery-sortable/ is not working for me. It gives me an array of empty objects while I expect the array to contain the <li> objects in the order sorted.

1
  • nope. if you expand the array and object in console, you will notice that I have no way to relate the object to the <li> element. The objects are not of <li>. maybe I'm missing something obvious. I need to get the ids of each of the object in that array. Commented Aug 28, 2013 at 4:42

2 Answers 2

4

@sza's answer will work well, still I managed to get it working using the plugin options:

jQuery('.draggable').sortable({
  onDrop: function (item, container, _super) {
      console.log(container.el.sortable("serialize").get());
    _super(item, container);
  },
  serialize: function (parent, children, isContainer) {
    return isContainer ? children.join() : parent.attr('id');
  }
});

The thing is the the default serialize function wasn't returning the result we expected so I created a custom one much like the one on an example above ("Connected lists with limited drop targets")

Here's the updated fiddle

Sign up to request clarification or add additional context in comments.

Comments

2

You can get all <li> by calling .children() like this

var li_list = $('.draggable').children();

1 Comment

@Reigel it is sorted. since the draggable changes the dom and children() are all items from top to bottom.

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.