Skip to main content

Hi All,

 

I'm new to JS API with only a small JS experience.

What I'm trying to do is to retrieve the values of a Filter in Tableau 2018.1 via JS API and load them in to a JS array variable [ ].

My requirement is to then show these values into an HTML drop down list.

 

I checked couple of example of the function getFiltersAsync() but can't seem to make it work.

One example is this one: Tableau Get & Set Filter Example

 

However I only need the values from one Filter and I know its name.

 

Thanks for your help in pointing me to the right direction.

Regards

1 answer
  1. Oct 5, 2018, 5:19 AM

    Since I found the answer myself I'm going to share it with you:

     

    //SheetName is the name of worksheet the filter is on

    function FilterValues(SheetName)

    {

    var AccessControlFilter = [];

    //FilterCarPark is the name of the HTML combo box I want to be populated with filter values

    var box = document.getElementById("FilterCarpark");

     

    //This is where the magic happens

    viz.getWorkbook().getActiveSheet().getWorksheets().get(SheetName).getFiltersAsync()

    .then(

    function (filters) {

    // 0 represents the position of the filter on the worksheet. The filter is the first one, hence number 0

    AccessControlFilter = filters[0].getAppliedValues();

     

    //This loop goes through every value of the filter and populates them into the box variable

    for(j=0; j < AccessControlFilter.length; j++){

    var opt2 = document.createElement('option');

    opt2.innerHTML = AccessControlFilter[j].formattedValue;

    opt2.value = AccessControlFilter[j].value;

    box.appendChild(opt2);

    };

    });

    }

     

    I call the FilterValues function when the viz first starts and that's it my LOV are populated

0/9000