-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathfilter.html
50 lines (42 loc) · 1.78 KB
/
filter.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Filter</title>
<script type="module">
// FilterUpdateType represents the different update types for applying a filter.
// TableauEventType represents the type of Tableau embedding event that can be listened for.
import { FilterUpdateType, TableauEventType } from "https://public.tableau.com/javascripts/api/tableau.embedding.3.latest.js";
// Filter the viz based on the result from the dropdown selection.
async function yearFilter(year) {
let viz = document.getElementById("tableauViz");
let sheet = viz.workbook.activeSheet;
if (year) {
await sheet.applyFilterAsync("Academic Year", [year], FilterUpdateType.Replace);
} else {
await sheet.clearFilterAsync("Academic Year");
}
}
const dropdown = document.getElementById("changeYear");
// Add event handler to update the viz when a new dropdown value is selected.
dropdown.addEventListener("change", (e) => yearFilter(e.target.value));
</script>
</head>
<body>
<div style="width:800px; height:700px;overflow:auto;">
<!-- Initialization of the Tableau visualization. -->
<tableau-viz id="tableauViz" src="https://public.tableau.com/views/RegionalSampleWorkbook/College"
hide-tabs>
<viz-filter field="Academic Year" value="" />
</tableau-viz>
</div>
<div style="padding:20px;">
<!-- Dropdown to select the year to filter by. -->
Year: <select id="changeYear">
<option value="">All</option>
<option value="2013">2013</option>
<option value="2014">2014</option>
</select>
</div>
</body>
</html>