How to scroll through one or more table html and your table html daughters?

Asked

Viewed 27 times

0

How to go through all the tables and their daughter tables, because I need to make a sum of the columns "Value"? Tables are created dynamically according to the return of the Ajax function. I can have 1 or more tables "father" and for each table "father" I can have one or more tables "Daughters".

I know that walking through a table could do so:

$("#btnSavar").on("click", function(){
    $('#tblEmpresa> tbody  > tr').each(function() { 
       var linha = $(this);
    });
});

But I must go all the tables and their daughter tables from a single button event, but don’t know how to scroll through these daughter tables:

Table:

<div id="divPrincipal>
    <div class="ibox float-e-margins">
        <div class="ibox-title">Empresa A</div>
        <div class="ibox-content" id="acordion">
            <table id=tblEmpresa data-IdTblEmpresa=1>
                <thead><th>Nome</th><th>Endereco</th><th>Telefone</th><th>Valor Empresa</th></thead>
                <tbody>
                    <tr>
                        <td></td>
                        <td></td>
                        <td></td>
                        <td>R$ 3000,00</td>
                    </tr>
                    <tr>
                        <td colspan=3>
                            <table id=tblProduto data-IdTblProduto=43>
                                <thead><th>Nome</th><th>Tipo</th><th>Valor Produto</th></thead>
                                <tbody>
                                    <tr>
                                        <td></td>
                                        <td></td>
                                        <td>R$ 17,00</td>
                                    </tr>
                                    <tr>
                                        <td></td>
                                        <td></td>
                                        <td>R$ 86,00</td>
                                    </tr>
                                    <tr>
                                        <td></td>
                                        <td></td>
                                        <td>R$ 71,00</td>
                                    </tr>
                            </table>
                        </td>
                    </tr>
            </table>
        </div>
    </div>  
    
    <div class="ibox float-e-margins">
        <div class="ibox-title">Empresa B</div>
        <div class="ibox-content" id="acordion">
            <table id=tblEmpresa data-IdTblEmpresa=2>
                <thead><th>Nome</th><th>Endereco</th><th>Telefone</th><th>Valor Empresa</th></thead>
                <tbody>
                    <tr>
                        <td></td>
                        <td></td>
                        <td></td>
                        <td>R$ 500,00</td>
                    </tr>
                    <tr>
                        <td colspan=3>
                            <table id=tblProduto data-IdTblProduto=21>
                                <thead><th>Nome</th><th>Tipo</th><th>Valor Produto</th></thead>
                                <tbody>
                                    <tr>
                                        <td></td>
                                        <td></td>
                                        <td>R$ 20,99</td>
                                    </tr>
                            </table>
                        </td>
                    </tr>
            </table>
        </div>
    </div>
    
    <div class="ibox float-e-margins">
        <div class="ibox-title">Empresa C</div>
        <div class="ibox-content" id="acordion">
            <table id=tblEmpresa data-IdTblEmpresa=3>
                <thead><th>Nome</th><th>Endereco</th><th>Telefone</th><th>Valor Empresa</th></thead>
                <tbody>
                    <tr>
                        <td></td>
                        <td></td>
                        <td></td>
                        <td>R$ 250,00</td>
                    </tr>
                    <tr>
                        <td colspan=3>
                            <table id=tblProduto data-IdTblProduto=35>
                                <thead><th>Nome</th><th>Tipo</th><th>Valor Produto</th></thead>
                                <tbody>
                                    <tr>
                                        <td></td>
                                        <td></td>
                                        <td>R$ 54,90</td>
                                    </tr>
                                    <tr>
                                        <td></td>
                                        <td></td>
                                        <td>R$ 38,00</td>
                                    </tr>
                            </table>
                        </td>
                    </tr>
            </table>
        </div>
    </div>
<div>
  • 1

    You want to take all the values ? And add?

  • 1

    if the <table> daughters tag have a reference (class, id, etc) you can go through them using forEach() or counting them with a bow for there from the Index face <table> daughter you can get the values (I suggest you add them in an Array) and at the end of the loop add all!

  • @novic want to take the total value of each table, Total value of table1 Father, then take the Value of Table1 Daughter, take Total Value of table2 and so on.

  • Do you receive a JSON? because I saw you say AJAX, if yes sum by it is ideal

  • yes @novic get a JSON, could make the sum at the time of loading the screen, but this is not enough because the user can remove or add new items so I need to go through the tables whenever the user clicks the btnSalvar button.

  • You don’t only need to do it on loading, if it adds dynamic values add a variable value to show on the screen! because even it adding you will have to update the value

Show 1 more comment
No answers

Browser other questions tagged

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