0

I'm trying to create a dynamic table using ionic and AngularJS with exactly 5 columns for each rows. How do I traverse JSON DOM so I don't repeat the same record 5 times each row. Here's the structure of my tags. Many thanks.

<div class=“row” hg-repeat=“item in items”ng-controller=“myController”>
<div class=“col col-15”>
    <div class=“row”>
        <div class=“col col-25”>{{item.productName}}</div>
        <div class=“col col-75”>{{item.price}}</div>
    </div>
</div>

<div class=“col col-15”>
    <div class=“row”>
        <div class=“col col-25”>{{item.productName}}</div>
        <div class=“col col-75”>{{item.price}</div>
    </div>
</div>

<div class=“col col-15”>
    <div class=“row”>
        <div class=“col col-25”>{{item.productName}}</div>
        <div class=“col col-75”>{{item.price}</div>
    </div>
</div>

<div class=“col col-15”>
    <div class=“row”>
        <div class=“col col-25”>{{item.productName}}</div>
        <div class=“col col-75”>{{item.price}</div>
    </div>
</div>

<div class=“col col-15”>
    <div class=“row”>
        <div class=“col col-25”>{{item.productName}}</div>
        <div class=“col col-75”>{{item.price}</div>
    </div>
</div>
</div>
A.P.
  • 11
  • 4
  • How many rows you want? – Mr_Perfect Dec 27 '16 at 05:01
  • Depend on the data. This part is dynamic. – A.P. Dec 27 '16 at 05:06
  • There may only be 2 or 3 columns in the last row. Thanks for asking – A.P. Dec 27 '16 at 05:09
  • this is very similar, and there are a few different methods listed. You should be able to adapt one of the methods listed for your purpose: http://stackoverflow.com/questions/27211799/angular-ng-repeat-add-bootstrap-row-every-3-or-4-cols – Claies Dec 27 '16 at 05:18
  • Thanks. I'll check it out. – A.P. Dec 27 '16 at 05:32
  • no they don't work. They don't display the first few rows. and traversing JSON DOM by way of $index doesn't work. I tried many different variations. – A.P. Dec 27 '16 at 08:24
  • I did this simple codes in PHP. Is there anyway we can do this using JavaScript $sample = 17; for ($n = 1; $n <= $sample; $n++) { $x=0; if ($n==1 OR $x==$n+1) {echo"";} echo "
    $n
    "; if ($n%5==0 OR $n==$sample) {echo""; $x=$n+1;} }
    – A.P. Dec 27 '16 at 08:26

0 Answers0