Problem: Given an array of 'n' items I want them rendered in separate tables of m rows each. For example, if I have an array of n=30 items and m=6 then I need 5 tables of 6 items each appearing horizontally stacked together.
Attempted Solution: I tried using ng-repeat and ng-switch to render something to this effect but it didn't work. I am able to render these items as a single table (that's straight forward).
I know the code pasted below doesn't work as the first ng-switch doesn't close the and tags. Are there any generally known tricks to achieve something like this?
itemapp.directive("items", function () {
'use strict';
return {
restrict: 'E',
template: '<div id="itemDiv" ng-repeat="item in items" ng-show="$index==0">' +
'<span ng-switch on="$index % 10">' +
' <div ng-switch-when="0">' +
' <table><tbody>'+
' </div>'+
'<tr class="itemon">' +
'<td><input type="radio" ng-model="item.on" value="0" >OFF</input></td>' +
'<td>{{$index}}</td>'+
'</tr>' +
' <div ng-switch-when="9">' +
' </table></tbody>'+
' </div>'+
'</span>' +
'</div ng-show="$index==0">',
link: function (scope) {
},
scope: {
items: '='
}
};
});
Here is the code as an HTML Template:
<div id="itemDiv" ng-repeat="item in items" ng-show="$index==0">
<span ng-switch on="$index % 10">
<div ng-switch-when="0">
<table>
<tbody>
</div>
<tr class="itemon">
<td><input type="radio" ng-model="item.on" value="0">OFF</input></td>
<td>{{$index}}</td>
</tr>
<div ng-switch-when="9">
</table></tbody>
</div>
</span>
</div ng-show="$index==0">