I want to show 4 items per row. I have a markup like below. Depending on that markup i need to show four items in a single row. for example, If i have 8 data then there will be two row and each row consists 4 items.
If i loop outside <Grid gutters col="cols-4">
then there will be eight such elements and if i loop
inside that element then there will be eight Cell
element. How can this case be handled?
Here is the markup
const data = [
{id: 1, header: 'header', content: 'content', footer: 'footer'},
{id: 2, header: 'header', content: 'content', footer: 'footer'},
{id: 3, header: 'header', content: 'content', footer: 'footer'},
{id: 4, header: 'header', content: 'content', footer: 'footer'},
{id: 5, header: 'header', content: 'content', footer: 'footer'},
{id: 6, head/xer: 'header', content: 'content', footer: 'footer'},
{id: 7, header: 'header', content: 'content', footer: 'footer'},
{id: 8, header: 'header', content: 'content', footer: 'footer'},
]
<Grid gutters col="cols-4">
<Grid.Cell key={datum.id}>
<Card>
<Card.Header>{datum.header}</Card.Header>
<Card.Content>{datum.content}</Card.Content>
<Card.Footer>{datum.footer}</Card.Footer>
</Card>
</Grid.Cell>
<Grid.Cell>
</Grid.Cell>
<Grid.Cell>
</Grid.Cell>
<Grid.Cell>
</Grid.Cell>
</Grid>
<Grid gutters col="cols-4">
<Grid.Cell key={datum.id}>
<Card>
<Card.Header>{datum.header}</Card.Header>
<Card.Content>{datum.content}</Card.Content>
<Card.Footer>{datum.footer}</Card.Footer>
</Card>
</Grid.Cell>
<Grid.Cell>
</Grid.Cell>
<Grid.Cell>
</Grid.Cell>
<Grid.Cell>
</Grid.Cell>
</Grid>
To begin with, go about splitting the data in to chunks for each row. Try this:
That will remove the entries from the
data
array in lengths of4
and place them in to a multidimensional array which will look like this:Then you can go about looping through each of the arrays to dump out the markup.
The markup here is pseudo code and not properly tested but hopefully you get the idea.