How pagination works?
How pagination works?
Hello! I have some difficulties with dataTables pagination. All rows returned by ajax (12 rows) are displaing on the 1 page. But show entries is 10 and and DataTables plug-in have two page references. Click on page 2 doesn’t work. What am I doing wrong?
Here is my code.
HTML table ------------------------------------------------------------
<thead>
<tr>
<th>col1</th>
<th>col2</th>
<th>col3</th>
</tr>
</thead>
jQuery ------------------------------------------------------------
$(document).ready( function () {
oDataTable1 = $('#sip_list').dataTable( {
serverSide: true,
paging: true,
ajax: {
url: ' server_side.php',
type: 'POST',
dataType: 'json'
},
columns: [
{ data: "col1" },
{ data: "col2" },
{ data: "col3" }
]
} );
server_side.php --------------------------------------------------
<?php
$res[0] = array('col1'=>'1', 'col2'=>'2', 'col3'=>'3');
$res[1] = array('col1'=>'1', 'col2'=>'2', 'col3'=>'3');
$res[2] = array('col1'=>'1', 'col2'=>'2', 'col3'=>'3');
$res[3] = array('col1'=>'1', 'col2'=>'2', 'col3'=>'3');
$res[4] = array('col1'=>'1', 'col2'=>'2', 'col3'=>'3');
$res[5] = array('col1'=>'1', 'col2'=>'2', 'col3'=>'3');
$res[6] = array('col1'=>'1', 'col2'=>'2', 'col3'=>'3');
$res[7] = array('col1'=>'1', 'col2'=>'2', 'col3'=>'3');
$res[8] = array('col1'=>'1', 'col2'=>'2', 'col3'=>'3');
$res[9] = array('col1'=>'1', 'col2'=>'2', 'col3'=>'3');
$res[10] = array('col1'=>'1', 'col2'=>'2', 'col3'=>'3');
$res[11] = array('col1'=>'1', 'col2'=>'2', 'col3'=>'3');
$res = array('draw' => 1, 'recordsTotal' => 12, 'recordsFiltered' => 12, 'data' => $res );
echo json_encode($res);
and else, how can I add formated <code> on this forum? Thanks
Answers
Have you fully implemented server-side processing? The error suggests probably not.
Allan
I’am sorry for my stupid questions, I’m more than beginner :)
I added parameters - start:10 and length:10 into dataTable() but the result is same – 12rows/first page.
If so, then what start and length need for?
I don’t understand what way is right. May be I need to write event handler for all pages?
Something like
.on( 'page.dt', function () { doevent ( 'Page' ); } );
Let's step back for a second. Do you need server-side processing? Will your table have 50,000+ rows in it? If not, disable server-side processing. If it will, you need to read through the manual page for server-side processing in more detail and probably also play with the examples.
Allan
Thank you for help! I disabled server-side processing. 10 rows on the first page, 2 on the second one. Great! While there is no need in big tables, but in the nearest future why not. Thank you, allan.