Html webapp refreshes after second click!

23 views
Skip to first unread message

PROGETTAZIONE STUDIO GB

unread,
May 18, 2021, 6:30:40 AM5/18/21
to Google Apps Script Community
Hy everyone!
I built an handy and beatiful html table. Here as usual you have the url workable esample: https://docs.google.com/spreadsheets/d/1DIVs4gmI4ea2pRR0zI6xE1ndxMIqjnNXNrxRpn0ChZg/edit?usp=sharing
You can copy it.
The problem here is very strange: when I open the page and the "change" event reload the table you can see that the data retrieved are from last but one.
I suspect the problem is in this frontend function but I can't figure out where:
function generateTable1(dataArray) {
var tbody=document.getElementById ("table-body");
tbody.innerHTML="";
dataArray.forEach(function (r) {
var row= document.createElement("tr");
var col1= document.createElement("td");
col1.textContent=r[0];
var col2= document.createElement("td");
var a = document.createElement("a");
a.setAttribute('href', `${r[1]}`); // replace "link.html" with your own link
a.target="_blank";
a.innerHTML = "CLICK";
col2.appendChild(a);
row.appendChild(col1);
row.appendChild(col2);
tbody.appendChild(row);
});
console.log ("FLAG1");
}
document.getElementById("itemBando").addEventListener("change", function (e) {

google.script.run.withSuccessHandler(generateTable1).getTableDataDaQuery(); })

Can you help me?
Thanks in advance
Mauro 

Alex

unread,
May 19, 2021, 1:21:00 AM5/19/21
to Google Apps Script Community
Hi!


Before I fixed

function getTableDataDaQuery() {
  // FUNZIONE CHE RESITUTISCE I DATI DALLA QUERY

  const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(
    'Query-restituzione'
  );

  const data = [];

  if (sheet.getLastRow() > 1) data.push(...sheet.getDataRange().getValues());

  return data;
}

But the issue wasn't out.

Then I changed 

function dataDropDown1() {
  var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(
    'Copia di stati'
  );

  var dataStati = sheet
    .getRange(2, 8, sheet.getLastRow() - 1, 1)
    .getValues()
    .filter((row) => row[0] !== '');

  return dataStati;
}

And finally I ended up with your unclosed tags in the markup. It worked. Please get the formatted code from my Sheet.

I highly recommend formatting any of your code.

PROGETTAZIONE STUDIO GB

unread,
May 19, 2021, 1:33:19 AM5/19/21
to google-apps-sc...@googlegroups.com
It works!
Thank a lot Alex
Best Regards
Mauro

STUDIO GB DI ING. MAURO BASSOTTI

Via Grandi,18 - 00045 - Genzano di Roma - Roma - Italy

P. IVA 10990921008  - C. FISC.: BSSMRA65A14H501X

Codice destinatario: M5UXCR1


Cell: 0039 371 1895109 - Fisso: 0039 06 9364553 (soltanto lun e merc 9/13)





--
You received this message because you are subscribed to a topic in the Google Groups "Google Apps Script Community" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-apps-script-community/S-_yBpJEcpQ/unsubscribe.
To unsubscribe from this group and all its topics, send an email to google-apps-script-c...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/b6c57ad6-2bea-460d-977d-7dbcb04c2cf2n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages