Q
Q
qwentry2022-04-01 12:55:29
Bootstrap
qwentry, 2022-04-01 12:55:29

How to change the color of the entire row of bootstrap vue table?

Good afternoon.
Please tell me how to highlight the entire line, that is, make it danger?

There is a table:

<b-table
      :items="items"
      :fields="fields"
      :sticky-header="stickyHeader"
      head-variant="light"
      class="mt-5 mx-3"
    >
    </b-table>


As well as field & items
stickyHeader: true,

      items: [
        { login: 'user1', password: 'pass1', is_blocked: true, },
        { login: 'user2', password: 'pass2', is_blocked: false},
      ],
      fields: [
        {
          key: 'login',
          label: 'Login',
        },
        {
          key: 'password',
          label: 'Password',
        },
        {
          key: 'is_blocked',
          label: 'Blocked',
          formatter: (value, key, item) => {
            return value ? 'Yes' : 'No'
          },
          sortable: true,
        },
      ],


And actually the question is this. If I add _rowVariant: 'danger' to items, then I actually select the entire row, but this items arrives from the back and, accordingly, this row will not be there.
How can I make it so that if is_blocked is true, then the timeline would be red?

One of the options:
this.items.forEach(function(obj){if(obj.is_blocked === true){ obj._rowVariant = "danger"; } });

But are there any other options?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2022-04-01
@qwentry

methods: {
  trClass: rowData => rowData.is_blocked && 'table-danger',
  ...

<b-table
  :tbody-tr-class="trClass"
  ...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question