What are some creative ways to customize v-slot:cell templates?

Currently, I have the following code snippet within a table:

    <template v-slot:cell(checkbox)="row" style="border-left='5px dotted blue'">                      
       <input type="checkbox" v-model="row.rowSelected" @input="toggleSelectRow(row)"/>             
    </template>

I am attempting to apply inline styling to this template in order to add a fading border after form submission. However, I am encountering difficulty implementing even basic styles.

Although I am using bootstrap-vue, I believe regular CSS can still be utilized for customization.

Is there a straightforward method to incorporate a simple border around my cell?

Answer №1

Unfortunately, it's not possible to apply styles or classes directly to a <template>.

There are several workarounds available for this situation.

Firstly, you can utilize the fields property on b-table. By using the utility class p-0, you can remove default padding in a column. Add this class to the tdClass property within your field object. You can then wrap your b-checkbox within a div and reapply the desired padding to this element.

This method allows you to style the checkbox wrapper div as if it were the cell itself.

Another option is to use the tdClass property in the fields object to apply classes along with your styles. The advantage of tdClass is that you can bind a method to it, passing information about the cell's value. This means you can dynamically change applied classes based on the content of the cell.

The final option involves using b-table-simple and manually crafting the markup. While this approach provides full control over the table layout, it requires reimplementing the functionality of b-table from scratch.


Below is an example snippet demonstrating implementation of options 1 and 2:

new Vue({
  el: '#app',
  data() {
    return {
      fields: [
        'age',
        'first_name',
        'last_name',
        {
          key: 'active',
          tdClass: 'p-0'
        },
        {
          key: 'active2',
          tdClass: this.applyTdClass
        }
      ],
      items: [{
          age: 40,
          first_name: 'Dickerson',
          last_name: 'Macdonald',
          active: false,
          active2: false
        },
        {
          age: 21,
          first_name: 'Larsen',
          last_name: 'Shaw',
          active: false,
          active2: false
        },
        {
          age: 89,
          first_name: 'Geneva',
          last_name: 'Wilson',
          active: true,
          active2: true
        },
        {
          age: 38,
          first_name: 'Jami',
          last_name: 'Carney',
          active: false,
          active2: false
        }
      ]
    }
  },
  methods: {
    applyTdClass(value, key, item) {
      const classes = [];

      classes.push('border');
      /* Example of dynamically changing classes */
      if (value) {
        classes.push('bg-success');
      } else {
        classes.push('bg-danger');
      }

      return classes;
    }
  }
})
<link href="https://unpkg.com/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="f89a97">[email protected]</a>/dist/css/bootstrap.min.css" rel="stylesheet"/>
<link href="https://unpkg.com/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="50323f24109726253510627e61765c66675060605f9c7d65617c62">[email protected]</a>/dist/bootstrap-vue.css" rel="stylesheet"/>

<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.6.11/vue.js"></script>
<script src="https://unpkg.com/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="adcfc2dedcccd8dcdbc882cdcfdcedcbd296dad7d7daad80cfc8ccd186fbe92916bbe86">[email protected]</a>/dist/bootstrap-vue.js"></script>


<div id="app">
  <b-table :items="items" :fields="fields">
    <template v-slot:cell(active)="{ item }">
      <div style="padding: 0.75rem" class="border-left border-primary">
    <b-checkbox v-model="item.active"></b-checkbox>      
      </div>
    </template>
    <template v-slot:cell(active2)="{ item }">
      <b-checkbox v-model="item.active2"></b-checkbox>
    </template>
  </b-table>
</div>

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

Ensuring input boxes are neatly positioned underneath one another, regardless of the chosen font size

Is there a way in CSS to ensure that these input boxes are always aligned below each other, regardless of font family, size, or window movement by the user? https://i.stack.imgur.com/Zbadh.png Currently, I am using the following approach: tab1 { paddi ...

Can the arrangement of icons/buttons on the JW Player control bar be customized?

I am trying to customize the skin of my JWplayer like this: This is my current progress: I have been researching how to rearrange the order of icon / button on the controlbar. According to the jwplayer documentation, the buttons on the controlbar are div ...

Ways to create interactive multiple dropdown menu using vue-multiselect

I'm not sure if it's possible to achieve what I want with Vue for a specific component by changing its data and automatically loading it. Below is my expectation (tried in jQuery) var data = {country:{type:'dropdown',values:[' ...

"Having issues with Django not properly applying the JavaScript and CSS files I've linked in

I have completed my project and organized all the necessary files, including index.html, css, js, and settings.py within the appropriate folders. I am encountering an issue with applying a pen from the following source: CodePen index.html <!DOCTYPE h ...

Alert message in jQuery validation for the chosen option value

I am attempting to validate a combo box with the code provided below. Currently, I receive multiple alert messages even if one condition is true. My goal is to only display one alert message when a condition is met and highlight the other values in red. Th ...

Vuetify enabling dynamic calculations in real-time

I'm currently working on a Vuetify-based dynamic calculator project. Below is the code snippet I am using: <v-row class="mt-8 align-self-center"> <v-col cols="2"> <v-text-field :value="weight" ...

Stacking SVG elements can lead to distortion effects

Currently experimenting with the innovative SVG stacking method to integrate multiple icons into a single file, reducing the browser's HTTP requests. The details of this technique can be found in depth here. In essence, it involves placing numerous S ...

Is there a way to exchange the chosen options between two bootstrap-vue multiple select boxes?

Is there a way to switch the selected options between two bootstrap-vue multiple select boxes? I am trying to create a UI similar to the image shown below but I am struggling with writing the method. This is how I have written the template: <template ...

What is causing myInterval to not be cleared properly?

const homeButton = document.getElementById('home'); window.myInterval = 0; const showHome = () => { console.log('showHome'); window.myInterval = setInterval(wait, 400) } const wait = () => { console.log('wait'); ...

React Hamburger Menu not working as intended

I am facing an issue with my responsive hamburger menu. It is not functioning correctly when clicked on. The menu should display the navigation links and switch icons upon clicking, but it does neither. When I remove the line "{open && NavLink ...

Using Bootstrap to Position DIVs at the Top, Middle, and Bottom

I'm looking to create a layout with three DIVs inside a container DIV, all centered horizontally. The first DIV should be aligned at the top of the container, the second in the vertical center, and the third at the bottom. While I found some helpful t ...

Is there a method to pre-load a CSS background image so that it can still be displayed even without an internet connection?

Situation: Imagine having a web app that shows an error message when trying to perform an action but fails due to a connectivity problem. The error dialogue has a CSS class with a background image that can't load because of the connection issue, res ...

Encountering issues while deploying a Vue.js application on an Ubuntu server using GitLab Runner

Currently, I am in the process of deploying an application from a GitLab repository to a server running Ubuntu 20.04. The GitLab runner is registered and operational, with all SSH keys added accordingly. Although I have created the .gitlab-ci.yml file, I e ...

How can I retrieve the value from the input field using vue.js?

I am currently utilizing the vue-js-toggle-button library. While I understand that I can access the value inside the name using $refs, the issue arises as I have 3 toggle buttons and cannot set a Ref because I want to retrieve the name value dynamically i ...

Setting the font size for the entire body of a webpage globally is ineffective

Technology Stack: Nuxt.js + Vuetify.js Problem: Unable to set global body font size Solution Attempt: I tried to adjust the body font size to 40px in ~/assets/style/app.styl: // Import Vuetify styling ...

Tips for resolving state change issues in VUEX

I am facing an issue with making changes to the state while splicing an element from another array without affecting the state itself. To clarify, I want to remove one element from the array arrayWithFilters = [] without altering the state.selected.filte ...

Struggling to make css selector acknowledge the margins on the right and left

I am trying to style two inner divs within a containing div by floating the first one to the left and the second one to the right. Additionally, I want to add a margin of 15px on the left for the first div and on the right for the second div. The challenge ...

Chrome and Firefox: Images cling together

I've encountered an issue with my recently launched website. Some images in a grid appear to be stuck together, but this problem only occurs in Firefox and Chrome browsers. Oddly enough, zooming in to around 110% then back to 100% seems to temporarily ...

Effortlessly glide to the top of the webpage

After dedicating numerous hours to this task and being a newcomer to JavaScript/JQuery, I am still unsure of how to achieve the following: I have implemented a "back to top" anchor link in the footer of my pages that directs users back to the header. I am ...

Use v-bind to redirect to Localhost rather than the original link

The current button is linked to the data from v-for="book in books". The URL in the database is www.google.com. <md-button v-bind:href="book.url" target="_blank">SEE ORIGINAL</md-button> However, when loading the page on localhost, the butt ...