Pagination and AJAX
Pagination and AJAX
Hi,
I'm using datatables and I don't if it's possible to load only some row from database and have pagination from all of them. The ideia is to load and show, for example, 5 rows and when we click on 2, of the pagination, we get the next 5 rows with AJAX.
Is this possible?
Best regards,
JA
I'm using datatables and I don't if it's possible to load only some row from database and have pagination from all of them. The ideia is to load and show, for example, 5 rows and when we click on 2, of the pagination, we get the next 5 rows with AJAX.
Is this possible?
Best regards,
JA
This discussion has been closed.
Replies
[code]
"sPaginationType": "full_numbers",
"iDisplayLength": 10,
"aLengthMenu": [5, 10],
"sAjaxDataProp": "waiting",
"sAjaxSource": 'https://www.finaidtest.com/index.php/studentqueue_controller/ajaxcall',
[/code]
now if your using fnreloadajax you must pass these paramters to maintain your state :
[code]
setInterval(function() {
table1.fnReloadAjax(null,null,true);
}, 1000); < == one second reload
[/code]
hopefully this helps
See also: http://datatables.net/usage/#data_sources
Allan
what I was looking for it's something similar to the server side, but I'm using an external ajax call to insert rows in my datatable, with the fnAddData. In this case, is it possible to do something like server side?
best regards,
JA
Allan
Allan
I'm trying to implement by my self a simple "program" to understand the Server-side processing plugin.
I have this html:
[code]
$(document).ready(function(){
$('#table').dataTable({
"bJQueryUI": true,
"iDisplayStart": 20,
"iDisplayLength": 10,
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "ajax.php",
"sPaginationType": "full_numbers",
"oLanguage": {
"sInfo": "Got a total of _TOTAL_ entries to show (_START_ to _END_)",
"sSearch": "Search:",
"sLengthMenu": "Display _MENU_ records",
"oPaginate": {
"sPrevious": "Previous"
}
},
});
});
Column 1
Column 2
<!-- -->
[/code]
And my ajax.php is that:
[code]<?php
session_start();
if(isset($_SESSION['sEcho']))
$_SESSION['sEcho']=$_SESSION['sEcho']+1;
else
$_SESSION['sEcho']=1;
$count = 0;
$data = array();
for ($i=0;$i<100;$i++) {
$teste[] = ['hello'.$i, 'hellox'.$i];
$count = $count+1;
}
/*
* Paging
*/
if ( isset( $_GET['iDisplayStart'] ) && $_GET['iDisplayLength'] != '-1' )
{
$ini = $_GET['iDisplayStart'];
$count = $_GET['iDisplayLength'];
$i = 0;
while ($i<$count) {
$data[] = $teste[$ini];
$ini = $ini+$i;
}
}
if(!$data) {
$data = $teste;
}
$output = array(
"sEcho" => intval($_SESSION['sEcho']),
"iTotalRecords" => $count*10,
"iTotalDisplayRecords" => 10,
"aaData" => array()
);
foreach($data as $t) {
$output['aaData'][] = $t;
}
echo json_encode($output);
?>[/code]
But I get an error with a message "DataTables warning (table id='table'): DataTables Warning: JSON data from server could not be parsed. This is caused by a JSON formating error".
When I comment this part of the code:
[code]/*
* Paging
*/
if ( isset( $_GET['iDisplayStart'] ) && $_GET['iDisplayLength'] != '-1' )
{
$ini = $_GET['iDisplayStart'];
$count = $_GET['iDisplayLength'];
$i = 0;
while ($i<$count) {
$data[] = $teste[$ini];
$ini = $ini+$i;
}
}[/code]
I don't have the error message, but I don't understand why. I declare the iDisplayStart and the iDisplayLength in my html file.
Allan
jQuery.ajax( {
"dataType": 'json',
"type": "POST",
"url": sSource,
"data": aoData,
"success": fnCallback
} );
}[/code]
But, the iDisplayStart and the iDisplayLength are null and this is impossible to entry in the if cycle. I realize that the problem is in the way that I declare iDisplayStart.
Allan
Thanks for the replies, that helped me alot.
In fact, now I can get the value that I have posted in my .js file.
But, one last question...How can I get the value of the pagination to parse to my .php file by aoData?
Best regards,
JA
Allan