ngFor Problem Ionic


#1

Hey, i am getting some data from a JSON URL, you could see it below,


Here “cname” is "Geriatrics."
I want to print cname only once and then “stitle” under it.
If one has some other cname than “Geriartrics” than it should print that cname and its stitle in it.
Demo Required result,

1). Geriartrics:
Heart Valve Disease
Test 1.

2). Something else
Test 5
Test 8

My JSON url is:
http://server10.a2zcreatorz.com/staging/projects/mobapp/Bayer/fetchsurveytest.php?urId=30

Hope this explains better :slight_smile:
Thanks


#2

I think you will need to create a new array structure locally to get the desired grouping.


#3

The problem is that i cannot predict the amount of data that would come by this URL. Any suggestions ?


#4

Explore the use of RxJS to manage, filter and parse the data. Good luck!


#5

I use a npm package called sort-by
https://www.npmjs.com/package/sort-by

I created 2 pipes
distinct
filter
they use sort-by the property align the data

 <ion-item *ngFor="let item of sortedAllReturn | distinct: {propName: 'name',sortNames:['name']}">

 <ion-item  *ngFor="let subitem of sortedAllReturn | filter: {propName: 'name',propValue: item.name,sortNames:['price'],rows: 0}">

hope that helps