Serverside Processing with AJAX and a non standard datasource

Serverside Processing with AJAX and a non standard datasource

rhythmicdevilrhythmicdevil Posts: 10Questions: 0Answers: 0
edited January 2013 in DataTables 1.9
Hi.
I am attempting to use datatables to page data from our internal API. The datatable is fetching data but for some reason the paging controls are not active. I manually set the iTotalRecords value because I cant actually get a count of records (its a long story). Given that I am only displaying 10 records and told the datatable that I have 500 records I assumed the paging controls would be active. What did I miss?

Thanks very much
Steve


Here is the table initialization:
[code]
var d_table = $('#dr_tuf').dataTable( {
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": '/datamining/get_dr_tuff_datatable_',
"aoColumns" : [
{"mData" : "URL"},
{"mData" : "Source"},
{"mData" : "MD5"},
{"mData" : "FirstSeen"},
{"mData" : "LastSeen"},
{"mData" : "Rating"},
{"mData" : "Confidence"},
{"mData" : "AnalystRating"}
]
});
[/code]

And here is my server side code:
[code]
$sEcho = 1;
if(!empty($this->params['url']['sEcho']))
{
$sEcho = (int)$this->params['url']['sEcho'];
}

$num_of_rows = 10;

$query_data = array(
'conditions' => array(
'alias' => 'dr_tuf',
'cache' => FALSE,
'rows' => $num_of_rows
//'select' => $select
)
);

$data = $this->Datamining->DrTuf->find('all', $query_data);

// Fields in returned data
$fields = array('URL', 'Source', 'MD5', 'FirstSeen', 'LastSeen', 'Rating', 'Confidence', 'AnalystRating');
$datatable = new StdClass();

foreach($data as $row)
{
$r = new StdClass();
foreach($fields as $f)
{
if(!empty($row['DrTuf'][$f]))
{
$r->$f = $row['DrTuf'][$f];
}
else
{
$r->$f = '';
}
}
$datatable->aaData[] = $r;
}

$datatable->sEcho = $sEcho;
$datatable->iTotalRecords = 500;
$datatable->iTotalDisplayRecords = $num_of_rows;

$this->set('response', $datatable);
$this->render('../elements/ajax_response', 'ajax');
[/code]

Replies

  • rhythmicdevilrhythmicdevil Posts: 10Questions: 0Answers: 0
    Man it sure is lonely in here.
  • rhythmicdevilrhythmicdevil Posts: 10Questions: 0Answers: 0
    Sure is chilly out here in the cold.
  • allanallan Posts: 63,389Questions: 1Answers: 10,450 Site admin
    Aye - cold here as well :-)

    That looks like it should work okay. Can you link us to a test case, or run the debugger over it.

    I would say:

    > $datatable->iTotalDisplayRecords = $num_of_rows;

    That looks dodgy. iTotalDisplayRecords and iTotalRecords should be the same unless you have filtering applied - http://datatables.net/usage/server-side

    Allan
This discussion has been closed.