Over a million developers have joined DZone.

Fixed Width Sortable Tables Row with jQueryUI

· Web Dev Zone

Start coding today to experience the powerful engine that drives data application’s development, brought to you in partnership with Qlik.

When you use jQuery UI sortable function on a table I've noticed that it will collapse the width of the row you're dragging which can lead to a strange user experience. In this tutorial we are going to see how you can use a helper function to change the width of dragging rows back to the original width.

Have a look at the demo to see the difference.


jQuery Sortable is part of the jQuery UI library which can be found below.

jQuery Sortable

To define a table to have sortable rows all you have to do is apply the sortable method to the parent element of the row, which normal would be the table itself or ideally the table body.


<td>The Shawshank Redemption</td>

Then you can make the table body rows sortable by using the following jQuery code.

$('table tbody').sortable();

One of the options you can use on the sortable method is helper property where you can define a function to run when dragging the display. Therefore we simply need to create a function that will reset the width of the table row by simply using the function below.

$('table tbody').sortable({
    helper: fixWidthHelper

function fixWidthHelper(e, ui) {
    ui.children().each(function() {
    return ui;


Create data driven applications in Qlik’s free and easy to use coding environment, brought to you in partnership with Qlik.


Published at DZone with permission of Paul Underwood, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}