1

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!

link for jsfiddle

1
  • 1
    You ar not calling the 2 last lines. You must create a function and call it each time a line is moved to re-compute attributes. Give a look at the doc, the "change" event : api.jqueryui.com/sortable/#event-change Commented Jun 6, 2013 at 13:50

2 Answers 2

2

It looks like you aren't executing the code to do the prioritization after you sort.

http://jsfiddle.net/3CWBt/

$(function(){

    $("#priority-list").sortable({
        stop: setPriority
    });
    setPriority();

    function setPriority() {
        $("#priority-list li").each( function(i){
            $(this).attr("data-priority", "pri-" + (i + 1));
        });
    }

});
Sign up to request clarification or add additional context in comments.

Comments

0
$("#priority-list").sortable({
    stop : function( event, ui ) {
         $("#priority-list li").each( function(i){
             $(this).attr("data-priority", "pri-" + (i + 1));
         });
     }
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.