I have a table with different rows and fields. In one row I have two fields with display:none;
and when I make the drag of this rows, there is an effect like la
Having struggled with the sortable plugin myself for the past few days, I think the following changes need to be done:
Add the helper function to create the correct sizes on the helper (draggable object) to have the correct size.
In the start function, add the item html to the placeholder html, to have the placeholder stay identical to the original.
Code:
$("#tbodyproject").sortable({
items: "> tr",
appendTo: "parent",
helper: "clone",
placeholder: "placeholder-style",
start: function(event, ui) {
$(this).find('.placeholder-style td:nth-child(2)').addClass('hidden-td')
//copy item html to placeholder html
ui.placeholder.html(ui.item.html());
//hide the items but keep the height/width.
ui.placeholder.css('visibility', 'hidden');
},
stop: function(event, ui) {
ui.item.css('display', '')
},
//add helper function to keep draggable object the same width
helper: function(e, tr)
{
var $originals = tr.children();
var $helper = tr.clone();
$helper.children().each(function(index)
{
// Set helper cell sizes to match the original sizes
$(this).width($originals.eq(index).width());
});
return $helper;
},
update: function( event, ui ) {
let newOrder = $(this).sortable('toArray');
$.ajax({
type: "POST",
url:'/admin/projects/updateOrder',
data: {ids: newOrder}
})
.done(function( msg ) {
location.reload();
});
}
}).disableSelection();
Updated fiddle