Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vuetify table - custom css isn't applied to first row after page reload

Table:

<v-card :dark="true">
      <v-card-title>
        <v-btn color="indigo" dark @click="initialize"><v-icon dark>refresh</v-icon></v-btn>
        <v-spacer></v-spacer>
        <v-text-field append-icon="search" label="Search" single-line hide-details></v-text-field>
      </v-card-title>
      <v-data-table :dark="true" :headers="headers" :items="expenses" hide-actions class="elevation-1">
        <template slot="headers" slot-scope="props">
          <tr>
            <th v-for="header in props.headers">{{header.text}}</th>
          </tr>
        </template>
        <template slot="items" slot-scope="props">
          <tr v-bind:class="getClass(props.item)">
            <td class="text-xs-center">{{ props.item.year }}</td>
            <td class="text-xs-center">{{ props.item.month }}</td>
            <td class="text-xs-center">{{ props.item.day }}</td>
            <td class="text-xs-center">{{ props.item.description }}</td>
            <td class="text-xs-center">{{ props.item.value }}</td>
            <td class="text-xs-center">{{ props.item.category }}</td>
            <td class="text-xs-center">{{ props.item.details }}</td>
            <td class="justify-center layout px-0">
              <v-btn icon class="mx-0" @click="deleteItem(props.item)">
                <v-icon color="pink">delete</v-icon>
              </v-btn>
            </td>
          </tr>
        </template>
        <template slot="no-data">
          <v-btn color="primary" @click="initialize">Reset</v-btn>
        </template>
      </v-data-table>
    </v-card>

Css before page reload, after the code is edited in Webstorm and automatically compiled:

before

And after the reload:

after

And if I just remove the first row, the same happens no matter which one is first.

like image 765
user2993349 Avatar asked May 11 '18 10:05

user2993349


Video Answer


1 Answers

I had the same problem.

They problem here is that You override the items slot including <tr> tag. Without that everything will work fine. But for me, that was not a solution so if You want to override the <tr> tag also, add :key to it, like this: <tr :key="props.index">. Take a look at source of v-data-table here. To be honest, i don't know why it make that big difference but in my case that resolved the problem (i suspect that it is connected with vue list rendering).

Hope it helps!

like image 181
Zbigniew Hadrian Avatar answered Sep 18 '22 15:09

Zbigniew Hadrian