Generate a new div element dynamicaly after every 10 elements are added

I am facing the following scenario:

I need to dynamically add an UNKNOWN number of checkboxes to a layout component, arranged in columns with 10 checkboxes per layout item.

Although I have successfully added all the checkboxes to a single div element, I am struggling to add the divs dynamically.

This is my current setup:

      <md-card v-if="loaded">
        <md-card-header>
          <div class="md-title">SETTINGS FOR COLUMNS</div>
        </md-card-header>
        <md-divider></md-divider>
        <md-card-content>

          <div>
            <b-form-checkbox
              v-for="option in options"
              v-bind:key="option.id"
              @input="changeOptions"
              :id="option.text"
              v-model="option.value"
              name="checkbox-1"
            >
              {{ option.displayName }}
            </b-form-checkbox>
          </div>

        </md-card-content>
      </md-card>

And this is the current output:

https://i.sstatic.net/HFKjb.png

My goal is to have the items neatly organized in columns with 10 checkboxes in each column.

This is the desired outcome: https://i.sstatic.net/XgCXp.png

Answer №1

To achieve this layout, simply utilize css grid:

<div class="grid-checkboxes">
...place your checkboxes here  
</div>
.grid-checkboxes {
  display: grid;
  grid-auto-flow: column;
  grid-template-rows: repeat(10, 1fr);
}

You can adjust the number of items per column by modifying the grid-template-rows property.

Answer №2

Implementing pagination for options can be achieved using a computed property like this:

computed:{
  paginatedOptions(){
        var matrix = [], i, k;

    for (i = 0, k = -1; i < this.options.length; i++) {
        if (i % 10 === 0) {
            k++;
            matrix[k] = [];
        }

        matrix[k].push(list[i]);
    }
  return matrix;         
 }

}

Then display the paginated array in your template like so:

<div v-for="pOptions in paginatedOptions" style="display:flex">
  <div>
       <b-form-checkbox
              v-for="option in pOptions"
              v-bind:key="option.id"
              @input="changeOptions"
              :id="option.text"
              v-model="option.value"
              name="checkbox-1"
            >
              {{ option.displayName }}
            </b-form-checkbox>
  </div>           
</div>

This pagination algorithm was inspired by this answer

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Tips for integrating Vuex store with router for seamless accessibility

Hey there! I'm currently working on a Vue project that involves using both vue-router and vuex. In my application, after a successful login, I store the JWT token in vuex. However, I am facing challenges with the following: 1) How to dynamically show ...

Using VueJs to associate boolean values with dropdowns

I am currently working on a form with a dropdown menu containing two options: "True" and "False". My goal is to save the selected value as a boolean in the form. For instance, when the user selects "True", I want the value stored as true in boolean format ...

The grandchild of sibling A sends out a signal, prompting the parent to make necessary adjustments in the value, however sibling B

This template serves as the parent with 2 child components <payment :isEditing="isEditing" @action="onActionButtonClick" /> <create-details v-if="isCompanyDetailsCreating" @action="onActionButtonClick" /> ...

Clicking on an element deactivates its hover state

While experimenting on this JSFiddle, I noticed that after clicking one of the boxes, the hover state becomes inactive and doesn't show up again. These three boxes have their background set using css background-image. The click event is attached usin ...

Can global Vue 3 plugins be utilized within Storybook narratives?

Is it possible to integrate a Vue 3 plugin into Storybook stories? One example is the use of FormKit for creating form elements within components. I have globally set up FormKit in my main.ts file like this: import { plugin, defaultConfig } from '@f ...

An easy way to place text along the border of an input field in a React JS application using CSS

I am struggling to figure out how to create an input box with text on the border like the one shown in the image below using CSS. I have searched extensively but have not been able to find any solutions to achieve this effect. I attempted using <input&g ...

Unable to select selectbox in the bottom section of Safari browser

There seems to be an issue with the selectbox being unselectable at the lower part in Safari. It's difficult to pinpoint the exact problem in the code. You can see the issue on the country selectbox by visiting this website: <span> <sp ...

Tips for adjusting the alignment of numbers in an ordered list to the right

Check out the code snippet below: The list items are correctly aligned to the right, but the numbers are not. How can we adjust the CSS so that the numbers align properly on the right as well? ol { width: 15vw; } <ol style="text-align:right;"> ...

The table is not displaying the CSS class as intended

I need to modify the behavior of a table so that upon clicking on a value, a specific class is set and the user is redirected to a particular page. The structure of the table is as follows: <?php // Determine the file name based on content type if( ...

How can I deactivate a specific range without altering the appearance with Bootstrap 5?

My challenge lies in maintaining the style of a range input while disabling user interaction with it. I've tried to recreate the original styling manually, but without success: <!DOCTYPE html> <html lang="en"> <head> <!-- ...

Arranging containers in a fixed position relative to their original placement

A unique challenge presents itself in the following code. I am attempting to keep panel-right in a fixed position similar to position: relative; however, changing from position: relative to position: fixed causes it to move to the right side while the left ...

Change the input field font style in AngularJS

Check out this Plunker link for validation of input field: http://plnkr.co/edit/iFnjcq?p=preview The validation only allows numbers to be entered and automatically adds commas. My query is, if a negative number is entered in the field, how can I change th ...

Vuex 3: The State Remains Unknown

software versions: "vue": "2.4.2", "vue-router": "2.7.0", "vuex": "3.0.1" I'm working on simulating a basic login feature with two input fields that will eventually utilize JWT for authenticated logins. However, I'm encountering an issue w ...

Searching for all classes and IDs in a CSS Stylesheet that include a specific keyword

I am currently working with a premium WordPress theme that has an extensive styles.css file consisting of over 25,000 lines. My goal is to make sitewide changes to the font and main color, and in order to do this effectively, I need to identify all classes ...

Utilize a single WebAssembly instance within two separate Web Workers

After compiling a wasm file from golang (version 1.3.5), I noticed that certain functions using goroutines are not supported. When these functions are called, they run in the current thread and slow down my worker significantly. To address this issue, I w ...

What steps should I take to fix my responsive media query?

I am currently working on fixing some responsive issues on my WordPress website. Previously, in mobile view, it looked like this: https://i.stack.imgur.com/vpvHy.jpg After adding the following code to the CSS of my child theme: @media only screen a ...

The system encountered an error stating that the required component "Footer" in the main directory was not located in the specified node_modules

Issue I'm Facing: Error found in components/main/Footer within the file path: ./node_modules/babel-loader/lib!./node_modules/vue-loader/lib/selector.js?type=script&index=0!./src/App.vue Components Tree as shown in the screenshot below: https ...

Optimizing performance by serving Vue JS chunks lazily from a CDN

I am currently working on a single-page application built with Vue.js 3 and managed by Vue CLI 5 (Webpack 5). The application is hosted within a Laravel app, which is deployed on AWS through Laravel Vapor. Using this tool, all static assets, including JS c ...

As the height is expanded, the background color gradually infiltrates the body of the page

I am currently working on an angular application that utilizes angular-pdf. The controller and view function perfectly, and the PDF is displayed correctly, except for one issue. The height of the PDF exceeds the min-height of the module, causing it to expa ...

Populate List Items until Maximum Capacity is Reached and Increase the

Is there a way to make a ListItem fill the list vertically while also being able to overflow it if needed? I'm looking for a solution that would allow me to access the height of the empty space in the list, which I believe would be the minHeight. Som ...