I am looking to arrange the names in alphabetical order when a list item is clicked. My tools of choice are Vue.js and Flex Grid.
The list item I am working with is called ListAll,
When clicking on ListAll, I want to display all the records grouped by names from the nameList array. However, I am encountering difficulties in displaying the grouped names as intended. The problem lies in creating line breaks after each set of names. I am utilizing Flex Grid for this purpose. After displaying the records starting with A, the records starting with B should appear on a new line, but unfortunately they do not break to a new line. How can I implement a line break after each group of names using Vue.js, ES6, or CSS?
To add a line break, I have tried using
<div class="break"></div>
, but it is not achieving the desired outcome.
The records are currently being displayed in 4 columns without any line breaks using flexbox grid CSS class, as shown below:
Apples Apricots Avocados Almond
Abiu Berry Bananas Boysenberries
Blueberries Breadfruit Carambola Cantaloupe
Cranberries Cherries Custard-Apple
Expected Output:
Apples Apricots Avocados Almond
Abiu
Berry Bananas Boysenberries Blueberries
Breadfruit
Carambola Cantaloupe Cranberries Cherries
Custard-Apple
AlphabeticalFruitsName.vue
<template>
<div id="wrapper">
<ul class="listitems">
<li><a
href="javascript:;" @click="userSelection('ListAll')">ListAll</a>
</li>
</ul>
<div class="grid-container">
<div v-for="(name, index) in nameList" :key="name" class="grid-item">
<ul v-for="letter in alphabets" :key="letter">
<li v-if="name.startsWith(letter)"><a>{{ name }}</a></li>
<div class="break"></div>
</ul>
</div>
</div>
</div>
</template>
<script>
export default {
name: 'AlphabeticalFruitsName',
data() {
return {
nameList: [],
alphabets: ['A','B','C','D','E','F','G','H','I','J','K','L',
'M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z',],
names: [
{ name: 'Apples' },{ name: 'Apricots' },{ name: 'Avocados' },{ name: 'Apple Berry' },
{ name: 'Apple guava' },{ name: 'Almond' },{ name: 'Almond' },{ name: 'African Honeysuckle' },
{ name: 'African Plum' },{ name: 'Abiu' },{ name: 'Bananas' },{ name: 'Boysenberries' },
{ name: 'Blueberries' }, { name: 'Bing Cherry' },{ name: 'Breadfruit' },{ name: 'Cantaloupe' },
{ name: 'Carambola' },{ name: 'Cherimoya' },{ name: 'Cherries' },{ name: 'Cranberries' },
{ name: 'Custard-Apple' },{ name: 'Dates' }, { name: 'Honeysuckle' },{ name: 'Gooseberries' },
{ name: 'Grapefruit' },{ name: 'Grapes' },{ name: 'Guava' },{ name: 'Tangerine' },
{ name: 'Kiwi' },{ name: 'Lychee' },{ name: 'Strawberries' }, { name: 'Watermelon' }],
};
},
methods: {
userSelection(listItemName) {
this.nameList = [];
if (listItemName === 'ListAll') {
for (const value of this.names) {
this.nameList.push(value.name);
}
}
},
},
};
</script>
<style lang="scss" scoped>
.listitems {
display: flex;
justify-content: center;
}
ul {
list-style-type: none;
}
.grid-container {
display: grid;
grid-template-columns: auto auto auto auto;
padding: 10px;
}
.grid-item {
text-align: center;
}
.new-line:last-child {
content: '\a';
white-space: pre;
}
.break {
flex-basis: 100%;
height: 0;
}
</style>