Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

109
Visualizações
Boostrap Vue Change Cell Text in B-table

In a b-table, each cell in a column should have different text color. Not the background of the cell, but the actual text color. I am able to change the text color of the column header, but not the individual cell texts.

The b-table code:

<b-card title="Total">
  <b-table sticky-header="600px" hover :items="total" :fields="groupByFields"></b-table>
</b-card>

The fields where the column header color change is:

groupByFields: [
    {
      key: 'name',
      sortable: true,
    },
    {
      label: 'Total',
      key: 'count',
    },
    {
      key: 'interested',
      thStyle: { color: '#3eef33' },
      sortByFormatted: false,
      formatter: (value) => {
        const res = value;
        return (`($${res})`);
      },
    },
  ],

The thStyle color attribute changes the header text color, but not the text of values in the cells of that column. How would I match that color to the cell text (not background) of that column too?

about 4 years ago · Santiago Gelvez
1 Respostas
Responde à pergunta

0

Here's an example, using the #cell() slot:

new Vue({
  el: '#app',
  data: () => ({
    items: [],
    fields: [
      'id',
      { key: 'title', style: { fontStyle: 'italic' } },
      { key: 'price', style: { color: 'red', textAlign: 'right' } }
    ]
  }),
  mounted() {
    fetch('https://dummyjson.com/products')
     .then(_ => _.json())
     .then(_ => this.items = _.products);
  }
})
<link href="https://unpkg.com/bootstrap@4.6.1/dist/css/bootstrap.min.css" rel="stylesheet"/>
<link href="https://unpkg.com/bootstrap-vue@2.22.0/dist/bootstrap-vue.css" rel="stylesheet"/>
<script src="https://unpkg.com/babel-polyfill/dist/polyfill.min.js"></script>
<script src="https://unpkg.com/vue@2.6.12/dist/vue.min.js"></script>
<script src="https://unpkg.com/bootstrap-vue@2.22.0/dist/bootstrap-vue.js"></script>

<div id="app">
  <b-table :items="items" :fields="fields">
    <template #cell()="{field, value}">
      <div :style="field.style" v-text="value" />
    </template>
  </b-table>
</div>

If you only need to style a few columns, you might want to use appropriate #cell({key}) slots.

Documentation here.


Probably the most common technique is to add classes to cells. It provides granular control over the applied styling, without sacrificing flexibility.

about 4 years ago · Santiago Gelvez Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda