I'm trying to make it possible to send a row from a modal with a table to another table.
Here is what I have advanced. https://jsfiddle.net/eddyzezb/
However, although it sends the row to another table, it does not return to its original table when it is deleted. And I would like to know what I need to do it.
Thanks in advance.
JS Jquery 2.1.0:
$('table>tbody>tr>td>.a').one('click',function(){
$(".othertable").append("<tr><td>"+
$(this).closest('tr').children()[0].textContent+"</td><td><input type='text' placeholder='Ingresar cantidad'/></td><td>"+
$(this).closest('tr').children()[1].textContent+"</td><td><input type='button' class='btneli' value='Eliminar'></td></tr>");
$(this).parent().parent().remove();
$('tr .btneli').one('click',function(){
$('.btneli').parent().remove();
});
});
HTML:
<div class="row">
<div class="col-xs-12 col-md-12">
<table class="table table-condensed table-hover table-bordered">
<thead>
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Accion</th>
</tr>
</thead>
<tbody>
<tr>
<td>John</td>
<td>Doe</td>
<td><button class="a">Aqui</button></td>
</tr>
<tr>
<td>Sam</td>
<td>Smith</td>
<td><button class="a">Aqui</button></td>
</tr>
</tbody>
</table>
</div>
</div>
<table class="othertable table-condensed table-hover table-bordered">
<thead>
<tr>
<th>Firstname</th>
<th>Precio</th>
<th>Lastname</th>
<th>Accion</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
In response to your question I have made some changes to your code, basically it would look like this:
First we're going to slightly change the way you're thinking about your code, instead of removing the button row here we're just going to hide it. that is, we comment the line;
$(this).parent().parent().remove();
and we addvar tr = $(this).closest("tr");
. In the end you should have something like this:and then we add the code that I leave below in the button with the class; .btneli
In the same way I leave you the Snippet.
Update by comment follow-up.
Well, I'm going to leave you a code that I made based on the particular need. It should be noted that there were many things that I did not work with Jquery, I did them in Native JS, this is because of the ease that native JS has.