Skip to content

Instantly share code, notes, and snippets.

@neokoenig
Created May 3, 2015 09:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save neokoenig/cfc2352a5c885710d13c to your computer and use it in GitHub Desktop.
Save neokoenig/cfc2352a5c885710d13c to your computer and use it in GitHub Desktop.
<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>
// 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;
}
public function updatesortorder(){
if(isAjax()){
params.neworder=replace(params.neworder, "[", "all");
params.neworder=replace(params.neworder, "]", "all");
if(structKeyExists(params, "menuid") AND structKeyExists(params, "neworder")){
for (i=1;i<=listlen(params.neworder);i++) {
item=model("menuitem").updateOne(where="id=#listGetAt(params.neworder, i)#", sortorder=i);
}
renderText("#params.neworder# Sortorder updated");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment