How do i return the data first for filter,sort or limit and later return the record count
How do i return the data first for filter,sort or limit and later return the record count
Aryan1703
Posts: 73Questions: 19Answers: 1
What I want is when i am filtering/sorting i want to return the data first to the table and then later update the filtered count and total count so this way my data would be loaded faster.
private function _ssp_query($query, $http)
{
if (!isset($http['draw'])) {
return array();
}
// Add the server-side processing conditions
$this->_ssp_limit($query, $http);
$this->_ssp_sort($query, $http);
$this->_ssp_filter($query, $http);
// Get the number of rows in the result set
$ssp_set_count = $this->_db
->query('count')
->table($this->_read_table())
->get($this->_pkey[0]);
$this->_get_where($ssp_set_count);
// $this->_ssp_filter($ssp_set_count, $http);
$ssp_set_count->left_join($this->_leftJoin);
$ssp_set_count = $ssp_set_count->exec()->fetch();
// // Get the number of rows in the full set
$ssp_full_count = $this->_db
->query('count')
->table($this->_read_table())
->get($this->_pkey[0]);
$this->_get_where($ssp_full_count);
// if (count($this->_where)) { // only needed if there is a where condition
// $ssp_full_count->left_join($this->_leftJoin);
// }
$ssp_full_count = $ssp_full_count->exec()->fetch();
return array(
"draw" => intval($http['draw']),
"recordsTotal" => $ssp_full_count['cnt'],
"recordsFiltered" => $ssp_set_count['cnt']
);
}
This question has an accepted answers - jump to answer
Answers
The server side processing protocol expects the
recordsTotal
and recordsFiltered` to be in each response. There are no provisions to provide these values and a subsequent response. Otherwise Datatables wouldn't be able to calculate the paging information correctly for the paging buttons, etc.Kevin
But, lets say i want to pass a harcoded value like 9999(for records total and filtered) initially to the response and later when the query is excuted it will send the fetched count as response so this way I am not slowing down my table load.
Thanks
Ajax doesn't support receiving two different responses for the same request. You would need to send a second request to fetch the records total and filtered. You could possibly use
ajax
as a function to handle sending and processing a second request for the records total and filtered.There aren't any API's to programmatically update the paging button information. However you could create your own paging controls and keep track to the paging information when the records total and filtered are returned. Same with the information element to show how many records are in the table. You can create your own and update it appropriately.
Kevin