Quantcast
Viewing all articles
Browse latest Browse all 82109

Serverside Processing with AJAX and a non standard datasource

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:
		
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"}
			]
		});

And here is my server side 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');	

Viewing all articles
Browse latest Browse all 82109

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>