load records without expanding the table!

Asked

Viewed 214 times

0

good morning! with a difficulty of loading the records in a table without it expands, ex: I have a table with 9000 records, what happens is that when opening the page of the table it takes to load the records with that it extends showing all 9000 records, for after a while it decreases showing only 10 lines is clear so appearing the option of Next(paging) to see other records, wanted to know how to make it load the records faster and while this loading can even appear a loading message...!

the code is this:

index php.

<link href="../assets/css/datatables.min.css" rel="stylesheet" type="text/css">

<script type="text/javascript" src="../assets/js/jquery-1.11.3-jquery.min.js"></script>



 <table cellspacing="0" width="100%" id="example" class="table table-striped table-hover table-responsive">
    <thead>
    <tr>
    <th>Codigo</th>
    <th>Nome</th>
    <th>Sobrenome</th>
    </tr>
    </thead>
    <tbody>
    <?php
    require_once '../config/dbconfig.php';

    $stmt = $db_con->prepare("SELECT * FROM usuario ORDER BY idusuario DESC");
    $stmt->execute();
    while($row=$stmt->fetch(PDO::FETCH_ASSOC))
    {
        ?>
        <tr title="Edit" id="<?php echo $row['idusuario']; ?>" class="edit-link" onclick="#">
        <td><?php echo $row['idusuario']; ?></td>
        <td><?php echo $row['nomeusuario']; ?></td>
        <td><?php echo $row['sobreusuario']; ?></td>
        <!--<td align="center"><a id="<?php /*echo $row['emp_id'];*/ ?>" class="delete-link" href="#" title="Delete">
        <img src="delete.png" width="20px" />-->
        </a></td>
        </tr>
        <?php
    }
    ?>
    </tbody>
    </table>




<script src="../bootstrap/js/bootstrap.min.js"></script>
<script type="text/javascript" src="../assets/js/datatables.min.js"></script>
<script type="text/javascript" src="../assets/js/crudUsuario.js"></script>

<script type="text/javascript" charset="utf-8">
$(document).ready(function() {
    $('#example').DataTable({
    "bProcessing": true,    
    });

    $('#example')
    .removeClass( 'display' )
    .addClass('table table-bordered');
});
</script>

from now on, thank you!

  • You need this: https://datatables.net/examples/data_sources/server_side.html, https://datatables.net/examples/server_side/

  • so I already tried this one, I put the "Processing": true, "serverside": true, the Processing does not work and the server gives error!

  • You need to see what the server sends in response, if you have the errors enabled in php you can see what error is happening

  • the error is this when you put the serverside (datatables Warning table id=example - invalid json Response), I believe that because php is in index and not via ajax, so I don’t have that line either ("ajax": "../server_side/scripts/server_processing.php") why my php code is in the table itself as noted above!

  • This error is already given on the client side, and (I’m pretty sure) it comes from an error you have on the server side. You need to go to the network and see the response the server is sending: https://postimg.org/image/lyzsc2nz1/ , click on the right side of the service being called in your script js das datatables

  • would that be? https://postimg.org/image/frh6ouvbz/

  • No Jeferson, it’s your index.php?.... below, that’s where you see the server’s response to the request made for the datatable mount

  • face I am layman in this part of js and in some settings I do not use often, the console of this error (https://postimg.org/image/i9b9r18zn/) and the index.php loads tuydo at once and does not decrease the records but with that serverside! https://postimg.org/image/3ou6w7e0z/

  • It’s not index.php... It’s the last one below, "index.php? draw=..."

  • then load all 9000 and the html and table appear with all these... https://postimg.org/image/xrla24shjrecords/

  • That’s what’s wrong, there should be no html or anything, just a json sent by the server, take this example into account... https://datatables.net/examples/data_sources/server_side.html on the ajax tab and server side, follow you so... The server must send ONLY what is in the ajax tab, a json

Show 7 more comments
No answers

Browser other questions tagged

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