Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make two column to repeat for one item in the list?

Is there possible for the angular repeat to achieve that?Basically Im wondering there is a way to loop the 2 together? Really appreciate any help!

Controller:

$scope.date=[
    {ID:1,Date:'2016-11-12'},
    {ID:2,Date:'2016-11-15'},
    {ID:3,Date:'2016-12-06'}
]

HTML:

<table border="1" align="center">   
    <tr>            
        <th rowspan="2">ITEMCODE</th>
        <th rowspan="2">DEBTORCODE</th> 
        <th colspan="2" ng-repeat="d in date">{{d.Date}}</th>   
    </tr>       
    <tr>
        <th>Bal</th>
        <th>Order</th>
    </tr>
</table>

And I wish the column Bal and Order will repeat side by side under each date column. And I expect the column Bal and Order will repeat side by side

like image 249
Vincent Tang Avatar asked Dec 09 '16 13:12

Vincent Tang


2 Answers

You can use ng-repeat-start and ng-repeat-end which was introduced in Angular 1.2

<th ng-repeat-start="d in date">Bal</th>
<th ng-repeat-end>Order</th>

Working example https://jsfiddle.net/9ve3fu0m/

like image 66
Kenny Avatar answered Oct 25 '22 00:10

Kenny


You can accomplish this by using a nested table like this:

<table border="1" align="center">
<tr>
  <th rowspan="2">ITEMCODE</th>
  <th rowspan="2">DEBTORCODE</th>
  <th colspan="2" ng-repeat="d in date">
    <table border="1" >
      <tr>
        <th colspan="2">{{d.Date}}</th>
      </tr>
      <tr>
        <th>Bal</th>
        <th>Order</th>
      </tr>
    </table>
  </th>
</tr>
</table>
like image 20
jbrown Avatar answered Oct 25 '22 02:10

jbrown