User
User

Reputation: 1361

Print blank rows in the table using ng-repeat

<table>
 <tr ng-repeat="obj1 in jsondata">
     <td>{{$index+1}}</td>
     <td>{{obj1.Subject_ID}}</td>
     <td>{{obj1.Credit}}</td>
 </tr>
 /********print blank row like following depends on jsondata length*****************/  
 <tr ng-repeat="obj1 in jsondata.length">
  <td colspan="3">&nsbp;<td>   
 </tr>
/******************************/
</table>

Suppose jsondata.length length is 7 then print 3 blank rows, else if jsondata.length length is 8 then print 2 blank rows else if jsondata.length length is 10 or more then no blank row

How to do this using ng-repeat or in any other easy way?

Upvotes: 2

Views: 1153

Answers (1)

Naghaveer R
Naghaveer R

Reputation: 2944

Create a temporary Array with length 10. Based on your jsonData length display blank td

  <table>
    <tr ng-repeat="obj1 in jsondata">
      <td>{{$index+1}}</td>
      <td>{{obj1.Subject_ID}}</td>
      <td>{{obj1.Credit}}</td>
    </tr>
    <tr ng-if="(temp.length >= jsondata.length)" ng-repeat="key in temp | limitTo: (jsondata.length - temp.length) track by $index">
      <td colspan="3">blank
        </td>
    </tr>
  </table>

DEMO

Upvotes: 1

Related Questions