aazizhfc
(Ali Aziz)
December 15, 2022, 3:58pm
1
Hello,
I have a simple end-point that returns basic information about classes. It has nested items in it. I implement the code to visualize the regular columns but I am not sure how to display the column with nested data.
{
"Class": "BIO",
"Start_Date": "11/09/2022",
"End_Date": "12/09/2022",
"Methods": [
{
"Inst_Method": "CC"
},
{
"Inst_Method": "LAB"
}
]
}
let template = `< table bgcolor=โ#FFFFFF โ>
< th>Class
< th>Start_Date
< th>End_Date
< /tr>
{{#each response}}
<tr>
<td>{{Class}}</td>
<td>{{Start_Date}}</td>
<td>{{End_Date}}</td>
</tr>
{{/each}}
< /table>`;
// Set visualizer
pm.visualizer.set(template, {
// Pass the response body parsed as JSON as data
response: pm.response.json()
});
How do I display the โMethodsโ and its nested โInst_Methodโ data in one cell per row?
Any help is appreciated. Thank you!
Thank you.
Does it only return one class at a time like in your example?
If not, can you post an example with multiple classes.
If it does, then your logic is slightly wrong, as the for each will see the class, start date and end date as separate lines of data.
If it does only return one class at a time, then the following should work. (You can ignore the extra parsing that I needed to add to get Postman echo to replicate your example).
var template = `
<style type="text/css">
.tftable {font-size:14px;color:#333333;width:100%;border-width: 1px;border-color: #87ceeb;border-collapse: collapse;}
.tftable th {font-size:18px;background-color:#87ceeb;border-width: 1px;padding: 8px;border-style: solid;border-color: #87ceeb;text-align:left;}
.tftable tr {background-color:#ffffff;}
.tftable td {font-size:14px;border-width: 1px;padding: 8px;border-style: solid;border-color: #87ceeb;}
.tftable tr:hover {background-color:#e0ffff;}
</style>
<table class="tftable" border="1">
<tr>
<th>Class</th>
<th>Start Date</th>
<th>End Date</th>
<th>Methods</th>
</tr>
<tr>
<td>{{response.Class}}</td>
<td>{{response.Start_Date}}</td>
<td>{{response.End_Date}}</td>
<td>
{{#each response.Methods}}
{{Inst_Method}}
{{/each}}
</td>
</tr>
</table>
`;
let json = pm.response.json().data
console.log(json);
pm.visualizer.set(template, {
response: json
});
aazizhfc
(Ali Aziz)
December 15, 2022, 7:53pm
3
Thank you mdjones,
It returns multiple classes at a time. The following is an example of multiple classes. Some of them have only one instructional method, other classes have multiple ones. I have seen one with 5 instructional methods.
[
{
"Class": "BIO",
"Start_Date": "11/09/2022",
"End_Date": "12/09/2022",
"Methods": [
{
"Inst_Method": "CC"
},
{
"Inst_Method": "LAB"
}
]
},
{
"Class": "ANTH",
"Start_Date": "03/02/2022",
"End_Date": "06/04/2022",
"Methods": [
{
"Inst_Method": "CC"
},
{
"Inst_Method": "OL"
}
]
},
{
"Class": "MATH",
"Start_Date": "04/03/2022",
"End_Date": "06/05/2022",
"Methods": [
{
"Inst_Method": "LAB"
}
]
},
{
"Class": "CIS",
"Start_Date": "10/09/2022",
"End_Date": "12/09/2022",
"Methods": [
{
"Inst_Method": "HYBRD"
}
]
}
]
This seems to work.
var template = `
<style type="text/css">
.tftable {font-size:14px;color:#333333;width:100%;border-width: 1px;border-color: #87ceeb;border-collapse: collapse;}
.tftable th {font-size:18px;background-color:#87ceeb;border-width: 1px;padding: 8px;border-style: solid;border-color: #87ceeb;text-align:left;}
.tftable tr {background-color:#ffffff;}
.tftable td {font-size:14px;border-width: 1px;padding: 8px;border-style: solid;border-color: #87ceeb;}
.tftable tr:hover {background-color:#e0ffff;}
</style>
<table class="tftable" border="1">
<tr>
<th>Class</th>
<th>Start Date</th>
<th>End Date</th>
<th>Methods</th>
</tr>
{{#each response}}
<tr>
<td>{{Class}}</td>
<td>{{Start_Date}}</td>
<td>{{End_Date}}</td>
<td>
{{#each Methods}}
{{Inst_Method}}
{{/each}}
</td>
</tr>
{{/each}}
</table>
`;
let json = pm.response.json().data
console.log(json);
pm.visualizer.set(template, {
response: json
});
1 Like
aazizhfc
(Ali Aziz)
December 16, 2022, 12:20pm
5
Thank you. It is working now.
I appreciate it!
Best,
Ali
aazizhfc
(Ali Aziz)
December 16, 2022, 2:33pm
6
One last thing, is it possible to freeze the header row in the โVisualizeโ tab while scrolling up and down? When scrolling it is difficult to keep track of what every column represents.
Try the following in the CSS.
<style type="text/css">
.tftable {font-size:14px;color:#333333;width:100%;border-width: 1px;border-color: #87ceeb;border-collapse: collapse;}
.tftable th {font-size:18px;background-color:#87ceeb;border-width: 1px;padding: 8px;border-style: solid;border-color: #87ceeb;text-align:left;position:sticky;top:0;}
.tftable tr {background-color:#ffffff;}
.tftable td {font-size:14px;border-width: 1px;padding: 8px;border-style: solid;border-color: #87ceeb;}
.tftable tr:hover {background-color:#e0ffff;}
</style>`Preformatted text`
This is setting a sticky table header โ th { position: sticky; top: 0; }
There can be issues with this approach, but see it if works.
1 Like
aazizhfc
(Ali Aziz)
December 16, 2022, 6:52pm
8
Thank you. This is perfect. The header becomes an overlay over the grid view.
Thanks again.
Ali
danny-dainton
(Danny Dainton)
Split this topic
August 30, 2023, 9:48am
9
@mission-cosmonaut-61
Potentially, but a) this should be its own question, not tacked onto a closed topic and b) what have you tried so far?
Can you also post more than one account in your example. (Include at least two please).
1 Like
Moved to its own topic and closing this topic out.