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/
– Miguel
so I already tried this one, I put the "Processing": true, "serverside": true, the Processing does not work and the server gives error!
– JASL
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
– Miguel
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!
– JASL
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
– Miguel
would that be? https://postimg.org/image/frh6ouvbz/
– JASL
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
– Miguel
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/
– JASL
It’s not index.php... It’s the last one below, "index.php? draw=..."
– Miguel
then load all 9000 and the html and table appear with all these... https://postimg.org/image/xrla24shjrecords/
– JASL
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
– Miguel
Let’s go continue this discussion in chat.
– JASL