Navigation through dashboard
This example uses the HTML Canvas "Preload dashboard data" feature to implement dashboard navigation.
This dropdown lists all dashboards in your Ubidots account.
When you select one, it opens in a new browser tab.
HTML:
<div>
<h1>Navigate through your Dashboards</h1>
<select id="dashboardsList"></select>
</div>JavaScript:
var token = ubidots.token;
const dashboardsDropdown = document.getElementById('dashboardsList');
dashboardsDropdown.addEventListener('change', handleSelectionChange);
getAllDashboards(token).then((data) =>
{
// Iterate over the data and create options
const dropdown = document.getElementById('dashboardsList');
data.results.forEach(item =>
{
const option = document.createElement('option');
option.value = item.id; // Adjust the value according to your data
option.text = item.label; // Adjust the displayed text according to your data
option.label = item.label;
dropdown.appendChild(option);
});
});
function handleSelectionChange()
{
const dashboardID = this.value; // Get the selected value
const url = `https://industrial.ubidots.com/app/dashboards/${dashboardID}`;
window.open(url, '_blank');
}
async function getAllDashboards(ubidotsToken)
{
const url = "https://industrial.api.ubidots.com/api/v2.0/dashboards/";
const method = "GET";
const req = await fetchWrapper(url, method, ubidotsToken);
return req;
}
async function fetchWrapper(url, method, token = null, payload = null)
{
const options =
{
method: method,
headers: {'Content-Type' : 'application/json'}
};
if (payload)
{
options.body = JSON.stringify(payload);
}
if (token)
{
options.headers['X-Auth-Token'] = token;
}
const response = await fetch(url, options);
const jsonData = await response.json();
return jsonData;
}
The result looks like this:

Last updated
Was this helpful?