3
I have a table where I list the amount of items in an order. And in each row I have a number of 01
to 15
sequential where identifies the amount of items.
The problem is that when I delete an item, the interesting thing was that the numbers that identify each row update automatically and get random. Do you understand? Note: The list is made in table.
<table id="table_itens" class="table table-striped">
<thead>
<tbody>
<tr id="exc_01">
<td>01</td><!-- Estes números que eu quero atualizar dinamicamente -->
</tr>
<tr id="exc_02">
<td>02</td><!-- Estes números que eu quero atualizar dinamicamente -->
</tr>
<tr id="exc_03">
<td>03</td><!-- Estes números que eu quero atualizar dinamicamente -->
</tr>
</tbody>
</table>
Javascript code:
<script type="text/javascript" language="javascript">
function adicionaItemPedido(){
var contador = (cont < 10) ? '0'+ cont++ : cont++;
$("#table_itens").append(
'<tr id="exc_'+ contador +'">\n\
<td><b>'+ contador +'</b></td>\n\
<td>'+ referencia_estofado[0] +'</td>\n\
<td><input type="hidden" class="id_est_revest_aux" value="'+ $("#revestimento_aux").val() +'" />'+ revestimento[0] +'</td>\n\
<td><input type="hidden" class="id_padrao_aux" value="'+ $("#cod_padrao option:selected").val() +'" />'+ $("#cod_padrao option:selected").text() +'</td>\n\
<td>'+ (($("#revestimento_aux_2").val() === 'undefined') ? "-" : $("#revestimento_aux_2").val()) +'</td>\n\
<td>'+ (($("#cod_padrao_2").val() === 'undefined') ? "-" : $("#cod_padrao_2").val()) +'</td>\n\
<td>'+ referencia_estofado[1] +'</td>\n\
<td>'+ $("#quantidade").val() +'</td>\n\
<td>'+ $("#valor_unitario").val() +'</td>\n\
<td>'+ $("#desconto_acrescimo").val() +'</td>\n\
<td>'+ $("#valor_total").val() +'</td>\n\
<td><button type="button" class="btn btn-danger btn-xs btnRemover"><i class="glyphicon glyphicon-remove" ></i> Remover</button></td>\n\
</tr>');
}
</script>
What do you mean "get random"? If you had
1, 2, 3, 4
and removed the2
, it’s supposed to stay1, 2, 3
(the3
turn2
and the4
turn3
) or is it something else?– mgibsonbr
Hello @mgibsonbr is exactly that. Do you have any idea how to do this?
– Bruno Duarte
I avoidance do this, preferring to mark the deleted items with a
<del></del>
(i.e. showing them cut) and keeping the numbering, to simplify. But if that’s what you want, I know how to do yes, just a moment...– mgibsonbr