0

I am trying to highlight rows in a table if conditions are met; fine > 0 OR date due > date today

This code works fine but it is only for one(1) condition. If issue.fine > 0.

<tr v-for="issue in issues" :key="issue.id" :class="{'text-danger font-weight-bold': issue.fine > 0}">
   <td>{{ issue.firstname}} {{ issue.lastname}}</td>
   <td>{{ issue.datedue }}</td>
</tr>

I need to have two(2) conditions;
1. issue.fine > 0 OR 2. issue.datedue > the date today

I tried this but it does not work.

<tr v-for="issue in issues" :key="issue.id" :class="{'text-danger font-weight-bold': issue.fine > 0, issue.datedue > new Date()">
   <td>{{ issue.firstname}} {{ issue.lastname}}</td>
   <td>{{ issue.datedue }}</td>
</tr>

Please help. Thank you.

3 Answers 3

1

Use &&, not a comma.

issue.fine > 0 && issue.datedue > new Date()

The comma is syntactically fine, but behaviorally it returns the value of the final expression.

EDIT:

In response to your edit, the operator for OR is ||. See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Logical_Operators

Sign up to request clarification or add additional context in comments.

3 Comments

I think && works but the new Date() is causing an error.
It says "Issues detected. The new issues panel displays information about deprecations, breaking changes and other potential problems".
I am sorry I for my post, I mean one of the condition must be meant. Either #1 OR #2. Not #1 AND #2.
0

Multiple conditions which should be meta must be combined with an &&, not a comma.

<tr 
  v-for="issue in issues" 
  :key="issue.id" 
  :class="{'text-danger font-weight-bold': (issue.fine > 0 && issue.datedue && new Date())"
  >
  <td>{{ issue.firstname}} {{ issue.lastname}}</td>
  <td>{{ issue.datedue }}</td>
</tr>

2 Comments

I am sorry I for my post, I mean one of the condition must be meant. Either #1 OR #2. Not #1 AND #2. Thank you for your response. I tried your code but I can an error, "Issues detected. The new issues panel displays information about deprecations, breaking changes and other potential problems."
Oh in that case you should use || instead of &&
0

I would like to suggest to move this logic to a computed property just for better readability and remove the clutter from the HTML code.

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.