A
A
Artem Kondratsky2019-06-05 20:10:33
JavaScript
Artem Kondratsky, 2019-06-05 20:10:33

How to split into columns?

There is an array of data and there are several columns. I want to put 5 unique elements in each column using *ngFor. How can I do it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Nikolai Eremeev, 2019-06-06
@kondrackii

1) create a variable that will be responsible for the number of columns:

let count = Math.round(array.lenght / 5) // array - ваш массив
let columns = []
columns.length  = count

2) transform the array array into the following form [ [5 elements of the old array], [5 elements of the old array], [5 elements of the old array] ... ] // didn't describe how, I think you can handle it.
3) Making columns in the template
4) Display 5 unique values ​​in each column:
<div *ngFor="let column of columns; let i = index">
  <span *ngFor="let item of newArrays[i]> {{ item }} <span>
</div>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question