Reload DataTable content

0

I have a DataTable that I fill with a PHP that makes a query and I want to make only the table recharge:

<div class="card-body">
                        <table id='ejemplo1' class='table table-bordered table-striped'>
                            <?php
                            $conexion=mysqli_connect("localhost", "root", "", "pruebas_maps") or die ("Problemas con la conexion");
                            $consulta="SELECT * FROM registros2 where estado = 'pendiente'";
                            $registros=mysqli_query($conexion,$consulta) or die ("Problemas con la consulta");
                            echo "<thead>
                                    <tr>
                                        <th>Hora de entrega</th>
                                        <th>Cliente</th>
                                        <th>Dirección de obra</th>
                                        <th>Fecha de entrega</th>
                                        <th>Resistencia</th>
                                        <th>M3</th>
                                        <th style='display:none;'>M3</th>
                                        <th style='display:none;'>M3</th>
                                        <th style='display:none;'>M3</th>
                                        <th style='display:none;'>M3</th>
                                        <th style='display:none;'>M3</th>
                                        <th style='display:none;'>M3</th>
                                        <th style='display:none;'>M3</th>
                                        <th style='display:none;'>M3</th>
                                        <th style='display:none;'>M3</th>
                                        <th style='display:none;'>M3</th>
                                        <th>Acciones</th>
                                    </tr>
                                </thead>
                                <tbody>";
                            while ($reg=mysqli_fetch_array($registros))
                            {
                                $folio = $reg['id'];
                                //echo "editar_direccion.php?id=".$folio."&page=".$page."\"";
                                echo "<tr id='head$folio' data-toggle='modal' data-id='$folio' data-target='#orderModal'>
                                        <td>".$reg['hora']."</td>
                                        <td>".$reg['cliente']."</td>
                                        <td>".$reg['dir_obra']."<br/>".$reg['indicaciones']."</td>
                                        <td>".$reg['fecha_entrega']."</td>
                                        <td>".$reg['resistencia']." </td>
                                        <td>".$reg['m3']." </td>
                                        <td id='folio' style='display:none;'>".$reg['id']." </td>
                                        <td style='display:none;'>".$reg['metodo_pago']." </td>
                                        <td style='display:none;'>".$reg['fecha_registro']." </td>
                                        <td style='display:none;'>".$reg['pu']." </td>
                                        <td style='display:none;'>".$reg['tiro']." </td>
                                        <td style='display:none;'>".$reg['ton']." </td>
                                        <td style='display:none;'>".$reg['elem_colar']." </td>
                                        <td style='display:none;'>".$reg['revenimiento']." </td>
                                        <td style='display:none;'>".$reg['adicionales']." </td>
                                        <td style='display:none;'>".$reg['padd']." </td>
                                        <td>        
                                            <button class='btn btn-danger btn-sm btnBorrar' aria-label='Left Align' value='$folio'>Borrar</button>
                                            <button class='btn btn-warning btn-sm btnCancelado' aria-label='Left Align' value='$folio'>Cancelar</button><br/><br/>
                                            <button class='btn btn-primary btn-sm btnEditar' aria-label='Left Align' onclick='location.href=\"editar_direccion.php?id=".$folio."&page=".$page."\";'> Editar</button>
                                            <button class='btn btn-success btn-sm btnEntregado' aria-label='Left Align' value='$folio'>Entregado</button>
                                        </td>
                                    </tr>";
                            }
                            mysqli_close($conexion);
                            echo "</tbody>
                                    <tfoot>
                                        <tr>
                                            <th>Hora de entrega</th>
                                            <th>Cliente</th>
                                            <th>Dirección de obra</th>
                                            <th>Fecha de entrega</th>
                                            <th>Resistencia</th>
                                            <th>M3</th>
                                            <th style='display:none;'>M3</th>
                                            <th style='display:none;'>M3</th>
                                            <th style='display:none;'>M3</th>
                                            <th style='display:none;'>M3</th>
                                            <th style='display:none;'>M3</th>
                                            <th style='display:none;'>M3</th>
                                            <th style='display:none;'>M3</th>
                                            <th style='display:none;'>M3</th>
                                            <th style='display:none;'>M3</th>
                                            <th style='display:none;'>M3</th>
                                            <th style='display:none;'>M3</th>
                                            <th>Acciones</th>
                                        </tr>
                                    </tfoot>";
                            ?>
                        </table>
                    </div>

Try to do it with this JS but just duplicate the table and do not let me use the controls:

function refresh_div() {
    jQuery.ajax({
        url:'registros.php',
        type:'POST',
        success:function(results) {
            jQuery(".card-body").html(results);
        }
    });
}

t = setInterval(refresh_div,1000);
    
asked by Carlos Roberto Luna Ochoa 31.05.2018 в 19:16
source

1 answer

0

Maybe the information is duplicated because you need to clean the table before refilling and use the refresh_div function.

Try adding this code snippet:

var table = $('#ejemplo1').DataTable();
table.clear().draw();
    
answered by 31.05.2018 в 19:43