I am developing a script of n-level of nested tables using div.
So there are 5 to 6 columns with n number of rows, every first column have to expand/collapse button, on click of which I make a call to API which gives me data respective to selected row filters.
Previously when I worked with core JavaScript and jQuery, I was using find method of document selector to identify the parent of expand/collapse button and push dynamically created HTML after that specific div only using innerHTML or append method of jQuery
I am a bit new to angular and haven't worked much. Please help me to solve this.
splitOpt is an array of objects based on which I will split report data.
this.splitOpt = [
{
id: "country",
label: "Country"
},
{
id:"os".
label:"Operating System"
},
{
id:"osv".
label:"Operating System Version"
}
]
Function to get reports
getReport() {
// apiFilters are array of object having some values to filter report data
var apiFilters: any = [{}];
for (var i = 0; i < this.sFilters.length; i++) {
if (this.sFilters[i][0].values.length > 0) {
var k;
k = this.sFilters[i][0].id
apiFilters[0][k] = this.sFilters[i][0].values;
}
}
var split = this.splitOpt[0].id;
this._apis.getReportData(split, apiFilters[0]).subscribe(response => {
if (response.status == 1200) {
this.reportData = response.data.split_by_data;
}
})
}
Function to check if there are more splits or not
checkIfHaveMoreSplits(c){
if(this.splitOpt.length > 0) {
var index = this.splitOpt.findIndex(function(v) {
return v.id == c
})
if (typeof(this.splitOpt[index+1]) != "undefined"){
return this.splitOpt[index+1];
} else {
return 0;
}
}
}
Code to draw table based on split and report data.
Let's assume there is only one object for the country in splitopt object than checkIfHaveMoreSplits() returns 0 which means I do not have to give expand button and if it is not 0 that expand button will appear there.
Onclick of expanding button I will select next element from splitopt and call API to get report having split param as a carrier and so on.
<div class="table" >
<div class="row" *ngFor="let rData of reportData; let i = index;" >
<div class="col" >
<button
class="btn btn-sm"
*ngIf="checkIfHaveMoreSplits(splitbykey) !== 0"
(click)="splitData(splitbykey)"
>+</button>
{{rData[splitbykey]}}
</div>
<div class="col">{{rData.wins}}</div>
<div class="col">{{rData.conversions}}</div>
<div class="col">{{rData.cost}}</div>
<div class="col">{{rData.bids}}</div>
<div class="col">{{rData.impressions}}</div>
<div class="col">{{rData.rev_payout}}</div>
</div>
I am managing one array which identifies how deep I can expand collapse element
Let us assume that array has three elements namely country, carrier, and os
So first table which I will draw having all the countries in the table with expand button on click of which I will send selected country and get carriers of that specific country. After getting the response I want to create custom HTML based on response and append html after selected row.
Here are the screenshots as well consist of full workflow :)
Step 2
Step 3


