Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

136
Views
Filter by class in a Vue table, generated with v-for

I'm in Vue2 and I have a table, created by a v-for, with the rows that have a class of "included" or "allResults", based on a condition.

I need to show/hide only the table rows with a class of "included" when I trigger a switch (dataShow) that has a value of all or selected.

I've written a simple method for that but I would like to implement this function directly in the vue template, checking if every table row has a class of selected and hide it.

thanks in advance for help

<input v-model="dataShow" true-value="selected" false-value="all" type="checkbox" name="Show all or selected" />


<tbody>
  <tr v-for="(comparable, index) in sortedSelectedComparables" :class="watchedProperty.map(el => el.idorg).includes(comparable.idorg) ? 'included' : 'allResults'">
    <td>{{ Math.round(comparable.distance) + 'm'}}</td>
    <td>{{ comparable.address }}</td>
    <td>{{ comparable.startdate }}</td>
    <td>{{ comparable.usedetail_en }}</td>
  </tr>
</tbody>
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

How about using v-if or v-show to toggle the rows?

  • If dataShow is false, show all rows
  • or, if dataShow is true, show only the rows listed in watchedProperty
<tbody>
  <tr v-for="(comparable, index) in sortedSelectedComparables" v-if="!dataShow || watchedProperty.map(el => el.idorg).includes(comparable.idorg)">
    <td>{{ Math.round(comparable.distance) + 'm'}}</td>
    <td>{{ comparable.address }}</td>
    <td>{{ comparable.startdate }}</td>
    <td>{{ comparable.usedetail_en }}</td>
  </tr>
</tbody>

If you'd like to use class to toggle the visibility, you need to set css. Something like this...

<table :class="{'showAll': !dataShow}">
  <tbody>
    <tr v-for="(comparable, index) in sortedSelectedComparables" v-if="!dataShow || watchedProperty.map(el => el.idorg).includes(comparable.idorg)">
      <td>{{ Math.round(comparable.distance) + 'm'}}</td>
      <td>{{ comparable.address }}</td>
      <td>{{ comparable.startdate }}</td>
      <td>{{ comparable.usedetail_en }}</td>
    </tr>
  </tbody>
</table>
<style scoped lang="scss">
  table.showAll td:not(.included) {
    display: none;
  }
</style>
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!