Created
August 6, 2013 09:53
-
-
Save jekamozg/6163244 to your computer and use it in GitHub Desktop.
Jquery UI sortable
This file contains hidden or 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
$('.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