Server side processing and pagination problem

Server side processing and pagination problem

spidermanspiderman Posts: 3Questions: 0Answers: 0
edited November 2010 in General
Hi Allan,

Recently, I started using jquery and found this great plugin. I want to display the data table based on user selection. And I was passing user selection and "sEcho" variable to my php script on server side. I was able to display datatable but following are problems on which I am stuck .

1) Pagination is not working correctly. For testing, I am having 15 records in database. When I select 10 entries from drop down, It shows at the bottom 2 pages and both pages is having same data (same 15 records). It just does not divide data into page with 10 records and page with 5 records.

2) Global search is also not working . None of the columns are sorted when I enter keywords in search box.

For your reference, following is snippet of my code. Please let me know where I am going wrong.
[code]
if(typeof oTable == 'undefined'){
oTable = $('#applicanttable').dataTable( {
"sAjaxSource": 'processrequest.php',
"bProcessing": true,
"sPaginationType": "full_numbers",
"iDisplayLength": 25,
"aoColumns": [
null,
null,
null,
{ "sType": "html" },
null,
null,
null,
{ "sType": "html" }
],
"bServerSide": true,
"bPaginate":true,
"bAutoWidth": true,
"bFilter":true,
"bSort":true,
"fnServerData": function (sSource, aoData, fnCallback){
var selection = document.getElementById("selection").value;
aoData.push({"name": "selection",
"value": selection
});
$.ajax({
type: "POST",
url: sSource,
data: 'sEcho='+aoData[0].value+'&sel='+aoData[42].value,
success: fnCallback
});
}
} );
[/code]
PHP server side scrpit....
[code]
header('Content-type: application/json');


$sEcho = (int)$_POST['sEcho'];
$request = $_POST['sel'];

if($request == 'prev')
$result = getDataFromDatabase();
else if($request == 'current')
$result= getDataFromDatabase();
else if($request == 'all')
$result = getDataFromDatabase();

$numofrecords = mysql_num_rows($result);
if($numofrecords == '')
$numofrecords = 0;

$totalrecords = getAllDataFromDatabase();
$displayrecords = mysql_num_rows($totalrecords);
$output .= '{"sEcho":'.$sEcho.',';
$output .= '"iTotalRecords":'.$displayrecords.',';
$output .= '"iTotalDisplayRecords":'.$numofrecords.',';
$output .= '"aaData": [ ';
........']}';
echo $output;
[/code]



Thanks
Samir

Replies

This discussion has been closed.