From 95cf6d5afb685486673e3af6cb3adb088ad0dfb1 Mon Sep 17 00:00:00 2001
From: Juan Fuentes <juanf@bs-mbpr28.d.ethz.ch>
Date: Tue, 3 Sep 2019 16:13:18 +0200
Subject: [PATCH] SSDM-8697 : jexcel column width now recalculates
 automatically on type or paste and gets saved/restored

---
 .../html/js/util/JExcelEditorManager.js       | 23 ++++++++++++++++---
 1 file changed, 20 insertions(+), 3 deletions(-)

diff --git a/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/util/JExcelEditorManager.js b/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/util/JExcelEditorManager.js
index 2ccaf756822..4c1ab4c4bf8 100644
--- a/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/util/JExcelEditorManager.js
+++ b/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/util/JExcelEditorManager.js
@@ -4,16 +4,28 @@ var JExcelEditorManager = new function() {
 
     this.getOnChange = function(guid, propertyCode, entity) {
         var _this = this;
-        return function() {
+        return function(el, record, x, y, value) {
             var jExcelEditor = _this.jExcelEditors[guid];
             if(jExcelEditor) {
+                // Change column width
+                var columnWidth = parseInt(jExcelEditor.getWidth(x));
+                var td = el.children[1].children[0].children[2].children[y].children[parseInt(x)+1];
+                var columnScrollWidth = td.scrollWidth;
+
+                if(columnScrollWidth > columnWidth) {
+                    jExcelEditor.setWidth(x, columnScrollWidth + 10);
+                }
+
+                // Save Editor
                 var data = jExcelEditor.getData();
                 var style = jExcelEditor.getStyle();
                 var meta = jExcelEditor.getMeta();
+                var width = jExcelEditor.getWidth();
                 var jExcelEditorValue = {
                     data : data,
                     style : style,
-                    meta : meta
+                    meta : meta,
+                    width : width
                 }
                 entity.properties[propertyCode] = "<DATA>" + window.btoa(JSON.stringify(jExcelEditorValue)) + "</DATA>";
             }
@@ -108,7 +120,7 @@ var JExcelEditorManager = new function() {
 	    var data = [];
 	    var style = null;
 	    var meta = null;
-
+        var width = null;
 	    if(entity.properties && entity.properties[propertyCode]) {
 	        var jExcelEditorValueAsStringWithTags = entity.properties[propertyCode];
 	        var jExcelEditorValue = null;
@@ -120,6 +132,7 @@ var JExcelEditorManager = new function() {
 	            data = jExcelEditorValue.data;
 	            style = jExcelEditorValue.style;
 	            meta = jExcelEditorValue.meta;
+	            width = jExcelEditorValue.width;
 	        }
 	    }
 
@@ -137,6 +150,10 @@ var JExcelEditorManager = new function() {
                     onchangemeta: null
         };
 
+        if(width) {
+            options.colWidths = width;
+        }
+
         if(mode === FormMode.VIEW) {
             options.allowInsertRow = false;
             options.allowManualInsertRow = false;
-- 
GitLab