1 Reply Latest reply on Apr 10, 2018 2:10 PM by Patrick A Van Der Hyde

    JS API select worksheet on tabswitch for data export

    Ted Slinkard

      trying to add a button so the users can export data using javascript API.

       

      currently have the button calling

       

      function ExportData() {

          viz.showExportDataDialog();

      }

       

      the issue is we have multiple dashboards and when the users select a different tab(dashboard) the first worksheet is not automatically selected so it won't export anything.

       

      I'm trying to add an event listener, ignoring a few worksheets we have for layout of menu (thus the ignoreArray)  but I get the error Cannot read property activatesheetasync of undefined.  is there a better way of doing this?  just need to allow the users to export the data to csv so they can use in excel.

       

      viz.addEventListener('tabswitch', function () {

              var sheets = workbook.getActiveSheet().getWorksheets();

              var IgnoreArray = ["MenuIcon", "BlankSheet", "CloseIcon"];

       

       

              for (var i in sheets) {

                  if ($.inArray(sheets[i].getName(), IgnoreArray) < 0) {

                      console.log(sheets[i].getName());

                      viz.workbook.getActiveSheet().activateSheetAsync(sheets[i].getName());

                  }

              }

          })