Error traversing table html with jquery

0
I have a HTML table and I need to get the values of value='1' data-chkIdProcessamentoDiario='1' data-chkIdRegistro='1' and assign in an array, but the problem is that each does not go through table html , although the browser log shows the opposite:

Boon:

<inputclass="btn btn-primary downloadPDF" value="Download PDF" type="button" id="BbtnDownloadPDF" />

Button event:

$(document).on('click', '.downloadPDF', function (e) {
                    e.preventDefault();    
                    var dados = [];
                    var i = 0;
                    var table = $('.grid > tbody');

                    table.find('tr').each(function () {

                        var _idprocessamentodiario = $('.chkProcessamentoDiario').data('chkidprocessamentodiario');
                        var _idregistro = $('.chkProcessamentoDiario').data('chkidregistro');
                        var _idservico = $('.download').data('idservico');

                        dados[i] = new Object();
                        dados[i]['IdProcessamentoDiario'] = _idprocessamentodiario;
                        dados[i]['IdRegistro'] = _idregistro;
                        dados[i]['IdServico'] = _idservico;
                        console.log(i + ' - _idprocessamentodiario: ' + dados[i].IdProcessamentoDiario + '| _idregistro: ' + dados[i].IdRegistro + '| idservico: ' + dados[i].IdServico);

                        i++;
                    });

                });

This is the HTML table:

<table class="grid">
    <thead>
        <tr class="header">
            <th scope="col">
            </th>
            <th scope="col">
<a href="/Documento?sort=EMPRESA&amp;sortdir=ASC">EMPRESA</a>            </th>
            <th scope="col">
<a href="/Documento?sort=CNPJ&amp;sortdir=ASC">CNPJ</a>            </th>
            <th scope="col">
<a href="/Documento?sort=CERT+CONJ+RFB%0d%0a&amp;sortdir=ASC">CERT CONJ RFB
</a>            </th>
            <th scope="col">
<a href="/Documento?sort=CERTIF+FGTS%0d%0a&amp;sortdir=ASC">CERTIF FGTS
</a>            </th>
            <th scope="col">
<a href="/Documento?sort=CND+D%c3%8dVIDA+ATIVA+DA+UNI%c3%83O&amp;sortdir=ASC">CND D&#205;VIDA ATIVA DA UNI&#195;O</a>            </th>
            <th scope="col">
<a href="/Documento?sort=CND+FGTS&amp;sortdir=ASC">CND FGTS</a>            </th>
            <th scope="col">
<a href="/Documento?sort=RECEITA+FEDERAL+PESSOA+JUR%c3%8dDICA+-+CNPJ&amp;sortdir=ASC">RECEITA FEDERAL PESSOA JUR&#205;DICA - CNPJ</a>            </th>
            <th scope="col">
<a href="/Documento?sort=TRIBUTOS+MOBILI%c3%81RIOS%0d%0a&amp;sortdir=ASC">TRIBUTOS MOBILI&#193;RIOS
</a>            </th>
</tr>
</thead>
<tbody>
    <tr>
        <td><input class='.checkbox-primary .checkbox-info chkProcessamentoDiario'  id='chkProcessamentoDiario' name='chkProcessamentoDiario' type='checkbox' value='1' data-chkIdProcessamentoDiario='1' data-chkIdRegistro='1'/></td>
        <td><div style='width:100%; height:100%; float:left;white-space:nowrap;'>ENERGIAS RENOVAVEIS S.A.</div></td>
        <td><div style='width:100%; height:100%; float:left;white-space:nowrap;'>08.439.659/0001-50</div></td>
        <td></td>
        <td></td>
        <td><a href='#'  class='download'  name='downloaditem' id='downloaditem1' data-IdProcessamentoDiario=1 data-IdRegistro=1  data-IdServico=1><span style='cursor:pointer'>CERTIDÃO POSITIVA</span></a></td>
        <td><a href='#'  class='download'  name='downloaditem' id='downloaditem2' data-IdProcessamentoDiario=1 data-IdRegistro=1  data-IdServico=2><span style='cursor:pointer'>Regular</span></a></td>
        <td><a href='#'  class='download'  name='downloaditem' id='downloaditem3' data-IdProcessamentoDiario=1 data-IdRegistro=1  data-IdServico=3><span style='cursor:pointer'>ATIVA</span></a></td>
        <td></td>
    </tr>
    <tr class="alt">
        <td><input class='.checkbox-primary .checkbox-info chkProcessamentoDiario'  id='chkProcessamentoDiario' name='chkProcessamentoDiario' type='checkbox' value='1' data-chkIdProcessamentoDiario='1' data-chkIdRegistro='2'/></td>
        <td><div style='width:100%; height:100%; float:left;white-space:nowrap;'>ENERGIAS RENOVAVEIS S.A. 2</div></td>
        <td><div style='width:100%; height:100%; float:left;white-space:nowrap;'>08.439.659/0002-31</div></td>
        <td></td>
        <td></td>
        <td><a href='#' class='download' name='downloaditem' id='downloaditem1' data-IdProcessamentoDiario=1 data-IdRegistro=2  data-IdServico=1><span  style='cursor:pointer'><font color='red'><b>A certidão deve ser emitida para o CNPJ da matriz ? 08.439.659/000150</b></font></span></a></td>
        <td><a href='#'  class='download'  name='downloaditem' id='downloaditem2' data-IdProcessamentoDiario=1 data-IdRegistro=2  data-IdServico=2><span style='cursor:pointer'>Regular</span></a></td>
        <td><a href='#' class='download' name='downloaditem' id='downloaditem3' data-IdProcessamentoDiario=1 data-IdRegistro=2  data-IdServico=3><span  style='cursor:pointer'><font color='red'><b>BAIXADA</b></font></span></a></td>
        <td></td>
    </tr>
    <tr>
        <td><input class='.checkbox-primary .checkbox-info chkProcessamentoDiario'  id='chkProcessamentoDiario' name='chkProcessamentoDiario' type='checkbox' value='1' data-chkIdProcessamentoDiario='1' data-chkIdRegistro='3'/></td>
        <td><div style='width:100%; height:100%; float:left;white-space:nowrap;'>EOL HOLDING S.A.</div></td>
        <td><div style='width:100%; height:100%; float:left;white-space:nowrap;'>11.594.952/0001-05</div></td>
        <td></td>
        <td></td>
        <td><a href='#'  class='download'  name='downloaditem' id='downloaditem1' data-IdProcessamentoDiario=1 data-IdRegistro=3  data-IdServico=1><span style='cursor:pointer'>CERTIDÃO NEGATIVA</span></a></td>
        <td></td>
        <td><a href='#'  class='download'  name='downloaditem' id='downloaditem3' data-IdProcessamentoDiario=1 data-IdRegistro=3  data-IdServico=3><span style='cursor:pointer'>ATIVA</span></a></td>
        <td></td>
    </tr>
</tbody>
</table>
    
asked by anonymous 31.05.2017 / 22:24

1 answer

1

Using this way $ ('.chkDriver') you will always get the first checkbox, you have to look for the checkbox inside the tr that is in the iteration. So:

table.find('tr').each(function (index, tr) {

                        var _idprocessamentodiario = $(tr).find('.chkProcessamentoDiario').data('chkidprocessamentodiario');
                        var _idregistro = $(tr).find('.chkProcessamentoDiario').data('chkidregistro');
                        var _idservico = $(tr).find('.download').data('idservico');

                        ...
});
    
31.05.2017 / 22:48