Skip to content

Commit

Permalink
Update AbstractDatatable.php
Browse files Browse the repository at this point in the history
Fixes Total Record Count Issue in case query contain multiple group by and having  clause
  • Loading branch information
iYogesharma authored Nov 3, 2022
1 parent a343a0f commit 209f5ea
Showing 1 changed file with 4 additions and 12 deletions.
16 changes: 4 additions & 12 deletions src/AbstractDatatable.php
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ protected function checkIfQueryIsForSearchingPurpose()
{
if( $this->request->isSearchable() )
{
$this->totalData = $this->query->count();
$this->totalData = $this->query->getCountForPagination();
$this->searchQuery();
}
}
Expand All @@ -269,30 +269,22 @@ protected function setTotalDataAndFiltered()
{
if( ! $this->totalData )
{
// to get correct result count in case of group by
if( $this->query->groups )
{
$this->totalData = $this->query->getCountForPagination();
}
else
{
$this->totalData = $this->query->count();
}
$this->totalData = $this->query->getCountForPagination();

$this->totalFiltered = $this->totalData;
}
else
{

$this->totalFiltered = $this->query->count();
$this->totalFiltered = $this->query->getCountForPagination();
if( !$this->totalFiltered )
{
if (!empty($this->havingColumns))
{
$this->query->bindings['where'] = [];
$this->query->wheres = [];
$this->havingCondition($this->request->getSearchString(), $this->havingColumns);
$this->totalFiltered = $this->query->count();
$this->totalFiltered = $this->query->getCountForPagination();
}
}
}
Expand Down

0 comments on commit 209f5ea

Please sign in to comment.