0 Replies Latest reply on Nov 20, 2015 3:57 AM by Stephen Hellyar

    API link to Checkbox & Switches - Missing Something

    Stephen Hellyar

      I want to use checkboxes  and toggle switches to filter or apply parameters against my embedded dashboard using the API.


      I used "Multiple Datasource Filters with JS API" by Kovner as a "tutorial." Here is the link:  JavaScript API: Multi-data source filters I tried to modify the function to account for a single data source and a dashboard versus a worksheet. 


      I have had mixed success.  It works on single value applications. 


      It does not work when:


      • I try to apply more than value to the filter using the standard ('Filter', ['Value 1','Value 2'])
      • I try to use it with a checkbox toggle.  It will successfully "fire" the first action and apply the filter or parameter, but return the second option.
      • There are no JS errors in the console, and the dashboard refreshes without the function being applied.   This would seem to suggest the function still needs to be tweaked.

       

      What am I missing?

       

       

      Here is my function for to switch between ADD and REMOVE a filter.

       

              function filterMainViz(filterName, values) {

              var sheet = mainViz.getWorkbook().getActiveSheet();

              var updateType;

              if($('#'+values).is(":checked"))    {

                  updateType = "ADD";

            

              } else {

                  updateType = "REMOVE";

              }

                  worksheetArray = sheet.getWorksheets();

                  for (var i = 0; i < worksheetArray.length; i++) {

                      worksheetArray[i].applyFilterAsync(filterName, values, updateType);

                  }

              }

       

      This is my attempt at modifying it to switch between two parameters.   It works on the first check (switch), but not the second.

        

           function switchMainViz() {

              var sheet = mainViz.getWorkbook().getActiveSheet();

              var updateType;

              if($('#').is(":checked"))    {

                  chartPercent();

            

              } else {

                  chartAmount();

              }

            }

        

                       

      Here are the two individual parameter control functions that are referenced above.

       

        

          function chartPercent() {

       

       

          mainWorkbook = mainViz.getWorkbook();

          // Set to Detail to Percent

          mainWorkbook.changeParameterValueAsync("Amount or Percent", "Percent").then(function () {

              alertOrConsole("'Chart Type' parameter set to Percent");

          });

      }

       

       

      function chartAmount() {

       

       

          mainWorkbook = mainViz.getWorkbook();

          // Set to Detail to Amount

          mainWorkbook.changeParameterValueAsync("Amount or Percent", "Amount").then(function () {

              alertOrConsole("'Chart type' parameter set to Amount");

          });

      }