1

I am using Vue and Vuetify to generate a table which I do. I want to make the headers of the table bold. Hence, I am thinking of passing a class to the headers and customize the headers from the CSS. Despite the fact that when I inspect the page(F12-> inspector) on the header my custom class has been passed but it don't do what I want it to do I feel like the code is overridden somehow. Can you please help ?

HTML:

   <v-data-table
                  :headers="headers"
                  :items="myDataPSUTwo"
                  :search="search"
                ></v-data-table>

the script:

data() {
    return {
      search: "",
      headers: [
        {
          text: "Name",
          align: "center",
          filterable: true,
          value: "name",
          class:"header-of-chart"
        },
        { text: "Value", value: "value" },
        { text: "Unit", value: "units" },
      ],
    };
  },

the CSS:

<style scoped>
.header-of-chart {
  font-weight: bold;
}

</style
4
  • If you can see your class has been applied when inspecting HTML, its properties may be overridden by the cascading nature of CSS if it is of less specificity. I can't see this from what you've provided, but worth trying font-weight: bold !important; Commented Apr 1, 2022 at 9:39
  • @paddyfields when i inspect the element i get this ``` class="text-center my-custom-cls sortable" ``` even if temporarily delete the other two classes still isnt doing anything ...i have added the !important as you suggested.. any other ideas? Commented Apr 1, 2022 at 9:49
  • Does this answer your question? Vuetify v-data-table custom header class styling not being applied Commented Apr 1, 2022 at 10:42
  • you need a deep selector to target/change vuetify styles. Here e .g >>> .v-data-table-header .header-of-chart Commented Apr 1, 2022 at 12:32

3 Answers 3

2

For anyone looking to use this in vuetify 3

in the script for headers, you can add headerProps with style in it

example use case:

data() {
    return {
      search: "",
      headers: [
        {
              title: 'Boat Type', 
              align: 'start', 
              key: 'name', 
              headerProps: 
              {
                  style: 'font-weight: 1000'
              } 
        }
      ],
    };
  },
Sign up to request clarification or add additional context in comments.

Comments

1

v-data-table has a header slot. You can use it to modify the header's style.

<template>
    <div id="app">
        <v-app id="inspire">
            <v-data-table
                :headers="headers"
                :items="desserts"
                :sort-by="['calories', 'fat']"
                :sort-desc="[false, true]"
                multi-sort
                hide-default-header
                class="elevation-1"
                >
                <template v-slot:header="{ props }">
                    <th v-for="head in props.headers">{{ head.text.toUpperCase() }}</th>
                </template>
            </v-data-table>
        </v-app>
    </div>
</template>
new Vue({
    el: '#app',
    vuetify: new Vuetify(),
    data () {
        return {
            headers: [
                {
                    text: 'Dessert (100g serving)',
                    align: 'start',
                    sortable: false,
                    value: 'name',
                },
                { text: 'Calories', value: 'calories' },
                { text: 'Fat (g)', value: 'fat' },
                { text: 'Carbs (g)', value: 'carbs' },
                { text: 'Protein (g)', value: 'protein' },
                { text: 'Iron (%)', value: 'iron' },
            ],
            desserts: [
                {
                    name: 'Frozen Yogurt',
                    calories: 200,
                    fat: 6.0,
                    carbs: 24,
                    protein: 4.0,
                    iron: '1%',
                }
            ],
        }
    },
})

Comments

0

v-data-table already have header text in bold that's the reason it is not impact anything. You want to increase the font size ? You can use it like this :

.header-of-chart {
  font-size: 25px !important;
}

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.