I am new to jquery / rails and I am having problems using .sortable (). I have extensible lines, and I can’t get the correct code to have a hidden line, that is, a child line, stick to the visible, that is, the parent line. Corresponding JS code:
(function($){
$.fn.jSortable = function(){
var element = this;
var fixHelper = function(e, ui) {
ui.children().each(function(){
$(this).width($(this).width());
});
return ui;
};
$(element).sortable({
helper: fixHelper,
axis: "y",
cursor: "move",
items: "tr.odd2",
distance: "30"
});
$(element).disableSelection();
};
})(jQuery);
The parent row has the odd2 class, and the child row is the child.
What is the correct way to lock two lines when applying .sortable ()?
I am currently using rails 3.1.1 with jquery-rails 1.0.19
EDIT:
Here is the relevant html
<table id="sortableTable">
<tr class= 'headings'>
<th><%= sortable "number" %></th>
<th><%= sortable "customer_id" %></th>
<th><%= sortable "priority" %></th>
<th><%= sortable "quantity" %></th>
<th><%= sortable "due_date" %></th>
<th></th>
</tr>
<% @jobs.each do |job| %>
<tr class= "odd2">
<td><%= job.number %></td>
<td><%= job.customer %></td>
<td><%= job.priority %></td>
<td><%= job.quantity %></td>
<td><%= job.due_date %></td>
<td><%= button 'Edit', edit_job_path(job) %></td>
</tr>
<tr class= "child">
<td><%= job.job_items %></td>
</tr>
<% end %>
</table>
<%= javascript_tag do %>
$(document).ready(function(){
$('#sortableTable tbody').jSortable();
});
<% end %>
EDIT 2: I upgraded my application to Rails 3.2.1 using jquery-rails 2.0.0
EDIT 3: Since no one has provided a solution for a table tag instead of a div, and I still need to find something that relates to the table, I have to switch to a div.