Skip to content

Instantly share code, notes, and snippets.

@jekamozg
Created August 6, 2013 09:53
Show Gist options
  • Save jekamozg/6163244 to your computer and use it in GitHub Desktop.
Save jekamozg/6163244 to your computer and use it in GitHub Desktop.
Jquery UI sortable
$('.sort-entity').each(function () {
var e = $(this);
var url = e.data('url');
var entity = e.data('entity');
e.find('td').each(function(){
$(this).css('width', $(this).width() +'px');
});
e.sortable({
update: function (event, ui) {
var $postData = {};
e.find('tr').each(function () {
var $this = $(this);
var $currentId = $this.data('entity-id');
if ($currentId !== undefined) {
$postData[$currentId] = $this.index() + 1;
}
});
if(url !== undefined) {
$.post(url, {
entity: entity,
weights: $postData
}, function(data){
console.log(data);
ui.item.removeClass('warning', 3000);
});
}
ui.item.addClass('warning');
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment