(function($) {
    $(function() {
        $.ajaxSetup({
            beforeSend: function(xhr, settings) {
                function getCookie(name) {
                    var cookieValue = null;
                    if (document.cookie && document.cookie != '') {
                        var cookies = document.cookie.split(';');
                        for (var i = 0; i < cookies.length; i++) {
                            var cookie = jQuery.trim(cookies[i]);
                            // Does this cookie string begin with the name we want?
                            if (cookie.substring(0, name.length + 1) == (name + '=')) {
                                cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                                break;
                            }
                        }
                    }
                    return cookieValue;
                }
                if (!(/^http:.*/.test(settings.url) || /^https:.*/.test(settings.url))) {
                    // Only send the token to relative URLs i.e. locally.
                    xhr.setRequestHeader("X-CSRFToken", getCookie('csrftoken'));
                }
            }
        });

        $(".results table tbody").sortable({
            axis: 'y',
            items: 'tr',
            cursor: 'move',
            opacity: 0.8,
            update: function(event, ui) {
                var $rows = $(this);
                $("#save-order").on("click", function(e) {
                    self = $(this);
                    self.addClass('disabled');
                    $.ajax({
                        url: $(this).attr('post-url'),
                        method: 'POST',
                        data: $rows.sortable('serialize', {
                            attribute: 'order-key',
                            expression: (/(.+)_(.+)/),
                        })
                    }).done(function () {
                        self.removeClass('disabled'); // for safety
                        location.reload(true);
                    }).fail(function () {
                        self.removeClass('disabled');
                    });
                }).show();
            }
        });
    });

})(jQuery);

@@ -103,810 +103,8 @@
 ) %7B%0A
-                function getCookie(name) %7B%0A                    var cookieValue = null;%0A                    if (document.cookie && document.cookie != '') %7B%0A                        var cookies = document.cookie.split(';');%0A                        for (var i = 0; i %3C cookies.length; i++) %7B%0A                            var cookie = jQuery.trim(cookies%5Bi%5D);%0A                            // Does this cookie string begin with the name we want?%0A                            if (cookie.substring(0, name.length + 1) == (name + '=')) %7B%0A                                cookieValue = decodeURIComponent(cookie.substring(name.length + 1));%0A                                break;%0A                            %7D%0A                        %7D%0A                    %7D%0A                    return cookieValue;%0A                %7D%0A
     
@@ -319,16 +319,18 @@
 Token%22, 
+$.
 getCooki
@@ -440,31 +440,8 @@
 e(%7B%0A
-            axis: 'y',%0A
     
@@ -531,34 +531,590 @@
     
-update: function(event, ui
+itemSerializer: function (serializedItem, sortableContainer)%7B%0A                var order = $(serializedItem.node).attr(%22order-key%22);%0A                if (order) %7B%0A                    var expression = (/(.+)_(.+)/),%0A                        match = expression.exec(order);%0A                    if (match) %7B%0A                        return %7Bname: match%5B1%5D, value: match%5B2%5D%7D%0A                    %7D%0A                %7D%0A                return %7Bname: 'order', value: serializedItem.index + 1%7D%0A            %7D%0A        %7D).each(function() %7B%0A            this.addEventListener(%22sortupdate%22, function(evt
 ) %7B%0A
@@ -1205,16 +1205,18 @@
 nction(e
+vt
 ) %7B%0A    
@@ -1227,24 +1227,28 @@
             
+var 
 self = $(thi
@@ -1241,33 +1241,33 @@
 r self = $(this)
-;
+,
 %0A               
@@ -1275,34 +1275,52 @@
     
-self.addClass('disabled');
+    serialize = $rows.sortable('serialize'),
 %0A   
@@ -1340,16 +1340,22 @@
     
-$.ajax(%7B
+    data = %7B%7D;
 %0A   
@@ -1375,142 +1375,206 @@
     
-    url: $(this).attr('post-url'),%0A                        method: 'POST',%0A                        data: $rows.sortable('serialize', %7B
+serialize.each(function (idx, container)%7B%0A                        $.each(container.items, function (idx, item)%7B%0A                            if (!data.hasOwnProperty(item.name)) data%5Bitem.name%5D = %5B%5D;
 %0A   
@@ -1602,113 +1602,300 @@
     
+d
 at
-tribute: 'order-key',%0A                            expression: (/(.+)_(.+)/),%0A                        %7D)
+a%5Bitem.name%5D.push(item.value);%0A                        %7D);%0A                    %7D);%0A                    self.addClass('disabled');%0A                    $.ajax(%7B%0A                        url: $(this).attr('post-url'),%0A                        method: 'POST',%0A                        data: data,
 %0A   
@@ -2200,32 +2200,34 @@
 );%0A            %7D
+);
 %0A        %7D);%0A   

fix sortablelist (html5sortable).