Skip to content

Commit 9711c54

Browse files
committed
Sortable: Copy the cell structure when sorting a table row. Fixes #9185 - Sortable: Placeholder breaks table-layout: fixed.
(cherry picked from commit 09b3533)
1 parent 83e0b4c commit 9711c54

File tree

3 files changed

+34
-18
lines changed

3 files changed

+34
-18
lines changed

tests/unit/sortable/sortable.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@
4444
border-width: 0;
4545
height:19px;
4646
}
47+
#sortable-table {
48+
width: 100%;
49+
}
4750
</style>
4851
</head>
4952
<body>

tests/unit/sortable/sortable_options.js

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -359,19 +359,31 @@ test( "{ placeholder: String }", function() {
359359
});
360360

361361
test( "{ placholder: String } tr", function() {
362-
expect( 3 );
363-
364-
var element = $( "#sortable-table tbody" ).sortable({
365-
placeholder: "test",
366-
start: function( event, ui ) {
367-
ok( ui.placeholder.hasClass( "test" ), "placeholder has class" );
368-
equal( ui.placeholder.children().length, 1, "placeholder tr contains a td" );
369-
equal( ui.placeholder.children().html(), $( "<span>&#160;</span>" ).html(),
370-
"placeholder td has content for forced dimensions" );
371-
}
372-
});
373-
374-
element.find( "tr" ).eq( 0 ).simulate( "drag", {
362+
expect( 4 );
363+
364+
var originalWidths,
365+
element = $( "#sortable-table tbody" ).sortable({
366+
placeholder: "test",
367+
start: function( event, ui ) {
368+
var currentWidths = otherRow.children().map(function() {
369+
return $( this ).width();
370+
}).get();
371+
ok( ui.placeholder.hasClass( "test" ), "placeholder has class" );
372+
deepEqual( currentWidths, originalWidths, "table cells maintian size" );
373+
equal( ui.placeholder.children().length, dragRow.children().length,
374+
"placeholder has correct number of cells" );
375+
equal( ui.placeholder.children().html(), $( "<span>&#160;</span>" ).html(),
376+
"placeholder td has content for forced dimensions" );
377+
}
378+
}),
379+
rows = element.children( "tr" ),
380+
dragRow = rows.eq( 0 ),
381+
otherRow = rows.eq( 1 );
382+
383+
originalWidths = otherRow.children().map(function() {
384+
return $( this ).width();
385+
}).get();
386+
dragRow.simulate( "drag", {
375387
dy: 1
376388
});
377389
});

ui/jquery.ui.sortable.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -763,15 +763,16 @@ $.widget("ui.sortable", $.ui.mouse, {
763763
element: function() {
764764

765765
var nodeName = that.currentItem[0].nodeName.toLowerCase(),
766-
element = $( that.document[0].createElement( nodeName ) )
766+
element = $( "<" + nodeName + ">", that.document[0] )
767767
.addClass(className || that.currentItem[0].className+" ui-sortable-placeholder")
768768
.removeClass("ui-sortable-helper");
769769

770770
if ( nodeName === "tr" ) {
771-
// Use a high colspan to force the td to expand the full
772-
// width of the table (browsers are smart enough to
773-
// handle this properly)
774-
element.append( "<td colspan='99'>&#160;</td>" );
771+
that.currentItem.children().each(function() {
772+
$( "<td>&#160;</td>", that.document[0] )
773+
.attr( "colspan", $( this ).attr( "colspan" ) || 1 )
774+
.appendTo( element );
775+
});
775776
} else if ( nodeName === "img" ) {
776777
element.attr( "src", that.currentItem.attr( "src" ) );
777778
}

0 commit comments

Comments
 (0)