Spreadsheet中关闭对话框

Spreadsheet中关闭对话框

本文介绍了自动关闭模式对话框 - 服务器代码完成后,在Google Spreadsheet中关闭对话框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Google表单,它运行一些Apps Script服务器代码连接到SQL服务器。我想在数据刷新时在模态对话框中显示消息loading ...。我可以让模式弹出,但是我想在代码完成后自动关闭对话框。



我设置的一个例子是:

   / code>触发服务器端 .gs 函数运行 
  • .gs中的服务器函数



  • 服务器代码将返回值发送回对话框
  • >
  • withSuccessHandler()在对话框中检测到服务器的返回结果
  • withSuccessHandler()运行并使用 google关闭对话框.script.host.close();



  • 您需要一个 < script> 标记在您的模式中d ialog。

     < script> 
    window.onload = function(){
    //console.log('window.onload ran!');

    google.script.run
    .withSuccessHandler(closeDialog)
    .theFunctionNameToUpdateDatabase()
    };

    window.closeDialog = function(){
    google.script.host.close();
    };
    < / script>

    现在您正在使用:

      HtmlService.createHtmlOutput(HTML在这里)

    您可以创建HTML代替文件:

      HtmlService.createHtmlOutputFromFile(filename)


    I have a Google Sheet that runs some Apps Script server code to connect to an SQL server. I want to show the message "loading..." in the modal dialog while data is being refreshed. I can get the modal to pop up, but I want to auto-close the dialog as soon as the code is finished.

    An example I have set up is:

    function testpop () {
      var htmlOutput = HtmlService
        .createHtmlOutput('<p> This box will close when the data has finished loading.</p>')
        .setSandboxMode(HtmlService.SandboxMode.IFRAME)
        .setWidth(250)
        .setHeight(200);
      SpreadsheetApp.getUi().showModalDialog(htmlOutput, 'Loading...');
      sleep(1000);
    //close the dialog
    }
    

    I know this can be called on a client side but need it to be handled in the GS so it fires when the code is done.

    解决方案

    The flow of events could be:

    • User does something
    • Triggers modal dialog
    • onLoad event of modal dialog triggers client side code
    • Client side google.script.run triggers a server side .gs function to run
    • Server function in .gs script file runs.
    • database updated from server.
    • server code sends a return value back to dialog
    • "withSuccessHandler()" in dialog detects the return from the server
    • "withSuccessHandler()" runs and closes the dialog using google.script.host.close();

    You'll need a <script> tag in your modal dialog.

    <script>
      window.onload = function() {
        //console.log('window.onload ran!');
    
        google.script.run
          .withSuccessHandler(closeDialog)
          .theFunctionNameToUpdateDatabase()
      };
    
      window.closeDialog = function() {
        google.script.host.close();
      };
    </script>
    

    Right now you are using:

    HtmlService.createHtmlOutput(the HTML here)
    

    You could create the HTML from a file instead:

    HtmlService.createHtmlOutputFromFile(filename)
    

    这篇关于自动关闭模式对话框 - 服务器代码完成后,在Google Spreadsheet中关闭对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

    08-12 03:53