Changing TD Data from a Table

Asked

Viewed 24 times

0

Hello. I have a table where td has an ID with the Cod of a product, for example: inserir a descrição da imagem aqui

How can I get this ID and change the info without updating the page?

I’m using Ajax to do the database searches, and I have a button called Edit, where you will edit the clicked line, the idea is that when you save the edit, change only the line that was edited without the need to update the td table, so I created this ID on tr to have an easier way to edit the line.

someone could help me.

Ajax Edit:

$('#EditarPro').click(function() {

            var ECod = $("#ECodigo").val();
            var Edesc = $("#EDesc").val();
            var Eqtd = $("#EQtd").val();
            var Evalor = $("#EValor").val();

            $.ajax({
                method: "POST",
                url: "editar.php",
                data: {
                    cod: ECod,
                    desc: Edesc,
                    qtn: Eqtd,
                    valor: Evalor
                }
            }).done(function(resposta) {
                // alert(resposta);
                // GerarTabela();
                if (resposta == '"Cadastro Com Sucesso!"') {
                    MudaLinha(Ecod);
                    $("#FecharModal").trigger('click');
                } else {
                    alert('falha ao Cadastrar');
                }
            }).fail(function() {
                $(".FecharModal").trigger('click');
                alert('falha ao Cadastrar');
                GerarTabela();
            });
        });

Function Mudalinha()

function MudaLinha(cod) {
            $.ajax({
                method: "POST",
                url: "Select.php",
                data: {
                    cod: cod,
                }
            }).done(function(resposta) {
                resposta = JSON.parse(resposta);

            }).fail(function() {
                console.log('falha ao Procurar');
            });
        }

  • I don’t know if you’ve searched, but there are jQuery plugins that do this previously

  • That’s why I’m here, because I looked and I couldn’t find

  • "How can I take this ID and change the Information" $('#tr27').html('aqui vai o conteúdo que quer mudar'). And you said you looked and didn’t find, you came to see the datatables? Do what you need, pass data and it assembles the values in table

  • Sure the datatables I know but I can’t use it here not yet

  • So you already found, "just can’t" use one of them... There is a pence of these plugins: https://www.jqueryscript.net/tags.php?/In-place%20Editing/

  • But since frameworks have emerged as angular, React, Vue,. knockout, etc and etc, I find that edit the gift for these cases well démodé...

  • "Easy" way to solve: for each TR you created, create 2 - one as you did and the other with the update form, the Edit button makes this other TR display, when submitting the form, wait for the successful response, in case of success, update the data TR. To know what/how to update vc can create an attribute in the inputs with the name of the TD that should be updated - eg: data-updateelement=<id of the TD to be updated>

  • If you want a concrete answer based on that say and I try to elaborate more to take a possible doubt.

  • It would be simpler to use the load: https://www.w3schools.com/jquery/jquery_ajax_load.asp

Show 4 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.