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

I'm new to Angular and I'm wondering how to close the panel by clicking on the 'x' button and also by clicking on the screen. Can anyone help me with this

Below is the HTML code I use for my button: <button class="btn btn-outlined " ng-click="vm.showCommentBox1()">Notify All</button> <div class="comment-box custom saveAll" ng-if=""><div class="panel panel-default"> ...

Resizing images in HTML can sometimes lead to extra white space appearing underneath the

I am facing an unusual scaling issue with my website design. Whenever I resize the browser window horizontally, the image scales correctly, but it leaves a white space below it where the rest of the page should start from if the window is large. I'm ...

Encountering an error when trying to add Vue Router to a pre-existing Vue.js project

Encountered npm error code ERESOLVE which led to the inability to resolve dependency tree. The error occurred while trying to resolve the dependencies for "[email protected]". It was found that "[email protected]" was present in the vue node_modu ...

Issue with Sass @use failing to load partial

I'm currently facing an issue while trying to import a sass partial called _variables.scss into my main stylesheet named global.scss. Every time I compile the sass code, I encounter the following error message: Error: Undefined variable. Here is the ...

The minimum height of the IE element could not fully expand within its flex container that was set to absolute positioning

Creating a webpage with a full-page layout using a content session that spans the entire height of its container is my current project. To achieve this, I have implemented the following: The content's container (div.inner) is set to be absolute-posi ...

How can I create a fixed class="form-row" and align a label and textbox in a horizontal line?

I encountered an issue with my simple bootstrap form that contains the following fields: The Labels and text box are not aligned properly in a straight line. When adjusting the size of the Notes field, it affects the positioning of the other fields causin ...

Ways to specify distinct css styles according to varying number of elements

I need the Button element to always take up 100% of the container, no matter how many elements are inside. Check out my Fiddle link here: Js Fiddle Link <div class="inputFieldBoolean buttonSeries" data-type="Boolean"><button class="true" data-va ...

Vue .filter doesn't work with reactive data sources

I'm currently working on a project that involves creating a dynamic shipping estimate in a Shopping Cart. The challenge I face is retrieving shipping methods from an API endpoint and making the data reactive to update in real-time based on the selecte ...

Tips for changing the size of a div using an absolute div position

Is it possible for the #parent div to resize based on the dimensions of the #child div (if the #child div is using position:absolute;)? Similar to how the #t_parent table resizes according to the size of the #t_child table. <div id="parent" style="pos ...

Utilizing Bootstrap Plugins with Nuxt.js: A Step-by-Step Guide

"dependencies": { "ant-design-vue": "^1.7.2", "bootstrap": "^4.6.0", "core-js": "^3.8.3", "nuxt": "^2.14.12", "popper.js": "^1.16.1" } ...

In Vue, it is not accurate to measure overflow

I am working on creating an overflow effect with tagging that fades out at the beginning to provide a subtle hint to users that there is more content. Here is what it currently looks like: https://i.stack.imgur.com/fXGBR.png To achieve this, I added a fa ...

Tips on Utilizing If/Else Conditions in HTML Table TD_TAGS

Can someone please explain how to implement an if/else condition within this <td> tag? <td data-label="Status">{{$t('Status'+item.cStatus)}}</td> This is what I am trying to achieve: if(item.cStatus == NW){ color:red ...

Unraveling the Mystery of CSS3 or JavaScript Sliders

I am currently developing a new website and I was intrigued by the slider effect on Apple and IBM's websites. For reference, you can check out how it works on sites like: and I noticed that the text and images slide in opposite directions, which se ...

developing both vertical and horizontal 'cross out'

I'm attempting to add a 'spacer' between buttons on my website using the word "or" with a vertical line centered above and below it. I've tried HTML <div class="footer-btn-wrap"> <div class="decor"><a href="... < ...

How can I disable the background color in Chrome autocomplete? Is there a way to make the background

There's a form on my website where the autocomplete feature shows a blue background color. The form itself has a semi-transparent white background. I managed to change the autofill color to white using this CSS property: -webkit-box-shadow: 0 ...

The DOM is failing to refresh in Vue.js even after the array has been updated

After receiving a list of items using AJAX, I store them in a data Array: loadSparepartFiles: function() { var vm = this; vm.activeSparepart.attachments = []; ajaxApi.loadJson('spareparts/sparepart/getFiles/'+vm.activeSparepartId, fu ...

The behavior of Mozilla in handling JQuery attr() function may result in variations in design elements such as font-family or font-size

I'm currently working on the login form. Below is my view in CodeIgnitor: <div id="login-form"> <?php echo heading('Login', 2); echo form_open('login/login_user'); echo form_input('email', set_value ...

Tips for preventing page breaks (when printing or saving as a PDF) in lengthy HTML tables

Here is the link to a single HTML file (including style and scripts): FQ.html The problem I'm facing can be seen in this image: I've tried several solutions, the latest of which involves the following CSS... @media print{ @page { size:10 ...

A guide on efficiently updating multiple Vue 3 components when a Pinia array undergoes changes

I'm facing an issue where multiple components accessing the same store don't respond to updates unless I manipulate a DOM element to trigger a new render. Within my Pinia store, I have an array and an update method: let MyArray: IMyItem[] = ...

The window.open() function is malfunctioning on Google Chrome

Within my vue.js application, I have encountered an issue when attempting to utilize window.open() to open a new tab. Strangely, whenever I use this method, the new tab opens briefly before immediately closing without loading any content. Surprisingly, win ...