I have a simple array of text objects that I want to display in a grid. This is using the Ionic framework.
The grid must be:
- Fixed height
- Exactly 3 rows
- Horizontal scroll (infinite columns)
- 2 visible columns with screen width < 768px (phones), 4 visible columns 768px and above (tablets)
I have the media query for the column widths and am using for the horizontal scrolling functionality.
How can I use ng-repeat (maybe with ngif ??) to create the grid, starting in the first column and filling that column with 3 rows before moving to the next column etc etc)
JS
var items = [
{text: "This is item1"},
{text: "This is item2"},
{text: "This is item3"},
.
.
.
]
CSS:
.myGridRow {
height: 40%;
}
.myGridCol {
width: 50%;
}
@media only screen and (min-width : 768px) {
.myGridCol {
width: 25%;
}
}
HTML
<ion-scroll direction="x">
<div class="row myGridRow"> <!-- The single container for the whole grid -->
<div ng-repeat="item in items"> <!-- only do this 3 times before starting a new row -->
<div class="row"><div class="col myGridCol">{{item.text}}</div></div>
</div>
</div>
</ion-scroll>
I am stuck here trying to determine how to move to the next column after each 3 rows, or if this is even the right way to do this.