Say I have the following data structure
* Key 1
* Value 1
* Value 2
* Key 2
* Value 3
* Value 4
* Value 5
How, with AngularJS, can I render it in a table similar to the following:
|-------|---------|
| Key 1 | Value 1 |
| |---------|
| | Value 2 |
|-------|---------|
| Key 2 | Value 3 |
| |---------|
| | Value 4 |
| |---------|
| | Value 5 |
|-------|---------|
The keys are done via rowspan
.
Nice and tricky question!
One way to do it would be:
Given an object like this:
$scope.testData={
key1:[1,2],
key2:[3,4,5]
};
You could do this:
<table>
<tr ng-repeat-start="(key, val) in testData">
<td rowspan="{{val.length}}">{{key}}</td>
<td>{{val[0]}}</td>
</tr>
<tr ng-repeat-end ng-repeat="value in val.slice(1)">
<td>{{value}}</td>
</tr>
</table>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With