Remove multiple rows from table when changing state

Asked

Viewed 45 times

0

When changing the state of the table rows, I intend that users do not see them. In this case I change the state in several rows at the same time. So by changing the state of the rows, I want to remove them from the table.

I’m doing it this way:

function inserir_registo()
{    
var Ids = [];
$("input[name^='teste1']").each(function() {Ids.push(this.value)});

var EstadoFinals = [];
$("select[name^='EstadoFinal1']").each(function() {EstadoFinals.push($(this).val())});

var dadosajax = {
 'Id[]' : Ids,
 'EstadoFinal[]' : EstadoFinals
};
$.ajax({
    url: './encomendaaprovada',
    type: 'POST',
    cache: false,
    data: dadosajax,
    error: function(){
      $(".error_message").removeClass('hide');
    },
    success: function(result)
    { 
    for( var i = 0; i < Ids.length; i++){ 
      if(dadosajax.EstadoFinal != '2'){
      Ids.remove();
    } 
   }
  }
});
}

The code I’m using to remove from the above function:

var Ids = [];
$("input[name^='teste1']").each(function() {Ids.push(this.value)});

success: function(result)
{
  for( var i = 0; i < Ids.length; i++){ 
  if(dadosajax.EstadoFinal != '2'){
  Ids.remove();
  } 
}

Return this error and do not remove lines:

?preview_id=2501&preview_nonce=dd04e65715&preview=true:784 Uncaught Typeerror: Ids.remove is not a Function at Object.Success (?preview_id=2501&preview_nonce=dd04e65715&preview=true:784) at i (jquery.min.js:2) at Object.fireWith [as resolveWith] (jquery.min.js:2) at A (jquery.min.js:4) at Xmlhttprequest.

Table:

<table class="table table-responsive" id="employee_ta">
<thead>
<tr>
<th style="display:none">Id</th>
<th>Data Encomenda</th>
<th>Tipo de Produto</th>
<th>Produto</th>
<th>Quantidade</th>
<th>Requerente</th>
<th>Destino</th>
<th>Observacoes</th>
<th>Última Aprovação</th>
<th>Último Preço</th>
<th>Estado</th>
</tr>
</thead>
<tbody>
<tr id="<?php echo $produto["Id"]; ?>">
<td style="display:none"><input type="text" rows="4" name="teste1[]" id="teste1" value="<?php echo $produto["Id"]; ?>"></td>
<td><?php echo $produto["Data"]; ?></td>
<td><?php echo $produto["Identificacao"]; ?></td>
<td><?php echo $produto["Produto"]; ?></td>
<td><?php echo $produto["Quantidade"]; ?></td>
<td><?php echo $produto["Requerente"]; ?></td>
<td><?php echo $produto["Destino"]; ?></td>
<td><?php echo $produto["Observacoes"]; ?></td>
<td><?php echo $ln1['DataAprovacao']; ?></td>
<td><?php echo $ln2['Preco']; ?> €</td>
<td><?php echo $produto["Estado"]; ?></td>          
</tr> 
</tbody>  
</table>

1 answer

1


Do it this way to remove a specific item from a array:

  for( var i = 0; i < Ids.length; i++){ 
  if(dadosajax.EstadoFinal != '2'){
   Ids.splice($.inArray(Ids[i], Ids), 1);
   $('tr[id="'+ Ids[i] +'"]').remove();
  }
}

More information: .splice() .remove()

  • does not return any error, but also does not remove the table rows.

  • Ai it will remove items from your array, if you want to remove items from the table you have to post your HTML code from the table to mount a selector

  • I added html from my table

  • Modified answer @Bruno

  • is exactly what I want. There is only one problem, for example in the table there are 4 lines, change the state to 4 lines but only remove two.

  • You can debug the code and go printing on the console to adapt the code to your need.

Show 1 more comment

Browser other questions tagged

You are not signed in. Login or sign up in order to post.