- I'm trying to color a row in a v-data-table based on the value of one of the fields in the table.
- I've tried all the solutions offered here and elsewhere, and experimented with a few more.
- I'm running the current version of Vuetify (2.3.9)
- I've reloaded everything, cleared browser cache and cookies, etc.
- I've tried with and without using slots.
- My application is wrapped in v-app
== without slots ==
<v-data-table
:items-per-page="50"
:headers="headers"
:items="jobs"
:height="600"
:search="search"
:hide-default-footer="true"
:item-key="jobs.JobID"
:item-class="row_class"
mobile-breakpoint="300"
no-data-text="No jobs today!"
dense
>
</v-data-table>
methods: {
row_class (item) { return "jobGreen" }
}
.jobGreen {
background-color: lightgreen;
}
Result:
- The class is not applied.
- Using item-class="jobGreen" (i.e. not reactive) also fails
- applying the jobGreen class to the v-data-table (i.e. class='jobGreen') works as expected
== using slot ==
(simplified)
<v-data-table>
<template v-slot:item="{item}">
<tr :class="row_class(item)">
<td>
{{ item.JobNumber }}
</td>
</tr>
</template>
</v-data-table>
methods: {
row_class (item) { return "jobGreen" }
}
OK, this works but the first row of the table never has a class applied! Sorting the table so that a different record is on top doesn't change things, so it's nothing to do with the data. The method is being called for each row of the table.