Changing the color of a selected variant in a BootstrapVue table using Vue.js

I am making use of the bootstrap-vue table row select support feature and I would like to change the color of the selected-variant prop of the b-table. Currently, the color is set to info for the selected row in the table. I wish to customize it and set the color to #91c27d.

Here is the code snippet and a screenshot for reference.

Here is the HTML code for the table:

    <b-table 
       sticky-header="450px" 
       striped 
       hover 
       :items="items" 
       :fields="fields"
       ref="selectableTable"
       selectable
       :select-mode="selectMode"
       selected-variant="info"
       @row-selected="onRowSelected">   
    </b-table>

Here is the full script:

    import axios from 'axios';
    export default {
       name: "Canvassing",
       data() {
          return {
             fields: [
                { key: 'userId', label: 'User ID', thStyle: {background: '#0074a5', color: '#ffffff'} }, 
                { key: 'id', label: 'ID', thStyle: {background: '#0074a5', color: '#ffffff'} },
                { key: 'title', label: 'Title', thStyle: {background: '#0074a5', color: '#ffffff'} },
                { key: 'completed', label: 'Completed', thStyle: {background: '#0074a5', color: '#ffffff'} }
              ],
              items: []
           }
        },
        created() {
           axios 
            .get('https://jsonplaceholder.typicode.com/todos')
            .then(res => this.items = res.data)
            .catch(e => {
               this.errors.push(e)
             });
        },
        methods: {
           onRowSelected(items) {
              this.selected = items
           }
        }
    }

Below is the screenshot of the output: https://i.sstatic.net/XyTrj.png

Answer №1

To incorporate your value, consider creating a unique variant name. One way to achieve this is by introducing a new theme color to Bootstrap's SCSS them color table: and

Alternatively, you can designate the selected variant as "" (an empty string) and customize it using CSS by targeting the selected row with

.table > tbody > tr.b-row-selected

<style scoped>
/deep/ .table > tbody > tr.b-table-row-selected,
/deep/ .table > tbody > tr.b-table-row-selected > td,
/deep/ .table > tbody > tr.b-table-row-selected > th {
  background-color: #91c27d;
}
</style>

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

Div vanishes once SVG Gaussian blur is applied

I'm attempting to add a Gaussian blur effect to an element that contains some child nodes with content. In Chrome, I successfully applied the blur using the following style: -webkit-filter: blur(2px); Unfortunately, Firefox does not support thi ...

Automatically adjusting the height of a Bootstrap carousel as the token-input list grows in size

I am working on a carousel that functions as a form. One of the carousel items contains a multi-select box. How can I automatically increase the height of only that specific carousel item as the height of the multi-select box increases? The first image sh ...

A Vue object with dynamic reactivity that holds an array of objects

I've experimented with various approaches, but so far I've only managed to get this code working: // This works <script setup lang="ts"> import { reactive } from 'vue' import { IPixabayItem } from '../interfaces/IPi ...

Show the separation between columns in a bootstrap table

Can someone help me with setting up a cryptocurrency ticker display using Bootstrap? I want to add vertical lines between columns using border properties, but I'm not sure how to make the right side borders of the cells visible along rows. <!-- ...

Display/Conceal a div using CSS in React JS/Redux

I've been working on a CSS toggle for a div with className toggling. My approach involves using redux to manage the boolean state. Using the redux chrome extension, I can see that the state is indeed changing but the div remains invisible. If you have ...

Struggling to get my Vue.js unit test to pass with test-utils

I'm currently testing a specific part of my Heading.vue component <v-layout column align-center justify-center> <img src="@/assets/images/logo.png" alt="Logo-Choro-des-Charentes" height="200"> <h1 class="mb-2 disp ...

Files are nowhere to be found when setting up an angular project

After creating an Angular project, I noticed that some key files were missing in the initial setup, such as app.modules.ts and app-routing.modules.ts The project was generated using the command ng new name Here is a screenshot displaying all the files th ...

Display a div beside it when hovering over a specific part of the image

If I have an image that is 200px wide and 900px tall How can I make a div display alongside it when hovering over a specific section of the image? ...

Center text within a dropdown using Bootstrap styling

In a row within my inline form, I have both an email input and a dropdown. However, after resizing the page, the text within the dropdown is no longer positioned correctly (text on the left, arrow on the right). I attempted to fix this by using: text-alig ...

Issue encountered while attempting to create a dockerized vue/quasar/node application: "Execution of the command '/bin/sh -c quasar build' resulted in a non-zero exit code: 1"

I am having trouble creating a vue/quasar app with the Dockerfile, encountering some errors: Upon running the command '/bin/sh -c quasar build', I received a non-zero code: 1 Currently, I am utilizing the latest LTS node version. Executing the ...

Tips for limiting access to data from various tabs when the web page first loads

div#tabCtrl div#page1 This table showcases the information for tab1 div#page2 This table showcases the information for tab2 ...

Error in Firefox: "Anticipated media feature name, but discovered 'hover'"

I am trying to style elements differently based on whether the client browser supports hovering or not. I came across media features as a solution and implemented it in the following way: /* Supports hovering */ @media (hover: hover) { ... } /* Does not ...

Fade in images using jQuery

I am having issues with fading in and out images using jQuery, it doesn't seem to be working as expected. I think there might be something crucial that I am missing. Take a look at the script below: var count = 1; setInterval(function() { ...

The universal CSS variables of Material UI

Creating reusable CSS variables for components can greatly simplify styling. In regular CSS, you would declare them like this: :root { --box-shadow: 0 2px 5px -1px rgba(0, 0, 0, 0.3); } This variable can then be utilized as shown below: .my-class { ...

Showing recurring HTML elements with conditional content

I am displaying multiple bootstrap badges in a table column with different colors based on the values. Each badge has a unique class and style name to differentiate the colors. I feel like there is a lot of repetition in my HTML code. Is there a way for me ...

Implement a jQuery feature to gradually increase opacity as the user scrolls and the page loads

On a dynamically loaded page via pjax (except in IE), there are several links at the bottom. Whenever one of these hyperlinks is clicked, the page scrolls to the top while still loading. Although I am okay with this behavior, I'm curious if it' ...

Navigate to the first item on the menu in the Chrome browser

Why does the First Menu Item (.chosen) jump in Chrome Browser when refreshed? It seems like it's changing the Padding-Right and Padding-Bottom. Please review the code and help me solve this irritating issue. It works fine in Firefox. <body> ...

My lists are not being styled by Embedded and Internal CSS

I want the ingredients list to be styled in green, equipment list in red, and method list in blue using different CSS techniques. My external works fine for changing the color to red, but my internal styles don't seem to apply to the other lists. < ...

Text that is curving around a D3.js pie chart

I am currently working on creating a 3D-Js chart and I would like the pie text to wrap around the pie itself. This is the exact effect that I am trying to achieve: https://i.sstatic.net/YOLdo.png I am facing two main issues: I am currently printi ...

Tips on starting up elements in the presence of dynamic components

Here is a code snippet that I am working with: <div id="blocks"> <component v-for="block in blockList" :is="block.component" :id="block.uniqueId" :init-show-header="showHeaders" v-model= ...