0

I would like to populate array data in modal box, then have the user assign the category from a predefined drop down located under the Category column. My blocking issue is understanding how to move data from getRangeValues() found in .gs to the .html file.

The html code body is add for visual purposes. In my head the javascript code would generate a p tag (or another tag) for each record that is in the 2D array.

list from 2D array data

function activateModal() {
  
  let sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('test');
  let html = HtmlService.createHtmlOutputFromFile('forStack');
  html.setWidth(800).setHeight(500);
  let ui = SpreadsheetApp.getUi().showModalDialog(html, 'Assign Categories')

}

function getRangeValues() {
  
  let sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('test');
  
  let range = sheet.getRange(1, 1, sheet.getLastRow(), sheet.getLastColumn())
  let values = range.getValues();
  
// Logger.log(values);
}

function fromHTMLFileData() {
  "brings data from HTML file function."
}
<!DOCTYPE html>
<html>
  <head>
    <base target="_top">
  </head>
  <body>
  
    <table>
      <thead>
        <tr>
          <th>Item</th>
          <th>Price</th>
          <th>Quantity</th>
          <th>Category</th>
        </tr>
      </thead>
      <tbody>
        <tr>
          <td>Apples</td>
          <td>0.50</td>
          <td>10</td>
          <td></td>
        </tr>
        <tr>
          <td>Pears</td>
          <td>1.00</td>
          <td>10</td>
          <td></td>
        </tr>
          <tr>
          <td>Carrots</td>
          <td>1.50</td>
          <td>70</td>
          <td></td>
        </tr>
        <tr>
          <td>Peanuts</td>
          <td>2.50</td>
          <td>1</td>
          <td></td>
        </tr>
     </tbody>
  </table>
    
    
    <script>
    
    "How do I call the data from "test" sheet function getRangeValues()?"
    
    script.google.run<function()> sends data to the .gs function.
    
    </script>
    
  </body>
</html>


TheMaster
  • 45,448
  • 6
  • 62
  • 85
  • 2
    About `My blocking issue is understanding how to move data from getRangeValues() found in .gs to the .html file.`, are these threads useful for your situation? https://stackoverflow.com/search?q=%5Bgoogle-apps-script%5D+google.script.run – Tanaike Oct 28 '20 at 00:53
  • 1
    You can load the the data with [templated html](https://developers.google.com/apps-script/guides/html/templates) or you can load the data with [google.script.run.withSuccessHandler().getData()](https://developers.google.com/apps-script/guides/html/communication) by using window.onload or JQuery $(function(){}) to get the data and return it back through the withSuccessHandler. [Here's an example of the JQuery approach](https://stackoverflow.com/a/46959677/7215091) – Cooper Oct 28 '20 at 01:40
  • 1
    You have a misconception regarding `google.script.run` as it could be used both to send data to / get data from server side code. Please read https://developers.google.com/apps-script/guides/html and the other pages under the User Inferace sidebar menu. – Rubén Oct 28 '20 at 01:59

0 Answers0