SpreadJS Designer: open the File -> Print menu from an external button

Posted by: dannicoara87 on 16 May 2025, 3:47 am EST

    • Post Options:
    • Link

    Posted 16 May 2025, 3:47 am EST

    Hello, I’m using SpreadJS with Designer and i want to use an external button to open the Print “menu” (as if i’m opening the File menu, and selecting Print option, but in a single action).

    Can i achieve this with command manager’s execute() method, or some other built-in method?

    Thank you in advance for the answer.

  • Posted 20 May 2025, 4:54 am EST - Updated 20 May 2025, 4:59 am EST

    Hi,

    Apologies for the delay caused over the weekend.

    It is possible to open the Print Menu in a single action by using an external button. Please refer to the below code snippet that illustrates the same:

    document.getElementById("printBtn").addEventListener("click", (e) => {
      let canShowMenu = false;
      if(!designer.getData("FileMenu_show")) canShowMenu = true;
      if(canShowMenu) {
        const fileMenuSettings = designer.getData("fileMenuSetting");
        if(!fileMenuSettings || !fileMenuSettings.activeCategory_main || fileMenuSettings.activeCategory_main !== "Print") {
          designer.setData("fileMenuSetting", {...fileMenuSettings, "activeCategory_main": "Print"});
        }
      }
      designer.setData("FileMenu_show", canShowMenu);
    });

    You can further refer to the attached code sample that uses the above code snippet and opens the Print Menu using an external button (see below).

    Please note that the command manager is specific to SpreadJS and is not meant to alter the designer-specific operations. Therefore, the command manager’s execute method will not trigger the Print Menu open action.

    Please feel free to reach out if you encounter any further issues or require additional guidance.

    Sample: https://jscodemine.mescius.io/share/7wPiO0lM5U23fouQlOiZtA/?defaultOpen={"OpenedFileName"%3A["%2Findex.html"%2C"%2Fapp.js"]%2C"ActiveFile"%3A"%2Fapp.js"}

    Gif:

    Regards,

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels