I'm facing a challenge where I need to showcase a set of text objects stored in an array within a grid format. I am utilizing the Ionic framework for this purpose.
Here are the specifications for the grid:
- It should have a fixed height
- Consist of exactly 3 rows
- Enable horizontal scrolling (infinite columns)
- Show 2 columns on screens narrower than 768px (phones) and 4 columns on screens 768px and wider (tablets)
I have already defined the media query for column widths and included for implementing horizontal scroll functionality.
The main question is how can I utilize ng-repeat (possibly with ngif ??) to construct the grid, starting from the first column and filling it with 3 rows before proceeding to the next column, and so on?
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"> <!-- Repeat this process 3 times before moving to the next row -->
<div class="row"><div class="col myGridCol">{{item.text}}</div></div>
</div>
</div>
</ion-scroll>
I'm currently stuck at determining the approach to switching to the next column after every 3 rows or confirming if this method aligns with the intended outcome.