Help call Rest and fill another table through Click

Asked

Viewed 25 times

0

Well I am in need of a help, I have a Datatable that is already working Ái when I click on a record I call a Rest and take the data and try to popular the other Datatable there that is the problem I have tried in several ways but never displays the data, Could somebody give me a hand? my code down as it is today.

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

        var apuracao = $('#indsApuracaos').val();
        var periodo = $('#txtPeriodo').val();
        var cpf = $('#txtCPF').val();
        var raizCNPJ = $('#empresaAgrupadora').val();

        tableEvtBasesTrab = $('#tableEvtBasesTrab').DataTable({
            "processing": true,
            "serverSide": true,
            "pageLength": 5,
            "searching":false,
            "destroy": true,
            "lengthMenu": [ [5], [5] ],
            "language": {
                "decimal":        "",
                "emptyTable":     "Sem dados disponíveis na tabela",
                "lengthMenu": "_MENU_ registros por página",
                "zeroRecords": "Nada Encontrado",
                "info": "Página _PAGE_ / _PAGES_",
                "infoEmpty": "Nenhum registro disponível",
                "infoFiltered": "(filtrado de _MAX_ registros totais)",
                "search": "Filtrar registros :",
                "loadingRecords": "Carregando...",
                "processing":     "Processamento...",
                "paginate": {
                    "first":      "Primeiro",
                    "last":       "Último",
                    "next":       "Próximo",
                    "previous":   "Anterior"
                },
                    "aria": {
                        "sortAscending":  ": Ativar para classificar coluna ascendente",
                        "sortDescending": ": Ativar para classificar coluna descendente"
                    }
                },
                "ajax": {
                    "url": "../rest/totalizadorS5001/busca",
                    parametros : [ 
                        {
                            name : 'apuracao',
                            value :  apuracao
                        },
                        {
                            name : 'periodo',
                            value :  $.utils.parseAnoMes($('#periodo').val())
                        },
                        {
                            name : 'cpf',
                            value :  cpf
                        },  
                        {
                            name : 'raizCNPJ',
                            value :  raizCNPJ
                        }
                    ],
                    "data": function ( data ) {
                    //
                    }
                },
                "columns": [
                { 
                    "width": "20%",
                    "data": null,
                    "render" : function (data, type, row) {
                        return data.atrIdEsoEve5001;
                    }
                },
                { 
                    "width": "20%",
                    "data": null,
                    "render" : function (data, type, row) {
                        return data.atrNrRecArqBase;
                    } 
                },  
                { 
                    "width": "20%",
                    "data": null,
                    "render" : function (data, type, row) {
                        return data.atrIndApuracao;
                    }
                },
                { 
                    "width": "20%",
                    "data": null,
                    "render" : function (data, type, row) {
                        return data.atrPerApur;
                    }
                },
                { 
                    "width": "20%",
                    "data": null,
                    "render" : function (data, type, row) {
                        return data.atrTpInsc;
                    }
                },
                { 
                    "width": "20%",
                    "data": null,
                    "render" : function (data, type, row) {
                        return data.atrNrInsc;
                    }
                },
                { 
                    "width": "20%",
                    "data": null,
                    "render" : function (data, type, row) {
                        return data.atrCpfTrab;
                    }
                },
                { 
                    "width": "20%",
                    "data": null,
                    "render" : function (data, type, row) {
                        return data.atrId;
                    }
                }
                ],
                drawCallback : function( settings ) {
                //
                },
                "order": [[ 0, 'asc' ]],
                "displayLength": 5
        });
    });

    $('#tableEvtBasesTrab tbody').on('click', 'tr', function () {

        var esoEvento5001 = tableEvtBasesTrab.row(this).data();
        var atrIdEsoEve5001 = esoEvento5001.atrIdEsoEve5001;

        var dataSetProcJudTrab = new Array();

        $.rest.get({
            servico : 'totalizadorS5001/buscaPorId',
            parametros : [ 
                {
                    name : 'atrIdEsoEve5001',
                    value : atrIdEsoEve5001
                }
            ],
            sucesso : function(data) {
                console.log(data);
                dataSetProcJudTrab = data.procJuds;
                console.log(dataSetProcJudTrab);
            }
        });

        var tableProcJudTrab = $('#tableProcJudTrab').DataTable({
            "processing": true,
            "serverSide": true,
            "pageLength": 5,
            "searching":false,
            "destroy": true,
            "data": dataSetProcJudTrab,
            "lengthMenu": [ [5], [5] ],
            "language": {
                "decimal":        "",
                "emptyTable":     "Sem dados disponíveis na tabela",
                "lengthMenu": "_MENU_ registros por página",
                "zeroRecords": "Nada Encontrado",
                "info": "Página _PAGE_ / _PAGES_",
                "infoEmpty": "Nenhum registro disponível",
                "infoFiltered": "(filtrado de _MAX_ registros totais)",
                "search": "Filtrar registros :",
                "loadingRecords": "Carregando...",
                "processing":     "Processamento...",
                "paginate": {
                    "first":      "Primeiro",
                    "last":       "Último",
                    "next":       "Próximo",
                    "previous":   "Anterior"
                },
                    "aria": {
                        "sortAscending":  ": Ativar para classificar coluna ascendente",
                        "sortDescending": ": Ativar para classificar coluna descendente"
                    }
                },
                "ajax": {
                    "data": function ( data ) {
                    //
                    }
                },
                "columns": [
                { 
                    "width": "20%",
                    "render" : function (data, type, row) {
                        console.log("Chegou Aqui");
                        console.log(data);
                        return data.atrNrProcJud;
                    }
                },
                { 
                    "width": "20%",
                    "render" : function (data, type, row) {
                        return data.atrCodSusp;
                    } 
                }
                ],
                drawCallback : function(settings) {
                //
                },
                "order": [[ 0, 'asc' ]],
                "displayLength": 5
        });
    });
});     

1 answer

0

The friendly idea as it is today is only popular when I click on the record line I will have to popular some more 5 different Datables yet, so I want to know how you do in one like this, for me to solve the rest, he is making a REST call in the code above, that returns a JSON already, I wanted to know how it is to get JSON and show in Datatable. The table I want to fill that is in the source code is tableProcJudTrab.

Browser other questions tagged

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