From e414af2fc360498be039fb1938c5e0ac602997dd Mon Sep 17 00:00:00 2001 From: Oleksii Kriuchykhin Date: Tue, 13 Dec 2016 16:21:17 +0100 Subject: [PATCH] Fix columns ordering when deleting custom fields [SCI-783] --- app/assets/javascripts/samples/sample_datatable.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/app/assets/javascripts/samples/sample_datatable.js b/app/assets/javascripts/samples/sample_datatable.js index 362b90234..e082f29bf 100644 --- a/app/assets/javascripts/samples/sample_datatable.js +++ b/app/assets/javascripts/samples/sample_datatable.js @@ -1147,6 +1147,8 @@ function changeToEditMode() { form .on('ajax:success', function() { + // Preserve columns ordering before destroying the table + var colOrder = table.colReorder.order(); // Destroy datatable table.destroy(); @@ -1159,6 +1161,10 @@ function changeToEditMode() { // Remove column from table (=table header) & rows var th = originalHeader.find('#' + id); var index = th.index(); + var colIndex = $('#samples thead').find('#' + id).index(); + if (colIndex >= 0) { + colOrder.splice(colIndex, 1); + } th.remove(); $('#samples tbody td:nth-child(' + (index + 1) + ')').remove(); @@ -1175,6 +1181,8 @@ function changeToEditMode() { // Re-initialize datatable table = dataTableInit(); + // Restore columns ordering + table.colReorder.order(colOrder); loadColumnsNames(); // Hide modal