1

I'm trying to create a .sortabletable using jQuery. The fixWidthHelper class preserves the table column widths. (I've removed some of the HTML)

Table HTML:

<table class = "table table-bordered" >
           hr content here...
    <tbody id = "field_wrapper">
            <tr>
              <td id = "move">...</td>
              <td id = "move">...</td>       
        </tbody>
      </table>

jQuery:

    $(function (sort) {
    sortable_tables.sorting_field_table();

});

var sortable_tables =
{
    sorting_field_table: function(sort)
    {
        $('#field_wrapper').sortable({
        placeholder: "drop",
        helper: sortable_tables.fixWidthHelper
        }).disableSelection();
    }
    fixWidthHelper: function(e, ui) {
        ui.children().each(function(sort) {
            $(this).width($(this).width()); 
        });
        return ui;
    }
});

CSS:

#move{ margin-left: 0px; padding-right:10px; cursor: move;}
.drop { 
    outline: thin dashed #CCC !important;
    background-color:#CCC;
    width:100%;
    }
2
  • $(function (sort) {...}); simply makes sort an alias for jQuery within the block. The next function(sort) expects a parameter, and the last function(sort) makes sort equivalent to the index of each ui.children(). None of these functions refer to the sort parameter. We'll need to see more code. Commented Jul 10, 2016 at 13:35
  • Thanks for quick response. I've updated my question to include the rest of the code. Commented Jul 10, 2016 at 14:06

2 Answers 2

1

The first block of your code is just defining a function on document.ready but it is not called anywhere.

Also, I don't see anything here that is actually performing any sorting.

Sign up to request clarification or add additional context in comments.

2 Comments

This is just the function. It is within the document.ready call. The sorting applies to #field-wrapper.sortable
$(function(...) is shorthand for $( document ).ready(). See learn.jquery.com/using-jquery-core/document-ready. So this answer is somewhat correct, although a function isn't actually being defined within the block.
0

I have got it it working!

jQuery:

$(function() {
  $( "#field_wrapper" ).sortable({
    placeholder: "drop"
  });
  $( "#field_wrapper" ).disableSelection();
});

1 Comment

Note: you need both the following jQuery links for it to work: <script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script> <script src="//code.jquery.com/jquery-2.2.4.min.js"></script>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.