1

I have this code running if loaded static.

HTML

<div class="control-group" id="example-2-1">
    <div class="span3">
        <ul class="sortable-list">
        </ul>
    </div>
</div>

JQUERY

// Example 2.1: Get items
$('#example-2-1 .sortable-list').sortable({
    connectWith: '#example-2-1 .sortable-list',

    receive: function(event, ui) {
        // so if > 10
        if ($(this).children().length > 1) {
            //ui.sender: will cancel the change.
            //Useful in the 'receive' callback.
            $(ui.sender).sortable('cancel');
        }
    }                   
});

But when I run it with AJAX, the sortable doesnt work anymore.

AJAX / REMOTE DATA

jQuery.ajax({
    type: "POST",
    url: "index.php/data/get_data/",
    success:function(response){                     

            $('#example-2-1').append ($(response).hide().fadeIn('1000000'));                                                    
    },

    error:function (xhr, ajaxOptions, thrownError){
        alert(thrownError);
    }
});

what did I miss?

2
  • Which sortable plugin u are using? Commented Jul 21, 2014 at 6:06
  • 3
    Try to call $( ".sortable-list" ).sortable(); after append. Commented Jul 21, 2014 at 6:09

3 Answers 3

6

Try calling .sortable after you append content to your div.

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

Comments

0

I hope you have following code under your response:

  <div class="span3">
    <ul class="sortable-list">
    </ul>
  </div>

If so ; try using following code to again refresh it.

 $( "#example-2-1 .sortable-list" ).sortable( "refresh" ); 

like below:

  jQuery.ajax({
type: "POST",
url: "index.php/data/get_data/",
success:function(response){                     

        $('#example-2-1').append ($(response).hide().fadeIn('1000000'));     
        // refresh sorting here.
        $( "#example-2-1 .sortable-list" ).sortable( "refresh" );                                                
},

error:function (xhr, ajaxOptions, thrownError){
    alert(thrownError);
}

});

Comments

0

Just after binding the dynamic sortable call below function

 $('#nestable3').nestable();

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.