0

From a Rest Api I am getting the following:

{
 "headers": ["h1", "h2"],
 "body": [{"h1": "a1", "h2":"a2"},
          {"h1": "b1", "h2":"b2"},
           ...                   ]
}

Now I would like to transform this one into an (orderable table) with angular. I tried:

<table class="table table-striped">
    <thead>
    <tr>
        <th ng-repeat="header in data.headers">{{ header }}</th>
    </tr>
    </thead>
    <tbody>
    <tr ng-repeat="line in data.body">
        <td ng-repeat="(key, val) in line">{{ val | date : "dd.MM.yy" }}</td>

    </tr>
    </tbody>
</table>

Of course it does not work, as objects do not have a key order in javascript. Is there a simple way to sort the line by headers?

0

1 Answer 1

3

You can do this very simple:

<tr ng-repeat="line in data.body">
    <td ng-repeat="header in data.headers">{{ line[header] | date : "dd.MM.yy" }}</td>
</tr>
Sign up to request clarification or add additional context in comments.

1 Comment

@N.V.Prasad No, orderBy sorts by field of iterated objects. But in our case lines have no 'header' field.

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.