Skip to content

Commit

Permalink
Merge pull request bgultekin#86 from reneweteling/patch-1
Browse files Browse the repository at this point in the history
Update count in datatables.php
  • Loading branch information
MarkVaughn committed Mar 25, 2014
2 parents a1f3c41 + 3b0aa0a commit 31ecafc
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions src/Bllim/Datatables/Datatables.php
Original file line number Diff line number Diff line change
Expand Up @@ -471,10 +471,10 @@ public function database_prefix() {
* @param string $count variable to store to 'count_all' for iTotalRecords, 'display_all' for iTotalDisplayRecords
* @return null
*/
private function count($count = 'count_all')
{
//Get columns to temp var.
private function count($count = 'count_all')
{

//Get columns to temp var.
if($this->query_type == 'eloquent') {
$query = $this->query->getQuery();
$connection = $this->query->getModel()->getConnection()->getName();
Expand All @@ -483,11 +483,19 @@ private function count($count = 'count_all')
$query = $this->query;
$connection = $query->getConnection()->getName();
}
//Count the number of rows in the select with the proper connection

// if its a normal query ( no union ) replace the slect with static text to improve performance
$myQuery = clone $query;
if( !preg_match( '/UNION/i', $myQuery->toSql() ) ){
$myQuery->select( DB::Raw("'1' as row") );
}


$this->$count = DB::connection($connection)
->table(DB::raw('('.$query->toSql().') AS count_row_table'))
->setBindings($query->getBindings())->count();
}
->table(DB::raw('('.$myQuery->toSql().') AS count_row_table'))
->setBindings($myQuery->getBindings())->remember(1)->count();

}

/**
* Returns column name from <table>.<column>
Expand Down

0 comments on commit 31ecafc

Please sign in to comment.