2 Replies Latest reply on Jun 25, 2018 8:04 AM by Raleigh Chen

    Filtering for non-categorical filters in the options Record

    Raleigh Chen

      I'm trying to have an embedded visualization show up with the Filters pre-applied, as opposed to using applyFiltersAsync during the OnFirstInteractive.  This works fine with normal Categorical (i.e. String) filters, but I can't seem to find anywhere for numeric or Date filters.  Is that possible?

       

      For example, this works fine.  When you load it, it immediately loads filtered down with just Virgin airlines:

       

          <script type="text/javascript">

          var viz, workbook, activeSheet;

              function initViz() {

                  var containerDiv = document.getElementById("vizContainer");

                  var url = "http://public.tableau.com/views/RegionalSampleWorkbook/Flights";

                  var options = {

                          hideTabs: true,

                          "Carrier Name": "Virgin",

                          onFirstInteractive: function () {

                               workbook = viz.getWorkbook();

                               activeSheet = workbook.getActiveSheet();

                          }

                     };

                     var viz = new tableau.Viz(containerDiv, url, options);

              }

       

      If I create a button and add the following code to it or add this code to OnFirstInteractive, it will filter based on the Average Minutes of Delay per Flight just fine, but only when I click the button on if I put it in OnFirstInteractive, it'll render the normal chart (filtered down to Virgin), and then filter out those values.

       

      workbook.getActiveSheet().applyRangeFilterAsync("AVG(Minutes of Delay per Flight)",{ min: 40 });

       

      However, if I try to alter the options object to try to have it load as filtered, it either doesn't filter at all, filters to nothing, or gives me an error.

                  var options = {

                          hideTabs: true,

                          "Carrier Name": "Virgin",

                          "AVG(Minutes of Delay per Flight)": { min: 40 },

                          onFirstInteractive: function () {

                                              workbook = viz.getWorkbook();

                                              activeSheet = workbook.getActiveSheet();

                          }

                    };

       

      Is this functionality not allowed?  Has anyone else been able to pass anything other than a String into the options object to filter the initial view of the visualization?

        • 1. Re: Filtering for non-categorical filters in the options Record
          Man Tsui

          Hi Raleigh,

           

          Here is my observation. I checked out the workbook and the sheet "Flights."

          Currently, AVG(Minutes of Delay) is set as measure in the sheet.

           

          You may want to try added AVG(Minutes of Delay) to the filter in order to make the Javascript API filter under options work.

           

          Screenshot.png

          1 of 1 people found this helpful
          • 2. Re: Filtering for non-categorical filters in the options Record
            Raleigh Chen

            That was it!  Thanks for your help!

             

            Ok, well, I thought that's what it was... but I've edited the workbook and added that Average column to the Filters shelf and pushed it to my own server environment:

             

            ... But it didn't work.... still got this error:

             

            Code:

                        var containerDiv = document.getElementById("vizContainer");

                        var url = "http://prodtabprim1w:8000/t/8/views/RegionalSampleWorkbook/Flights";

                        var options = {

                                hideTabs: true,

                                "Carrier Name": "Virgin",

                                "AVG(Minutes of Delay per Flight)": { min: 40 },

                                onFirstInteractive: function () {

                                     workbook = viz.getWorkbook();

                                     activeSheet = workbook.getActiveSheet();

                                }

                      };

                       

                        var viz = new tableau.Viz(containerDiv, url, options);