javascript - Vuetify Data Table (v-data-table) - how to conditionally style values in certain columns - Stack Overflow

What is the easiest way to highlight certain values in a column in a Vuetify Data Table (v-data-table p

What is the easiest way to highlight certain values in a column in a Vuetify Data Table (v-data-table ponent).

E.g. let's say in this first example here:

How to automatically style values in the Calories column that are greater than 300 in bold and red?

What is the easiest way to highlight certain values in a column in a Vuetify Data Table (v-data-table ponent).

E.g. let's say in this first example here: https://vuetifyjs./en/ponents/data-tables

How to automatically style values in the Calories column that are greater than 300 in bold and red?

Share Improve this question asked Aug 27, 2019 at 9:29 Mark Z.Mark Z. 2,44724 silver badges35 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 5

You can do something like that :

    <v-data-table
      :headers="headers"
      :items="desserts"
      class="elevation-1"
    >
      <template v-slot:item.calories="{ item }">
        <div :class="getStyle(item.calories)">{{ item.calories }}</div>
      </template>
    </v-data-table>

Then, in your script you can add a method "getStyle" that automatically style the values.

methods: {
    getStyle (calories) {
      if (calories > 300) return 'red--text font-weight-bold'
      else return ''
    },
  },

Here a codepen example : https://codepen.io/guizboule/pen/LYPyWMV?&editable=true&editors=101

In you want another solution, Vuetify made an example with chips : https://codepen.io/guizboule/pen/vYBmxwg?&editable=true&editors=101

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745318388a4622325.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信