From 73ad493c7e17602d4f4385bf98fdff51ce231f8e Mon Sep 17 00:00:00 2001 From: Patrick Date: Wed, 16 May 2018 15:43:23 -0400 Subject: [PATCH] add support for manual setting of filtered count --- src/DataTableAbstract.php | 15 ++++++++++++++- src/QueryDataTable.php | 11 ++++++++++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/DataTableAbstract.php b/src/DataTableAbstract.php index c0d632d3..c023e3a2 100644 --- a/src/DataTableAbstract.php +++ b/src/DataTableAbstract.php @@ -413,6 +413,19 @@ public function setTotalRecords($total) return $this; } + /** + * Set total records manually. + * + * @param int $total + * @return $this + */ + public function setFilteredRecords($total) + { + $this->filteredRecords = $total; + + return $this; + } + /** * Skip pagination as needed. * @@ -556,7 +569,7 @@ protected function filterRecords() } $this->columnSearch(); - $this->filteredRecords = $this->isFilterApplied ? $this->count() : $this->totalRecords; + $this->filteredRecords = $this->isFilterApplied ? $this->filteredCount() : $this->totalRecords; } /** diff --git a/src/QueryDataTable.php b/src/QueryDataTable.php index 270a5d19..38b828d1 100644 --- a/src/QueryDataTable.php +++ b/src/QueryDataTable.php @@ -121,6 +121,16 @@ public function totalCount() return $this->totalRecords ? $this->totalRecords : $this->count(); } + /** + * Count total items. + * + * @return int + */ + public function filteredCount() + { + return $this->filteredRecords ? $this->filteredRecords : $this->count(); + } + /** * Counts current query. * @@ -148,7 +158,6 @@ protected function prepareCountQuery() if (! $this->isComplexQuery($builder)) { $row_count = $this->wrap('row_count'); $builder->select($this->connection->raw("'1' as {$row_count}")); - $builder->setBindings([], 'select'); } return $builder;