Reputation: 38683
I am doing dynamically create a table and rows with using angularjs (ng-repeate)
example html :
<table>
<tr>
<td ng-repeat="obj in labellist">
{{obj.label}}
</td>
</tr>
<tr>
<td ng-repeat="obj in valauellist">
{{obj.value}}
</td>
</tr>
</table>
Data:
$scope.labellist=[{lable:"Address1"},{lable:"Address2"},{lable:"Address3"},{lable:"Address3"},{lable:"Address5"},{lable:"Address6"}];
$scope.valauellist=[{Value:"AAA"},{Value:"BBBB"},{Value:"CCCC"},{lable:"Address1"},{Value:"DDDD"},{Value:"EEEE"}]
Now the result is displaying like
Address1 Address2 Address3 Address5 Address6
AAAA BBBB CCCC DDDDD EEEEE
But I want to create tr
tag if the td
count is more than 3 (n count of number) .
Like
Address1 Address2 Address3
AAAA BBBB CCCC
Address5 Address6
DDDDD EEEEE
I tried to solve this with using angular
$index % 2
formula. but it's not working for me (any idea about this???). So I decide to wrap thetd
tag like astr
tag while increasing (like responsive) the wholetd
size is greater than table width.
All ideas are appreciated ...
Upvotes: 1
Views: 107
Reputation: 18392
Check out this fiddle. It uses a ul
list to achieve what you need. This solution does not base on 2 objects for rendering content and labels. I recommend to not store your labels and values in different objects.
<div ng-controller="MyCtrl">
<ul>
<li class="column-3" ng-repeat="item in items">
<strong>{{ item.header}}</strong><br/>
{{ item.value }}
</li>
</ul>
</div>
var myApp = angular.module('myApp',[]);
myApp.controller('MyCtrl', function ($scope) {
$scope.items = [{
header: 'test',
value: 'value 1',
},{
header: 'test',
value: 'value 1',
},{
header: 'test',
value: 'value 1',
},{
header: 'test',
value: 'value 1',
},{
header: 'test',
value: 'value 1',
}];
});
.column-3 {
width:33%;
float:left;
}
Upvotes: 1