A
A
Andrey Vasilev2020-06-15 01:23:55
JavaScript
Andrey Vasilev, 2020-06-15 01:23:55

How to evenly split data into columns?

Good day to all.
There was such task:
There are conditionally speaking 3 lists.
There is an array with cities (random number).
It is necessary to somehow evenly scatter all the cities on these three lists.
Something like this:
5ee6a30a1cff7288769080.png
There is a block that links all 3 lists (wrapper).
The lists are split separately 'city-column' > 'city-column__item'.
I'm interested in the JS option, I understand that you can turn over and solder the flexes.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
0
0xD34F, 2020-06-15
@Nolis

Computed property :

data: () => ({
  items: [ ... ], // массив данных
  columns: 666, // количество колонок, на которые надо разбить items
  ...
}),
computed: {
  columnItems() {
    const { items, columns } = this;
    const colSize = Math.ceil(items.length / columns);
    return [...Array(columns)].map((n, i) => items.slice(i * colSize, (i + 1) * colSize));
  },
  ...
},

O
origami1024, 2020-06-15
@origami1024

And one list without flex and without js with properties will not work?column-fill: balance-all;column-count: 3;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question