Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

138
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda