0

In my b-table i have a function that colors the rows based on a property :

<template>
    <b-table sticky-header="70vh" bordered striped
            :items="logs"
            :fields="fields"
            @row-clicked="showLogDetails"
            selectable
            select-mode="single"
            :tbody-tr-class="colorRowByCode"/>
</template>

methods: {
    colorRowByCode(item, type){
      if (!item || type !== 'row') return
      if(item.level === 'Critical') return 'table-danger'
      if(item.level === 'Warning') return 'table-warning'
      if(item.level === 'Error') return 'table-primary'
    }
  }

As you can see i return table-primary, let's say i wanna change this color to #FFDEB9

I followed these documentations : https://getbootstrap.com/docs/4.0/getting-started/theming/

https://github.com/bootstrap-vue/bootstrap-vue/issues/1395

https://bootstrap-vue.org/docs/reference/theming

So i created a custom.scss file in my assets and added this to my App.vue :

<style lang="scss">

  @import "assets/custom.scss";
  @import "~bootstrap/scss/bootstrap.scss";
  @import '~bootstrap-vue/dist/bootstrap-vue.css';

</style>

in my custom.scss i tried multiple things out like :

$table-primary: #FFDEB9 !default;
table-primary{
    color: theme-colors(#FFDEB9);
}

$theme-colors: (
  "primary": #FFDEB9,
  "table-primary": #FFDEB9
);
table-primary{
    color: #FFDEB9
}

without success, when i click on a row in the HTML explorer, all i see is that it has a class table-primary

enter image description here

How can i achieve this ? I really need differents colors for my table rows. Thanks a lot

1 Answer 1

0

You can have custom colored rows without changing the theme colors. Since you are giving the class name based on row, you can write CSS for the same.

Example : Lets say you have 3 types of row colors (row-danger, row-warning, row-primary)

methods: {
    colorRowByCode(item, type){
      if (!item || type !== 'row') return
      if(item.level === 'Critical') return 'row-danger'
      if(item.level === 'Warning') return 'row-warning'
      if(item.level === 'Error') return 'row-primary'
    }
  }

Now in CSS you can add,

<style lang="css">

.row-primary{
  background: #FFDEB9;
}

.row-danger{
  background: #FF0000;
}

.row-warning{
  background: #FF0101;
}

</style>

So basically you will be adding classes to your HTML using your method colorRowByCode and those classes will define the color for row as shown in CSS

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.