Skip to content

Instantly share code, notes, and snippets.

@andre347
Created August 20, 2019 19:34
Show Gist options
  • Save andre347/d7f58888b9c9ec20af739819c9b3d02a to your computer and use it in GitHub Desktop.
Save andre347/d7f58888b9c9ec20af739819c9b3d02a to your computer and use it in GitHub Desktop.
Tableau getFilterValues
function initializeViz() {
const url = "https://public.tableau.com/views/RegionalSampleWorkbook/Storms";
const div = document.getElementById("container");
let options = {
// when the viz has finished loading get the workbook
onFirstInteractive: () => {
let workbook = viz
.getWorkbook()
.getActiveSheet()
.getWorksheets()
.get("Storm Map Sheet")
.getFiltersAsync();
console.log(workbook);
}
};
viz = new tableau.Viz(div, url, options);
}
document.addEventListener("DOMContentLoaded", initializeViz);
document.getElementById("btn").addEventListener("click", getFilteredValue);
function getFilteredValue() {
viz
.getWorkbook()
.getActiveSheet()
.getWorksheets()
.get("Storm Map Sheet")
.getFiltersAsync()
.then(filters => {
const value = filters[0].getAppliedValues()[0].value;
const field = filters[0].getFieldName();
console.log(`Filtered ${field} for ${value}`);
});
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>Get Filter Values Example</title>
<script src="https://public.tableau.com/javascripts/api/tableau-2.0.0.min.js"></script>
</head>
<body>
<h1>Get Filter Values Tableau Dashboard</h1>
<p>Open the console and click the button below</p>
<button id="btn">Click here</button>
<div id="container"></div>
<script src="app.js"></script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment