1
I have a table, which I enclose the data dynamically in a table. I include in this way, I include in the first column the checkbox:
$("#tablepesquisaprodutos").append("<tr class='item'>"
+ "<td>" + "<input type='checkbox' class='link-check' />" + "</td>"
+ "<td>" + CodigoProduto + "</td>"
+ "<td>" + DescricaoProduto + "</td>"
+ "</tr>")
It works perfectly, but I need that when checking the checkbox, I can delete or edit the line (opening a modal with the line data), how can I do? Delete I can by a button, I do it that way:
$(function () {
$(document).on('click', '.link-excluir', function (e) {
e.preventDefault(); // isso aqui impede do '#' fazer o link pular
var $el = $(this);
$el.closest("tr").fadeOut(500, function () {
$el.remove();
})
})
})
Only in case I have the link to delete on the line, I need to select the line, and then click the action button, or delete or change.
$(".link-check").change();
is not good for you? Inside just check if it is checked or not and make appear/ disappear– Máttheus Spoo
If you want to open a fashion, there are several examples here on the site, like this: how to open jquery modal, or that: edit fields in modal. Now an easier way and make the
TD
editable, just change your code to+ "<td contenteditable='true'>" +
and it will be possible to edit the direct value inTD
, what you think?– Ricardo Pontual
@Máttheusspoo I wanted that when selecting it click on the button or to change or to delete, I think that with the change would not work.
– Mariana
@Ricardopunctual the idea is good, however I need q it select to then click the delete or change button
– Mariana
In this case, you can add the attribute
contenteditable='true'
by clicking the change button or checking the checkbox, and the eventblur
ofTD
remove the attribute :)– Ricardo Pontual
@Ricardopunctual but I didn’t understand how to do it. I will select the checkbox of the row I want to delete or change, how can I take the value of this row, and when clicking the delete button, and the change button, open the modal with the data.
– Mariana
But you want to edit directly in the table as I suggested or you want to open the modal?
– Ricardo Pontual
I want to edit by opening the modal. I already do this with a link in each row, but instead of having the link, I want to have the checkbox, select, and then yes, I click a button from outside the table to perform desired action
– Mariana
@Ricardopunctual I managed to delete, now as I can by clicking on the checkbox, and clicking on the edit button, open the modal with table information ?
– Mariana