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 lateral padding in the <tbody>
and the <thead>
, the table isn't shrinked, elements of the table yes.
In the next JsFiddle in the first row doesn't work correctly, but in second row which only have one field with display:none;
it works.
If have any question ask it.
Table while dragging:
At first I thought it could be solved by looking for the number of <td>
elements with the class .hidden-td
(class that has a display: none;
) and look for the element with the class .placeholder-style
(is the class that has the <tr>
that is generated when doing the drag) and add many <td>
as there are in the <tr>
that I am moving, but not, isn't working.
I know how much fields have clase .hidden-td
with this line
var numcells = $('.hidden-td').length;
Problem
I have 9 elements in the first row and in the other I have 8. In my function start()
I only hidden one column in my placeholder so when I make the drag of the first row there's one column left without apply the class .hidden-td
and that's why there's a space at the end of the columns.
How can I fix this?
When the placeholder is created, it only takes the number of cell in the row and create an empty row with those cells.
You are adding class
hidden-td
to nth child 2, so you are hiding one cell. This is OK for rows 2 and up, but not for first row, since you have one more cell in that row. See placeholder for row 2:For first row:
What you can do is hide every cell in the placeholder and show only the number you need. This can be done with CSS, like this:
Result: https://jsfiddle.net/3g3bt80e/1/
You could try the approach in the snippet below.
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:
Updated fiddle