I have a google sheet where I have scripted a custom sidebar.
Within the sidebar, I want to display the value of column I within the active row.
I've managed to work out the script to store the variable 'I' when the sidebar is opened:
var hotelName = ""
function openSidebar() {
var html = HtmlService.createHtmlOutputFromFile('index');
SpreadsheetApp.getUi().showSidebar(html);
var ss=SpreadsheetApp.getActiveSpreadsheet();
var s=ss.getSheetByName("Contract Registry Document");
var row=s.getActiveCell().getRow();
var column=9;
hotelName = s.getRange(row, column).getValue();
Logger.log(hotelName);
}
However I now need this to appear in an empty DIV element in my sidebar. How do I export this variable?
UPDATE:
That works great. I've now added as well a button to the sidebar to refresh and what I want that to do is to update the script so that if the user has changed rows, the new hotel name will show. At the moment I've added this HTML:
<div id="footer">
<div><?= hotel ?></div>
<p><i class="fa fa-refresh" aria-hidden="true" id="testing"></i></p>
</div>
And this JQuery to the index file:
$("#testing").on('click', function buttonClick() {
google.script.run.buttonClick();
});
And for the function I just copied the original function:
function buttonClick() {
var ss=SpreadsheetApp.getActiveSpreadsheet();
var s=ss.getSheetByName("Contract Registry Document");
var row=s.getActiveCell().getRow();
var column=9;
var hotelName = s.getRange(row, column).getValue();
// get the html template after retrieving the values
var html_template = HtmlService.createTemplateFromFile('index');
// set the value for the index.html `hotel` placeholder/scriptlet
html_template.hotel = hotelName;
// evaluate the template
var sidebar_html = html_template.evaluate();
SpreadsheetApp.getUi().showSidebar(sidebar_html);
Logger.log(hotelName);
}
However, really I want the value of the cell to update asynchronously so that the sidebar doesn't re-load, just the hotel name...
Would this be possible??