From 209f5eaed7aeb39113d980499ebc5561f57b4310 Mon Sep 17 00:00:00 2001 From: iYogesharma <44565761+iYogesharma@users.noreply.github.com> Date: Thu, 3 Nov 2022 15:49:29 +0530 Subject: [PATCH] Update AbstractDatatable.php Fixes Total Record Count Issue in case query contain multiple group by and having clause --- src/AbstractDatatable.php | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/src/AbstractDatatable.php b/src/AbstractDatatable.php index c2c1a33..451a8b7 100755 --- a/src/AbstractDatatable.php +++ b/src/AbstractDatatable.php @@ -255,7 +255,7 @@ protected function checkIfQueryIsForSearchingPurpose() { if( $this->request->isSearchable() ) { - $this->totalData = $this->query->count(); + $this->totalData = $this->query->getCountForPagination(); $this->searchQuery(); } } @@ -269,22 +269,14 @@ 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)) @@ -292,7 +284,7 @@ protected function setTotalDataAndFiltered() $this->query->bindings['where'] = []; $this->query->wheres = []; $this->havingCondition($this->request->getSearchString(), $this->havingColumns); - $this->totalFiltered = $this->query->count(); + $this->totalFiltered = $this->query->getCountForPagination(); } } }