4 Replies Latest reply on Jul 17, 2019 5:56 AM by Akshar Jamgaonkar

    Save and use the filters applied

    Akshar Jamgaonkar

      Hello All,

       

      I am new to integrating and using Tableau Javascript API. I am trying to implement a behaviour where user should be able to save the filters applied on a dashboard (containing many sheets).

       

      I understand we can get the applied filters using `getAppliedValues` function but I am not sure how should i go about saving the values from `getAppliedValues` function as it seems to return a lot of data.

       

      And, how can i use the response returned by `getAppliedValues` and later use to preload the dashboard to load with filters already set.

       

      In case anyone can point me in the correct direction or share some sample code in case they have implemented something similar it would be very helpful, Thanks.

        • 1. Re: Save and use the filters applied
          Geraldine Zanolli

          Hi Akshar,

           

          It is a cool project, did you already try to use custom views on Tableau Server?

           

          You can use the response returned by getAppliedValues by using the options. You can find more information here.

           

          Thanks,

          Gigi

          • 2. Re: Save and use the filters applied
            Akshar Jamgaonkar

            Hello Geraldine Zanolli,

             

            Thanks for your reply. Actually the two links you shared above seem to be broken, they are not opening at my end.

             

            Also, I tried a approach of using rememberCustomViewAsync and showCustomViewAsync. The saving seems to be working fine, but when I use showCustomViewAsync

             

            the filters are selected but not applied.

             

            The code for your reference is below

             

            save the filter:

            tableauViz.getWorkbook().rememberCustomViewAsync('my_filter');

             

            Retrieve the filters:

            tableauViz.getWorkbook().showCustomViewAsync('my_filter');

             

            the filters seems to be selected but are not applied. Can you please provide some insights on the same.

             

            Looking forward, Thanks.

            • 3. Re: Save and use the filters applied
              Geraldine Zanolli

              Hi Akshar,

               

              I did some testing on my side.

               

              You would need to call first the function getCustomViewAsync and then showCustomViewsAsync(). Custom views are not guaranteed to be loaded when the viz becomes interactive. Using the function getCustomViewsAsync() makes sure that all the views are loaded before you call the showCustomViewsAsync method.

               

              For example:

              <body onload="initViz();">

                  <div id="viz1"></div>

                  <div id="viz2"></div>

                  <script type="text/javascript">

                      function initViz() {

                          var url1 = "https://dub01.online.tableau.com/t/geraldinessite/views/testgigi/SalesDashboard";

                          var vizDiv1 = document.getElementById('viz1');

               

               

                          var options1 = {hideTabs: true, width: "1000px", height: "1000px",onFirstInteractive: function () {

                              workbook = viz.getWorkbook();

                              workbook.getCustomViewsAsync().then(function(){

                                  workbook.showCustomViewAsync("test");

                                  });

                          }};

                         

                          viz = new tableau.Viz(vizDiv1, url1, options1);

                         

                      }

                  </script>

              </body>

               

              I hope it is helpful,

              Gigi

              • 4. Re: Save and use the filters applied
                Akshar Jamgaonkar

                Hello Geraldine Zanolli,

                 

                many thanks for your reply, this is working as expected, I will test it a bit more and get back to you in case I have further questions.