最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Quasar conditional style of cell in component q-table - Stack Overflow

programmeradmin6浏览0评论

I would like to change color style in cell of q-table ponent.

{
  name: 'Active',
  align: 'center',
  label: 'Active',
  field: row => row.active,
  style: val => val ? 'color: red;' : 'color: black;',
  format: val => String(!!val),
  sortable: true
}

But this doesn't work.

If I try for testing, this work in all cells:

style: 'color: red;'

I think this is the mistake of my code in JS.

I would like to change color style in cell of q-table ponent.

https://codepen.io/abkrim-the-flexboxer/pen/eYYjPZZ

{
  name: 'Active',
  align: 'center',
  label: 'Active',
  field: row => row.active,
  style: val => val ? 'color: red;' : 'color: black;',
  format: val => String(!!val),
  sortable: true
}

But this doesn't work.

If I try for testing, this work in all cells:

style: 'color: red;'

I think this is the mistake of my code in JS.

Share edited Oct 19, 2021 at 13:05 Super Kai - Kazuya Ito 1 asked Nov 11, 2019 at 19:54 abkrimabkrim 3,6928 gold badges48 silver badges74 bronze badges 1
  • Because the style property is getting evaluated based on the val wouldn't it be applied using v-bind: (just taking a guess here). – Neha Sharma Commented Nov 11, 2019 at 20:42
Add a ment  | 

1 Answer 1

Reset to default 6

I think custom style classes use as function is removed from version 1(Ref https://github./quasarframework/quasar/issues/242, https://github./quasarframework/quasar/issues/2326). I tried this but it does not work.

{
  label: 'Message',
  field: 'message',
  classes (val) {
    return val.active==1 ? 'bg-red' : 'bg-yellow'
  },
  sort: true,
  width: '500px'
}

So best way is to customize the single column using slots.

<template v-slot:body-cell-active="props">
  <q-td :props="props" :class="props.row.active==1?'text-red':'text-black'">
    {{props.row.active}}
  </q-td>
</template>

Please refer the following code pen. You need to change the name of the active column in the lower case.

https://codepen.io/Pratik__007/pen/xxxaKxg

发布评论

评论列表(0)

  1. 暂无评论