lch
lch

Reputation: 4931

jquery ui sortable list send updated order of of elements with ajax

I need order of all the elements like item1=1&item2=2&item3=3 as soon as an element is sorted. here is the js fiddle for that code. could not paste as link due to indentation error.

Fiddle: jsfiddle.net/8s8t99r7/2/

Upvotes: 0

Views: 130

Answers (1)

Tushar
Tushar

Reputation: 87203

var order = [],
    counter = 1;

$('.sortable').sortable({
    connectWith: ".connectedSortable",
    cursor: "move",
    update: function(event, ui) {
        order = [];
        counter = 1;
        $('.sortable div').each(function() {
            order.push($(this).attr('id') + "=" + counter++);
        });
        alert(order.join('&'));
    }
}).disableSelection();

Demo: https://jsfiddle.net/tusharj/8s8t99r7/4/

Upvotes: 1

Related Questions