Reputation: 13
So I have an unordered list that's sortable using jQuery ui. I need the data-priority attribute to be 1-6 (or highest number) on every sort or re-sort. As it stands it sets it on load and doesn't re-set it after the sort.
I made a fiddle for you. It's probably something easy but I can't figure it out. >(
$("#priority-list").sortable();
$("#priority-list li").each( function(i){
$(this).attr("data-priority", "pri-" + (i + 1));
});
Thanks!
Upvotes: 1
Views: 765
Reputation: 4656
$("#priority-list").sortable({
stop : function( event, ui ) {
$("#priority-list li").each( function(i){
$(this).attr("data-priority", "pri-" + (i + 1));
});
}
});
Upvotes: 0
Reputation: 27022
It looks like you aren't executing the code to do the prioritization after you sort.
$(function(){
$("#priority-list").sortable({
stop: setPriority
});
setPriority();
function setPriority() {
$("#priority-list li").each( function(i){
$(this).attr("data-priority", "pri-" + (i + 1));
});
}
});
Upvotes: 2