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.9K Product Ideas
- 1.9K Ideas Exchange
- 1.6K Connect
- 1.3K Connectors
- 306 Workbench
- 6 Cloud Amplifier
- 9 Federated
- 3K Transform
- 112 SQL DataFlows
- 649 Datasets
- 2.2K Magic ETL
- 4K Visualize
- 2.5K Charting
- 789 Beast Mode
- 78 App Studio
- 43 Variables
- 745 Automate
- 187 Apps
- 475 APIs & Domo Developer
- 67 Workflows
- 16 DomoAI
- 40 Predict
- 17 Jupyter Workspaces
- 23 R & Python Tiles
- 406 Distribute
- 117 Domo Everywhere
- 279 Scheduled Reports
- 10 Software Integrations
- 139 Manage
- 136 Governance & Security
- 8 Domo Community Gallery
- 46 Product Releases
- 12 Domo University
- 5.4K Community Forums
- 41 Getting Started
- 31 Community Member Introductions
- 113 Community Announcements
- 4.8K Archive