I have a table that opens in a popup to search for material from a material requisition register, on the page (other than the pop up) has another table that when I add a material that was selected in pop up it copies the information from the selected material in the popup table to the page table. The problem is that when I add a material for example: steel, it copies the data from the steel all ok, but if I do a new search, example: concrete, when I add the concrete, instead of doing the append it overwrites the steel, if I add two materials from the same search, there it append correctly.
//Pesquisa os materiais
function Pesquisar() {
$('.corpoTbl').remove();
$.ajax({
url: "/Sip/RCM/ListarMateriais",
type: "POST",
data: { nome: $('#Pesquisar').val() },
datatype: 'json',
success: function (data) {
$.each(data, function (I, item) {
$('#tbl').append("<tr class=\"corpoTbl\"> <td class=\"ids\">" + item.ID + "</td><td id=\"nome\">" + item.Nome + "</td><td id=\"unidade\"><center>" + item.Unidade +
"</center></td><td> <center><input class=\"qtda\" type=\"text\" value=\"0\" style=\"width: 50px;\" /></center> </td><td> <center><img class=\"icon-plus\" src=\"/Sip/Content/Imagens/add.png\" /></center> </td></tr>")
})
}
});
}
//adiciona o item na tabela de listagem
$('#telaMaterial').on('click', '.icon-plus', function (event) {
var $botao = $(event.target);
var $tr = $botao.closest('tr');
var $qtda = $tr.find('.qtda').val();
var $id = $tr.find('.ids').text();
if ($qtda > 0 && $qtda != "") {
$.ajax({
url: "/Sip/RCM/AddCarrinho",
type: "POST",
data: { "qtda": $qtda, "id": $id },
success: function (data) {
alert("Material Adicionado!");
$('#tabelaMaterial').append("<tr class=\"corpoTbl\"> <td class=\"idMat\">" + $id + "</td><td>" + $tr.find('#nome').text() + "</td><td><center>" + $tr.find('#unidade').text() +
"</center></td><td class=\"qtd\"><center>" + $qtda + "<center></td><td id=\"excluir\"> <center><img class=\"icon-remove\" src=\"/Sip/Content/Imagens/cancel.png\" /></center> </td></tr>")
}
})
}
})