i am getting a dynamic data from the web api below is my response data
0
:
{CName: "a", Amt: 93027.51}
1
:
{ CName: "b", Amt: 32137.65}
2
:
{CName: "c", Amt: 54970.65}
3
:
{CName: "d", Amt: 30178.65}
4
:
{CName: "e",Amt: 1258}
5
:
{CName: "a",Amt: 1356}
6
:
{CName: "b",Amt: 1860}
7
:
{CName: "c",Amt: 1564}
8
:
{CName: "d", Amt: 1924}
9
:
{CName: "e",Amt: 15224}
10 : {CName: "e",Amt: 124}
here what my issue is here there is column named CName is there in that there are values that repeating multiple time like a,b,c repeated 2 times here what i want to know is there any possibility that we can distinct/ group these data including amt i mean totaling the distinct ?
below is my service code service.ts
getId(data) {
var url='http://xxxx.xxxx.x.xx/test/api/Data';
debugger;
return this.http.post(url,data).map(result => {
return result.json();
});
}
and by using the subscribe im consuming like this from service
this.serv.getId(this.table).subscribe(result=>{
this.Total=0;
if(result!=null)
this.resultData=result.Table;
for(var i=0;i<this.resultData.length;i++){
console.log(this.resultData);
this.Total=this.Total+parseFloat(this.resultData[i].amt);
}
},error=>{
console.log(error)})
}
With reference to the @Richard Matsen given approach i tried and got this below result
below is the json data im using
{CategoryName: "BEVARAGES", GrossAmt: "207.00", DiscAmt: "4.00", NetAmt: "215.00"}
1
:
{Name: "FOOD", GrossAmt: "5723.00", DiscAmt: "41.00", NetAmt: "6116.00"}
2
::
{Name: "BEVARAGES", GrossAmt: "198.00", DiscAmt: "18.00", NetAmt: "192.00"}
3
:
{Name: "FOOD", GrossAmt: "6720.00", DiscAmt: "117.00", NetAmt: "7062.00"}
4
:
here zero has been added in front of the data and when i m totaling the values displaying it the totaling of the whole is also getting wrong