From a3aacc6412875087aa92426d52e674230997c95b Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Fri, 15 Jan 2021 15:06:22 +0100 Subject: [PATCH] added method --- .../client/GeoPortalDataEntryApp.java | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/GeoPortalDataEntryApp.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/GeoPortalDataEntryApp.java index 29d5709..9d16ab8 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/GeoPortalDataEntryApp.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/GeoPortalDataEntryApp.java @@ -353,5 +353,55 @@ public class GeoPortalDataEntryApp implements EntryPoint { } }); } + + public static native String jsonToHTML(String jsonTxt)/*-{ + try + { + var jsonObj = JSON.parse(jsonTxt); + + if(jsonObj.length==undefined) + jsonObj = [jsonObj] + //console.log(jsonObj.length) + + // EXTRACT VALUE FOR HTML HEADER. + var col = []; + for (var i = 0; i < jsonObj.length; i++) { + for (var key in jsonObj[i]) { + //console.log('key json' +key) + if (col.indexOf(key) === -1) { + col.push(key); + } + } + } + + // CREATE DYNAMIC TABLE. + var table = document.createElement("table"); + try{ + table.classList.add("my-html-table"); + + }catch(e){ + console.log('invalid css add', e); + } + + // ADD JSON DATA TO THE TABLE AS ROWS. + for (var i = 0; i < col.length; i++) { + tr = table.insertRow(-1); + var firstCell = tr.insertCell(-1); + //firstCell.style.cssText="font-weight: bold; text-align: center; vertical-align: middle;"; + firstCell.innerHTML = col[i]; + for (var j = 0; j < jsonObj.length; j++) { + var tabCell = tr.insertCell(-1); + var theValue = jsonObj[j][col[i]]; + tabCell.innerHTML = theValue; + } + } + + return table; + } + catch(e){ + console.log('invalid json', e); + } + + }-*/; }