why my datatable only show me the first 20 records
why my datatable only show me the first 20 records
raul.l.eminem
Posts: 6Questions: 1Answers: 0
i got a table wich have 256 records in a mysql table and is filled by a foreach function(i'm using cakephp framework). in my original code works perfectly but when i used this
this is my table
<table class="table table-striped table-bordered table-hover" id="sample_3" data-page-length="25">
<thead>
<tr>
<th scope="col"><?= $this->Paginator->sort('Usuario') ?></th>
<th scope="col"><?= $this->Paginator->sort('Acción') ?></th>
<th scope="col"><?= $this->Paginator->sort('Tabla') ?></th>
<th scope="col"><?= $this->Paginator->sort('Fecha') ?></th>
<!-- <th scope="col"><?= $this->Paginator->sort('Objeto') ?></th>-->
</tr>
</thead>
<tbody>
<?php foreach ($trazas as $traza): ?>
<tr>
<td><?= $traza->has('user') ? $traza->user->nombre_completo : '' ?></td>
<td><?= $traza->has('accione') ? $traza->accione->nombre : '' ?></td>
<td><?= h($traza->tabla) ?></td>
<td><?= $this->FF($traza->fecha) ?></td>
<!-- <td><?= $this->Number->format($traza->id_objeto) ?></td>-->
</tr>
<?php endforeach; ?>
</tbody>
</table>
$(document).ready(function(){
$('#sample_3').DataTable();
});
only shows me 20 records....why is that...is very seriuos issue for me please help me...
This discussion has been closed.
Answers
ITs hard to say without seeing what your page looks like. Do you get any alert or console errors?
If you remove
$('#sample_3').DataTable();
from your code do all records appear?Kevin
the foreach in the tbody is because this is my index.ctp and i have a mysql table named TRAZAS WITH ALL THE CONTROLLER,MODEL ETC. So i search all my trazas and fill the table(THIS CODE IS ORIGINAL WHEN I USE CAKEPHP IT WORKS PERFECTLY ...BUT WHEN I USED DATABLE PLUGIN EXTRACTED FROM METRONICS ONLY SHOWS 20)...
PROBLEM:
MY SQL TABLE HAVE 256 RECORDS AND I SHOW IT IN MY index.CTP WITH CAKEPHP ORIGINAL CODE AND WOKRS PERFECTLY ...WHEN I USE DATATABLE ONLY SHOWS ME THE FIRST 20 ENTRIES AND NOTHING ELSE.
WHAT I NEED:
ALL MY 256 RECORDS...I DON'T KNOW WHY IS HAPPEN THIS...
if you can chat with me directly will be perfect..i'm from cuba so is very dificult for me post all my website i work offline with localhost...thanks
To troubleshoot we need to see the data in your page and the generated HTML for the table. Maybe you can view the source of your page once generated and paste the contents into https://pastebin.com/.
Please provide a link to the resulting pastbin url.
You can also try the W3C Validator.
Since you are generating the HTML it is likely Datatables doesn't like something in the data or there is something the the table's HTML thats not correct or what Datatables is expecting.
Do you have errors in your browser's console?
Kevin
my friend after cotinue trying to solve the problem i found this....why is happening this???....the datatable paginator only give 2 pages and 20 entries...and with the original paginator code from cakephp i got all my 256 entries..
this is the original paginator code
https://pastebin.com/dX9KqwK7 this is the paste webpage
I'm a bit confused. In your HTML I see 16 table rows. Does cakephp fetch from the sever for each page or is all 256 rows loaded at once?
EDIT: If you initialize Datatables using the DOM sourced table with 16 rows then that's all its going to know about.
Sorry, I'm not familiar with cakephp and how it works. Maybe instead of using cakephp to build your table you should let Datatables fetch the data using ajax and build the table.
But without understanding what your data and how you are trying to use it its hard to say.
EDIT: Maybe the manual page describing the Datatables data requirements will help you:
https://datatables.net/manual/data/
Kevin
sorry my friend i'm no familiar with datatable and using ajax...i'm going to ask in cakephp forum thanks my friend
Looks like you may have missed my update above.
Kevin