How to update a Datatable without Reload the page?

Asked

Viewed 147 times

1

I have a DataTable(plugin) generated from an Array that will mount an onlines user list. And mounts to paging.

But the AJAX that returns the list is of type GET and keeps updating the page to check if any ID has logged in and so updates the list, and for that I am using the setTimeOut.

My problem is:

When I am looking for some ID using paging, GET is carried out and so updates the page and back to the first page.

My doubt:

Is there any way to update this Array as GET without updating the page by going back to first page ?

Codes:

 //Função que atualiza a DataTable dos operadores
        function preencheTabelaOperadores() {
            console.log("Preenche Tabela Operadores");
            $.ajax({
                async: false,
                type: 'GET',
                url: '@Url.Action("GetQtdeSinaisPorOperador")',
                success: function (data) {

                    var tabelaOperadores = $('#dataTableOperadores').dataTable({
                        destroy: true,
                        bProcessing: true,
                        data: data,
                        columns: [
                                    { "data": "dsUserName" },
                                    { "data": "nmQtdeSinais" },
                                    { "data": "nmQtdeSinaisPrio1" },
                                    { "data": "nmQtdeSinaisPrio2" },
                                    { "data": "nmQtdeSinaisPrio3" },
                                    {
                                        "data": "nmBloqueado",
                                         "render": function (data, type, row) {
                                             var img

                                             if (data == 3) {
                                                 img = "<center><i class='fa fa-times-circle' style='color:orange; font-size:30px'></i></center>"
                                             } else if (data == 2){
                                                 img = "<center><i class='fa fa-times-circle' style='color:red; font-size:30px'></i></center>"
                                             } else {
                                                 img = "<center><i class='fa fa-check-circle' style='color:green; font-size:30px'></i></center>"
                                             }

                                             return img
                                        }
                                    },
                                    {
                                        "data": "idUsuario",
                                        "render": function (data, type, row) {
                                            var btn
                                            btn = "<button type='button' data-backdrop='false' data-item-description="+row.dsUserName+" class='btn bg-red-active deslogar' data-item-id=" + data + "  data-toggle='modal' data-target='#modalCertezaDeslogarUsuario' ><i class='fa fa-sign-out'></i> Deslogar </button>"
                                            return btn
                                        }
                            },
                            {
                                "data": "idUsuario",
                                "render": function (data, type, row1) {
                                    var btn1
                                    btn1 = "<button type='button' data-backdrop='false' data-item-description=" + row1.dsUserName + " class='btn bg-blue-active bloquear' data-item-id=" + data + " data-toggle='modal' data-target='#modalCertezaBloquearUsuario' ><i class='fa fa-sign-out'></i> Bloquear Evento</button>"
                                    return btn1
                                }
                            }

                        ],
                        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"
                            }
                        }
                    });
                    data = null;
                }
            });
           setTimeout(preencheTabelaOperadores, 15000);
        }
No answers

Browser other questions tagged

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