From faacef9933a0c73867fd2fd85bfd16c766a6ae03 Mon Sep 17 00:00:00 2001 From: msjonker Date: Fri, 6 Jul 2018 11:27:13 -0400 Subject: [PATCH] Adds a helper function that clones the row and sets the width of all the cells to their width in the table to maintain row width --- app/assets/javascripts/activeadmin-sortable.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/app/assets/javascripts/activeadmin-sortable.js b/app/assets/javascripts/activeadmin-sortable.js index 49c7dc9..75fa2b6 100644 --- a/app/assets/javascripts/activeadmin-sortable.js +++ b/app/assets/javascripts/activeadmin-sortable.js @@ -3,8 +3,21 @@ $('.handle').closest('tbody').activeAdminSortable(); }); + function sortHelper(e, tr) + { + var $originals = tr.children(); + var $helper = tr.clone(); + $helper.children().each(function(index) + { + // Set helper cell sizes to match the original sizes + $(this).outerWidth($originals.eq(index).outerWidth()); + }); + return $helper; + } + $.fn.activeAdminSortable = function() { this.sortable({ + helper: sortHelper, update: function(event, ui) { var elem = ui.item.find('[data-sort-url]'), url = elem.data('sort-url'),