I have two lists with 8 list elements within each one. I would like to drag either element into either list, and get the total order of both lists together.
Currently the order is classed as two separate sortable lists:
[0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7]
However I would like it to be (obviously in the order of the elements):
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]
The parameter connectWith
doesn't seem to be working at all, and I cannot drag elements into other lists.
$(document).ready(function() {
$('#list-1, #list-2').sortable({
connectWith: '.group',
update: function(event, ui) {
var orders = new Array();
$('#console').html('<b>posts[id] = pos:</b><br>');
$('.group li').each(function(i) {
var order = $(this).index();
var id = $(this).attr('data-post-id');
orders.push(order);
});
console.log(orders)
}
});
});
I have created a jsFiddle
Your problem is with the float:left
on the li
items .. you need to add float:left
to the containers too (ie the ul
) to give them some height
Updated your jsfiddle here
fix was changing your css to
ul { list-style: none; float:left; }
To get the order try this :
$('.group li').each(function(i) {
var id = $(this).data('post-id');
orders.push(parseInt(id.substr(id.indexOf('-')+1)));
});
console.log(orders)
Note: you should use .data() to store/retrieve data on a node not the attr()
method
Working example here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With