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

435
Visualizações
Filter Table by column value VueJS Array

I wrote this function to filter by status type. It's working but every time I filter the table data rows get disappeared. There're two status ( Active and Completed ) I wrote this code for filter,

                    <div class="DropContent">
                        <label class="LabelView">Status</label><br />
                        <select class="dropdown-size form-control" v-model="ins_status" v-on:change="filterData">
                        <option v-for="(option, i) in optionFilter" :value="i">
                            {{ option }}
                        </option>
                        </select>
                    </div>

                   filterData(evt) {
                     var val = evt.target.value;
                     if(val==0){
                        this.inspections = this.inspections.filter(function(e){return e.status = "Scheduled"});
                     }if(val==1){
                        this.inspections = this.inspections.filter(function(e){return e.status != "Scheduled"});    
                     }
                  },

This is the array that load data to table from a for loop,

enter image description here

Also inside 0: Object There's another array which contains data like above objects from the screenshot enter image description here

So totally there're 3 rows for the table. Before calling filter function, all 3 rows are visible. but when I filter again and again it reduces the no of rows of the table. According to given data if I filter three times no table records are shown in the table. Help me thanks.

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

try to store this.inspections in a local variable and then filter that variable and store the result inside this.inspections.

filterData(evt) {
  var val = evt.target.value;
  var inspections = this.inspections; // save inspections in local variable
  if(val==0){
    this.inspections = inspections.filter(function(e){return e.status = "Scheduled"});
  } if(val==1){
    this.inspections = inspections.filter(function(e){return e.status != "Scheduled"});    
  }
}
about 4 years ago · Juan Pablo Isaza Relatório

0

The problem was I modified the existing array. So each time I filter it changes. which means it changes the original table data even I assign it to a local variable. So I passed an extra prop to my working component and assigned it to a local variable.

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