1

I have Json data

[{"ID": "01000", "Name" : "Name1", "Age" : 25},
 {"ID": "01001", "Name" : "Name2", "Age" : 30},
 {"ID": "01001", "Name" : "Name3", "Age" : 23}]

and want to show this data in multiple table using ng-repeat. table should look like this

How the tables should look like

I've created function which locates Distinct ID's into "$scope.ID" variable.

    $scope.ID = [];
    $scope.ID.push("1");
    var s = 0;
    for (var i = 0; i < $scope.Report.length; i++){

        if ($scope.ID[s] != $scope.Report[i].Id){
            $scope.ID.push($scope.Report[i].Id);                 
            s++;
        }            
    }

Then I'm trying to display data into table in this way

    <div class="table" ng-repeat="id in ID" ng-model="query">

    <div class="row header">
      <div class="cell">
        ID
      </div>
      <div class="cell">
        NAME
      </div>
      <div class="cell">
        AGE
      </div>
    </div>

    <div class="row"  ng-repeat="r in Report | filter: query track by $index">
      <div class="cell">
        {{r.id}}
      </div>
      <div class="cell">
        {{r.name}}
      </div>
      <div class="cell">
       {{r.age}}
      </div>

    </div>
  </div>

Script returns two table but, each table has the same three value,

What the tables actually look like

I need that each generated table had own filter value, for this case first table should be filtered by ID: 01000 and second table By ID: 01001.

What should I do for this?

1 Answer 1

2

Try:

<div class="row header">
  <div class="cell">
    ID
  </div>
  <div class="cell">
    NAME
  </div>
  <div class="cell">
    AGE
  </div>
</div>


<div class="row"  ng-repeat="r in Report | filter: {id: id}">
  <div class="cell">
    {{r.id}}
  </div>
  <div class="cell">
    {{r.name}}
  </div>
  <div class="cell">
   {{r.age}}
  </div>

</div>

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.