Skip to content

Commit 209f5ea

Browse files
authored
Update AbstractDatatable.php
Fixes Total Record Count Issue in case query contain multiple group by and having clause
1 parent a343a0f commit 209f5ea

File tree

1 file changed

+4
-12
lines changed

1 file changed

+4
-12
lines changed

src/AbstractDatatable.php

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ protected function checkIfQueryIsForSearchingPurpose()
255255
{
256256
if( $this->request->isSearchable() )
257257
{
258-
$this->totalData = $this->query->count();
258+
$this->totalData = $this->query->getCountForPagination();
259259
$this->searchQuery();
260260
}
261261
}
@@ -269,30 +269,22 @@ protected function setTotalDataAndFiltered()
269269
{
270270
if( ! $this->totalData )
271271
{
272-
// to get correct result count in case of group by
273-
if( $this->query->groups )
274-
{
275-
$this->totalData = $this->query->getCountForPagination();
276-
}
277-
else
278-
{
279-
$this->totalData = $this->query->count();
280-
}
272+
$this->totalData = $this->query->getCountForPagination();
281273

282274
$this->totalFiltered = $this->totalData;
283275
}
284276
else
285277
{
286278

287-
$this->totalFiltered = $this->query->count();
279+
$this->totalFiltered = $this->query->getCountForPagination();
288280
if( !$this->totalFiltered )
289281
{
290282
if (!empty($this->havingColumns))
291283
{
292284
$this->query->bindings['where'] = [];
293285
$this->query->wheres = [];
294286
$this->havingCondition($this->request->getSearchString(), $this->havingColumns);
295-
$this->totalFiltered = $this->query->count();
287+
$this->totalFiltered = $this->query->getCountForPagination();
296288
}
297289
}
298290
}

0 commit comments

Comments
 (0)