Error clicking Header to order Datatable.js

Asked

Viewed 42 times

0

I’m using the api Datatable.js and I’m going through the following problem: When I click on any coluna da table html to make the ordenação the entire content of the tag tbody remain only one line with the message: "No record found".

Html

<tbody><tr class="odd"><td valign="top" colspan="14" class="dataTables_empty">Nenhum registro encontrado</td></tr></tbody>

Javascript

function RelEstadoFilaAgente(url) {
        var model = MontarFiltro();

        $.ajax({
            url: url,
            type: "POST",
            data: JSON.stringify(model),
            contentType: "application/json; charset=utf-8",
            processData: false,
            cache: false,
            success: function (response) {
                if (!response.success) {
                    alertify.error("Erro ao gerar Relatório, favor tentar novamente");
                } else {

                    var html = "";

                    $.each(response.listar, function (index, item) {

                        html = html + "<tr>" +
                            "<td nowrap>" + item.STATUS + "</td>" +
                            "<td nowrap>" + item.QUANTIDADE + "</td>" +
                            "</tr>";
                    });

                    if (html.length > 0) {
                        var table1 = "";

                        if ($.fn.dataTable.isDataTable('#tblRelatorio')) {
                            table1 = $('#tblRelatorio').DataTable();
                            table1.destroy();

                            table1 = $('#tblRelatorio').DataTable({
                                dom: "lfrtip",
                                language: {
                                    "sEmptyTable": "Nenhum registro encontrado",
                                    "sInfo": "Mostrando de _START_ até _END_ de _TOTAL_ registros",
                                    "sInfoEmpty": "Mostrando 0 até 0 de 0 registros",
                                    "sInfoFiltered": "(Filtrados de _MAX_ registros)",
                                    "sInfoPostFix": "",
                                    "sInfoThousands": ".",
                                    "sLengthMenu": "_MENU_ resultados por página",
                                    "sLoadingRecords": "Carregando...",
                                    "sProcessing": "Processando...",
                                    "sZeroRecords": "Nenhum registro encontrado",
                                    "sSearch": "Pesquisar",
                                    "oPaginate": {
                                        "sNext": "Próximo",
                                        "sPrevious": "Anterior",
                                        "sFirst": "Primeiro",
                                        "sLast": "Último"
                                    },
                                    "oAria": {
                                        "sSortAscending": ": Ordenar colunas de forma ascendente",
                                        "sSortDescending": ": Ordenar colunas de forma descendente"
                                    }
                                }
                            });
                        } else {

                            table1 = $('#tblRelatorio').DataTable({
                                dom: "lfrtip",
                                language: {
                                    "sEmptyTable": "Nenhum registro encontrado",
                                    "sInfo": "Mostrando de _START_ até _END_ de _TOTAL_ registros",
                                    "sInfoEmpty": "Mostrando 0 até 0 de 0 registros",
                                    "sInfoFiltered": "(Filtrados de _MAX_ registros)",
                                    "sInfoPostFix": "",
                                    "sInfoThousands": ".",
                                    "sLengthMenu": "_MENU_ resultados por página",
                                    "sLoadingRecords": "Carregando...",
                                    "sProcessing": "Processando...",
                                    "sZeroRecords": "Nenhum registro encontrado",
                                    "sSearch": "Pesquisar",
                                    "oPaginate": {
                                        "sNext": "Próximo",
                                        "sPrevious": "Anterior",
                                        "sFirst": "Primeiro",
                                        "sLast": "Último"
                                    },
                                    "oAria": {
                                        "sSortAscending": ": Ordenar colunas de forma ascendente",
                                        "sSortDescending": ": Ordenar colunas de forma descendente"
                                    }
                                }
                            });
                        };
                    };

                    $("#tblRelatorio > tbody").html(html);
                    $("#DivRelatorio").css("display", "block");

                };

            },
            error: function (response) {
                alertify.error("Erro ao gerar Relatório, favor tentar novamente");
            }
        }).done(function (response) {
            alertify.success(response.message);
        });
    };
  • 1

    Looking at it from the top, it seems to me that you are repopulating the table after starting dataTables. I think this had to be before.

  • Okay! , @Sam I’ll run the tests and then I’ll get back to you ! Thanks !

  • Good morning ! @Sam your analysis was correct the table should-be populated before starting the dataTables, I ran the tests and is fixed !

  • Good morning! Nice that you solved it. Good luck!

No answers

Browser other questions tagged

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