2 Replies Latest reply on Dec 12, 2016 2:22 AM by Swati Chhabra

    How can I dynamically set filters on my sheets when data is uploaded

    Jerry Daru

      I am trying to set my visualizations up so that when users save things to the database the data source will refresh and the sheet filters will be set to show the new data.

       

      I have this issue...

      My published workbook is three dashboards each comprised of two sheets. I don't publish the component sheets because I am showing tabs and I don't want the individual pieces visible. The sheets on the dashboard that have filters are named exactly like the dashboard sheet with the addition of the word "sheet", and those filters are set up to effect all visualizations on the dashboard they are on.

       

      I am having trouble setting the filters for those three dashboards. Here is what I am currently trying

      function getSheetForFilter(dashboardNames, dateTime, dataNames) {

      viz.refreshDataAsync().then(function () {

      console.log(dateTime, dataNames);

      workbook = viz.getWorkbook();

      console.log(workbook);

      for (var i = dashboardNames.length - 1; i >= 0; i--) {

      console.log("iteration " + i);

      var dataToFilter = dataNames[0];

      if (dashboardNames[i] === "") dataToFilter = dataNames;

      workbook.activateSheetAsync(dashboardNames[i])

      .then(function (newSheet) {

      console.log(newSheet);

      newSheet.getWorksheets().get(dashboardNames[i] + " Sheet").applyFilterAsync("UploadDate", dateTime, tableau.FilterUpdateType.REPLACE)

      .then(newSheet.getWorksheets().get(dashboardNames[i] + " Sheet").applyFilterAsync("dataName", dataToFilter, tableau.FilterUpdateType.REPLACE));

      });

      }

      });

      }

      basically I get my workbook and iterate through the dashboard names

      for each name I set the sheet with that name as activesheet and use getWorksheets and setFilterAsync to apply data to the filter...

       

      It's very complex, and doesn't work ->Double Sadface<-

        • 1. Re: How can I dynamically set filters on my sheets when data is uploaded

          Hey Jerry,

           

          The Community team is going through and cleaning up some older posts. Did you find a solution to this question? If not, less us know and we can try to take a look.

           

          -Diego

          • 2. Re: How can I dynamically set filters on my sheets when data is uploaded
            Swati Chhabra

            Hi Jerry,

             

            This can be achieved by defining the filter while initializing the container for the viz. Please see an example below: If you are using Name as filter on dashboard then set Name as Jerry

            function initViz() {

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

                            url = "https://<your_server>/#/site/<Site_Name>/views/<Workbook>/<tab>",

                            options = {

                                "Name": "Jerry",

                                hideTabs: true,

                                hideToolbar: true

                            };

             

            The only catch is you need to have Name as a filter on your dashboard. If you don't want to give the option to change the filter on dashboard place it outside your dashboard (if the width and height of dashboard is 800*1000 place filter as floating and put it at 900*1050 or anywhere else). This way the filter works and is not visible to the user.

             

            Regards

            Swati