Fetch data from a dataset using the Domo.js library and display it in DDX Brick
I am experiencing an issue with a DDX Brick implementation. I am unable to dynamically render data from a dataset into a table format within a DDX Brick.I have created a specific format using HTML & CSS, but I can't connect my Beast Modes to this JavaScript so I can show my data within this new table.
Best Answer
-
Here's an example. Note that my dataset0 is set for Example Sales Data. This would be set to your own dataset.
Javascript:
var domo = window.domo;
var datasets = window.datasets;
// get the data
domo.get(`data/v1/${datasets[0]}`).then(function(result){
var tableHTML = "<table><tr>";
// Extract headers and make them bold
var headers = Object.keys(result[0]);
headers.forEach(function(header) {
tableHTML += "<th><b>" + header + "</b></th>";
});
tableHTML += "</tr>";
// Loop through each row and populate table
result.forEach(function(row) {
tableHTML += "<tr>";
headers.forEach(function(header) {
tableHTML += "<td>" + row[header] + "</td>";
});
tableHTML += "</tr>";
});
tableHTML += "</table>";
// Link to html
document.getElementById("result").innerHTML = tableHTML;
});HTML:
<!DOCTYPE html>
<html lang="en">
<body>
<header>
<h1>Full Dataset Test</h1>
</header>
<main>
<div id="result"></div>
</main>
</body>
</html>CSS:
table {
border-collapse: collapse;
width: 100%;
}
th, td {
border: 1px solid black;
padding: 8px;
text-align: left;
}
th {
background-color: #4CABC5;
color: white;
font-weight: bold;
}
td:nth-child(3) {
border-left: 3px solid black;
border-right: 3px solid black;
background-color: #A3D4E1;
}** Was this post helpful? Click Agree or Like below. **
** Did this solve your problem? Accept it as a solution! **0
Answers
-
Here's an example. Note that my dataset0 is set for Example Sales Data. This would be set to your own dataset.
Javascript:
var domo = window.domo;
var datasets = window.datasets;
// get the data
domo.get(`data/v1/${datasets[0]}`).then(function(result){
var tableHTML = "<table><tr>";
// Extract headers and make them bold
var headers = Object.keys(result[0]);
headers.forEach(function(header) {
tableHTML += "<th><b>" + header + "</b></th>";
});
tableHTML += "</tr>";
// Loop through each row and populate table
result.forEach(function(row) {
tableHTML += "<tr>";
headers.forEach(function(header) {
tableHTML += "<td>" + row[header] + "</td>";
});
tableHTML += "</tr>";
});
tableHTML += "</table>";
// Link to html
document.getElementById("result").innerHTML = tableHTML;
});HTML:
<!DOCTYPE html>
<html lang="en">
<body>
<header>
<h1>Full Dataset Test</h1>
</header>
<main>
<div id="result"></div>
</main>
</body>
</html>CSS:
table {
border-collapse: collapse;
width: 100%;
}
th, td {
border: 1px solid black;
padding: 8px;
text-align: left;
}
th {
background-color: #4CABC5;
color: white;
font-weight: bold;
}
td:nth-child(3) {
border-left: 3px solid black;
border-right: 3px solid black;
background-color: #A3D4E1;
}** Was this post helpful? Click Agree or Like below. **
** Did this solve your problem? Accept it as a solution! **0 -
it's working ! Thank you
1 -
If you set all three of the datasets (dataset0, dataset1, dataset2) to your dataset, you can remove the Example Sales Data. But be careful, removing it without changing all can wipe out the brick.
** Was this post helpful? Click Agree or Like below. **
** Did this solve your problem? Accept it as a solution! **1
Categories
- All Categories
- 1.8K Product Ideas
- 1.8K Ideas Exchange
- 1.6K Connect
- 1.2K Connectors
- 300 Workbench
- 6 Cloud Amplifier
- 9 Federated
- 2.9K Transform
- 102 SQL DataFlows
- 626 Datasets
- 2.2K Magic ETL
- 3.9K Visualize
- 2.5K Charting
- 755 Beast Mode
- 61 App Studio
- 41 Variables
- 693 Automate
- 178 Apps
- 456 APIs & Domo Developer
- 49 Workflows
- 10 DomoAI
- 38 Predict
- 16 Jupyter Workspaces
- 22 R & Python Tiles
- 398 Distribute
- 115 Domo Everywhere
- 276 Scheduled Reports
- 7 Software Integrations
- 130 Manage
- 127 Governance & Security
- 8 Domo Community Gallery
- 38 Product Releases
- 11 Domo University
- 5.4K Community Forums
- 40 Getting Started
- 30 Community Member Introductions
- 110 Community Announcements
- 4.8K Archive