vendredi 20 novembre 2015

Switch between Javascript functions based on Checkbox or Toggle selection (Tableau API)

I want to use a checkbox or toggle checkbox to switch between two Tableau Javascript API functions.

It get mixed results. A single filter will ADD and REMOVE in a checkbox. It will not work when applying multiple values to the filter (e.g., (filterName, [Value 1, Value 2], ADD)).

It will run the first action when "connected" to a checkbox toggle switch, but it will not switch back and return the other function.

    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);
        }
    } 

Similar problem when I try to apply this approach to switch between two functions. It will run the first action (check or toggle), but it will not switch back or run the second function.

function switchMainViz() {
    var sheet = mainViz.getWorkbook().getActiveSheet();
    var updateType;
    if($('#').is(":checked"))    {
        chartPercent();

    } else {
        chartAmount();
        }
    }

The original chartPerce() is

    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");
});

}

The original chartAmount() is

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");
});

}




Aucun commentaire:

Enregistrer un commentaire