I currently have the following code
$(document).on('click', '#educationDone', function () {
var linkText = $('#educationDone').text();
if (linkText === 'Done') {
$('#degreeTable td:nth-child(1), #degreeTable th:nth-child(1)').hide();
$(this).text('Edit and reorder entries');
$("#degreeTable tbody").sortable("disable");
} else {
$(this).text('Done');
$('#degreeTable td:nth-child(1), #degreeTable th:nth-child(1)').show();
$("#degreeTable tbody").sortable("enable");
}
});
and I get the jquery-ui error:
cannot call methods on sortable prior to initialization; attempted to call method 'enable'
When it gets to the line:
$("#degreeTable tbody").sortable("enable");
or
$("#degreeTable tbody").sortable("disable");
The code runs totally fine when I had it all on the initial load page but now I'm trying to break it into pieces so it loads only when the user clicks on a certain button to load all of the HTML and js for that section. In order for the click events to work I had to go to adding the Event Handler by using the .on. I am assuming that the error is being throw because the page is being dynamically build. How do I need to rewrite the sortable line? I'm pretty sure it's syntax because I've tried to put it in every place I can but it does not work. I'm guessing it is something like:
$(document).on('sort'),'#degreeTable', function()){}
But I don't have a clue, I'm using jquery-1.12.4.min.js and ui/1.12.1/jquery-ui.js
Thanks for the help
Here is a simple example using Sortable with a Table. If you expand your example to include more details, someone may be able to advise more.
Since you are not using a List (
<ul>), you need to define theitemsthat sortable will use. This would be the Rows (<tr>) of the table in the table body.See more: http://api.jqueryui.com/sortable/#option-items