Created
May 3, 2015 09:26
-
-
Save neokoenig/cfc2352a5c885710d13c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<table id="menu-sortable" rel="#params.key#" class="table table-condensed"> | |
<thead> | |
<tr> | |
<th width=25></th> | |
<th>ID</th> | |
<th>Name</th> | |
</tr> | |
</thead> | |
<tbody> | |
<cfloop query="allitems"> | |
<tr> | |
<!--- Drag Handle ---> | |
<td><i class="fa fa-arrows"></i></td> | |
<!--- ID ---> | |
<td class="sortorder">#id#</td> | |
<!--- Name ---> | |
<td>#name</td> | |
</tr> | |
</cfloop> | |
</tbody> | |
</table> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Sortable menu items | |
$("#menu-sortable > tbody").sortable({ | |
items: "tr", | |
axis: 'y', | |
placeholder: ".bg-warning", | |
handle: ".fa-arrows", | |
forcePlaceholderSize: true, opacity: 0.7, revert: true, | |
tolerance: "pointer", | |
cursor: "move", | |
stop: function() { | |
$.ajax({ | |
type: "POST", | |
url: "/admin/menus/updatesortorder?format=json", | |
data: { | |
menuid: $("#menu-sortable").attr("rel"), | |
neworder: calcOrder | |
} | |
}) | |
} | |
}).disableSelection(); | |
/* Gets all td's of class sortorder and gets the values of id, returning and array */ | |
function calcOrder(){ | |
var orderarray=[]; | |
$("#menu-sortable tbody").find("tr").each(function(){ | |
var order=$(this).find(".sortorder").html(); | |
orderarray.push(order); | |
}); | |
return orderarray; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment