Reputation: 7207
My problem is that table shrinks while dragging. Row remains it's width, but table shrinks. Is there a way to keep table's original width while dragging?
Sortable functionality is being called with:
$("table[id=tblSelectedCAMERC] tbody").sortable();
Upvotes: 1
Views: 1616
Reputation: 343
In your sortable function, add a self-created placeholder where you define the column span of the table. In my case 8
:
start: function(even, ui) { ui.placeholder.html('<!--[if IE]><td colspan="8" > </td><![endif]-->')},
Now there is an empty row, without height. So add the height in your css (or any other desired layout):
.ui-sortable-helper, .sortable-placeholder {
display: table; /* This, for me, shows a border around where the row is placed */
height: 50px;
}
To understand what's happening; jquery creates an element to show in the ui. Various reasons for the ui to mess up, especially in a table. If you create your own placeholder (it could be pink too, for example) you can define how to not mess it up. In this case, adding the colspan.
Upvotes: 0
Reputation: 163
Add this in your style sheet:
.ui-sortable-helper {
display: table;
}
Upvotes: 1
Reputation: 30893
When using Sortable for a <table>
element, it is sometimes best to define exactly what will be the item
. Please review: http://api.jqueryui.com/sortable/#option-items
I would advise the following:
$(function(){
$("table[id=tblSelectedCAMERC] tbody").sortable({
sort: function(evt, ui){
debugger;
},
item: "> tr",
handle: ".iORAS_ORD"
}).disableSelection();
});
Update
As there are some extra cells, You can do this:
CSS
.shrink td:last-child {
display: none;
}
JavaScript
$(function(){
$("table[id=tblSelectedCAMERC] tbody").sortable({
sort: function(evt, ui){
debugger;
},
items: "> tr",
handle: ".iORAS_ORD",
scroll: true,
tolerance: "intersect",
placeholder: "shrink"
}).disableSelection();
});
Remember that the placeholder class is applied to the item, in this case the <tr>
. So if we need to suppress or hide some of the cells, we need to select them. This example assumes 1 extra cell. If you have more cells, I would advise adding a class to them (E.G.: hidden
) so that you can more easily select them. You could also try other CSS selectors (https://www.w3schools.com/cssref/css_selectors.asp)
Upvotes: 1