1
Good afternoon. I have a table that I carry some equipment in HTML. I would like to reload it when deleting a device from the table. I have the following function in my Javascript page. This function is in the onClick event of the delete button.
function reloadNovoEquipamentoTable(){
var element = document.getElementById('listNovoEquipamentosOrcamento');
element.reload();}
How to re-load this table?
Ajax
function removeNovoEquipamento(equipamentoID, orcamentoID) {
$.ajax({
url: "actions/removeNovoEquipamento",
method: "POST",
data: "equipamentoID=" + equipamentoID + "&orcamentoID=" + orcamentoID,
success: function (response) {
alert('excluido com sucesso');
},
error: function (response) {
alert(response);
}
});
}
Below is the table to list:
<table class="table table-striped table-condensed margin-top" id="listNovoEquipamentosOrcamento">
<thead>
<tr>
<button type="button" class="btn btn-primary btn-modal" data-target="#modalNovoEquipamento" data-toggle="modal"><span class="glyphicon glyphicon-wrench"></span> Novo Equipamento</button>
<th colspan="10" style="text-align: center"><h3>Lista de Novos Equipamentos</h3></th>
</tr>
<tr>
<th>Item</th>
<th>Qtd.</th>
<th>Descrição</th>
<th id="td-acoes">Ações</th>
</tr>
</thead>
<tbody id="tbody-novoEquipamento">
<c:forEach items="${orcamento.listNovoEquipamentosOrcamento}" var="equipNovoOrcamento" varStatus="i">
<tr>
<td>
${fn:length(orcamento.listEquipamentosOrcamento)+ i.index+1}
<input type="hidden" required="true" name="equipamentoNovoID" value="${equipNovoOrcamento.id}"/>
</td>
<td><input id="qtd_${fn:length(orcamento.listEquipamentosOrcamento)+ i.index}" type="number" class="form-control" onchange="validaQuantidade(this);" value="${equipNovoOrcamento.quantidade}" placeholder="Qtd" min="1" required="true" name="quantidade"/></td>
<td><input type="text" name="descricao" class="form-control" value="${equipNovoOrcamento.descricao}" readonly="true" /></td>
<td><button type="button" onclick='removeNovoEquipamento(${equipNovoOrcamento.id},${orcamento.id});reloadNovoEquipamentoTable();' class="btn btn-danger btn-sm"><span class="glyphicon glyphicon-trash"></span></button></td>
</tr>
</c:forEach>
<tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td id='total' colspan='2'></td><td></td></tr>
</tbody>
</table>
How do you delete ? By Ajax ?
– Diego Souza
Yes. I delete via Ajax.
– Raphael Prado de Oliveira
So instead of re-loading the table why not delete the row ?
– Diego Souza
How can I do that ?
– Raphael Prado de Oliveira
Edit your question and post ajax code.
– Diego Souza
What do you use to list ? A table ?
– Diego Souza
Use <table></table>
– Raphael Prado de Oliveira
Edit your question and put a bit of the table...
– Diego Souza
The HTML, Bro....
– Diego Souza