How to automatically reload a datable

How to automatically reload a datable

IndiraDev26IndiraDev26 Posts: 4Questions: 3Answers: 0
edited October 2018 in Free community support

How to automatically reload a datable every 10 seconds without pressing buttons, please

<script>
      $(document).ready(function(){
        $('#mitabla').DataTable({
          "order": [[1, "desc"]],
          "language":{
          "lengthMenu": "Mostrar _MENU_ Registros por página",
          "info": "Mostrando pagina _PAGE_ de _PAGES_",
            "infoEmpty": "No hay registros disponibles",
            "infoFiltered": "(filtrada de _MAX_ registros)",
            "loadingRecords": "Cargando...",
            "processing":     "Procesando...",
            "search": "Buscar:",
            "zeroRecords":    "No se encontraron registros coincidentes",
            "paginate": {
              "next":       "Siguiente",
              "previous":   "Anterior"
            },          
          },
            
        }); 
      });
      
      
    </script>

EDIT: Updated use Markdown code formatting.

Answers

  • kthorngrenkthorngren Posts: 20,141Questions: 26Answers: 4,736

    Doesn't look like you are loading the table data using Datatables. How you fetch and update the table is outside the scope of Datatables. You would use methods similar to how you initially load the table.

    However you will need to tell Datatables about the updated data. One way would be to use rows().invalidate() after you update the table.

    Kevin

  • IndiraDev26IndiraDev26 Posts: 4Questions: 3Answers: 0
    edited October 2018

    Es la primera vez que uso dataTables
    Encontré:

    Reload the table data every 30 seconds

    var table = $('#example').DataTable( {
    ajax: "data.json"
    } );

    setInterval( function () {
    table.ajax.reload( null, false ); // user paging is not reset on reload
    }, 30000 );

    Cómo aplicarlo a mi código

  • kthorngrenkthorngren Posts: 20,141Questions: 26Answers: 4,736

    How are you fetching the data now?

    The above could work but you would need to use ajax to have datatables get the data initially.

    Kevin

This discussion has been closed.