Skip to content

Instantly share code, notes, and snippets.

@andre347

andre347/app.js

Created Aug 20, 2019
Embed
What would you like to do?
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
You can’t perform that action at this time.