0

i have made a calendar in momentjs and would like to color e.g the weekends differently.

The dates and days are rendered in a v-for like so:

<tr v-for="(day, index) in days" :key="index" class="grid-container">
    <td class="grid-item">{{ day.date.format("Do") }}</td>
    <td class="grid-item">{{ day.date.format("dddd") }}</td>
    <td class="grid-item">{{ day.workhours }}</td>
    <td class="grid-item">{{ day.overtime }}</td>
    <td class="grid-item">{{ day.flextime}}</td>
    <td class="grid-item">{{ day.sickness}}</td>
    <td class="grid-item">{{ day.vacation}}</td>
   </tr>

is it possible to change e.g the background color of all of these td's if

day.date == "Saturday"

2 Answers 2

5

You can use class binding

update: I missed the name of the day, I added what Jose Fernández suggested

template:

<tr
  v-for="(day, index) in days"
  :key="index"
  v-bind:class="{ active: day.format('dddd') == 'Saturday' }"
  class="grid-container"
>
  ...
</tr>

style:

<style scoped lang="scss">
.active {
  background-color: green;
}
</style>
Sign up to request clarification or add additional context in comments.

2 Comments

I would have thought so too, but when i add that and look in the developer tools, the class is not added to the <tr> elements that contains Saturday. Can it have something to do with the day.date not having been formatted yet?
ty it works now, just needed to reset my eyes and implement your solution accordingly
1

I think what Chris replied is the finest solution. Although I think what you want to check is:

day.date.format("dddd") == 'Saturday'

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.