From 688d2b2902828ea1e11fa1cfec59cb51e47c2e62 Mon Sep 17 00:00:00 2001 From: Patrick Date: Thu, 17 May 2018 01:48:03 -0400 Subject: [PATCH] Add support for manual setting of filtered count (#1516) --- src/DataTableAbstract.php | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/DataTableAbstract.php b/src/DataTableAbstract.php index c0d632d3..57063dc4 100644 --- a/src/DataTableAbstract.php +++ b/src/DataTableAbstract.php @@ -413,6 +413,19 @@ public function setTotalRecords($total) return $this; } + /** + * Set filtered records manually. + * + * @param int $total + * @return $this + */ + public function setFilteredRecords($total) + { + $this->filteredRecords = $total; + + return $this; + } + /** * Skip pagination as needed. * @@ -540,6 +553,16 @@ public function toJson($options = 0) return $this->make(); } + /** + * Count filtered items. + * + * @return int + */ + protected function filteredCount() + { + return $this->filteredRecords ? $this->filteredRecords : $this->count(); + } + /** * Perform necessary filters. * @@ -556,7 +579,7 @@ protected function filterRecords() } $this->columnSearch(); - $this->filteredRecords = $this->isFilterApplied ? $this->count() : $this->totalRecords; + $this->filteredRecords = $this->isFilterApplied ? $this->filteredCount() : $this->totalRecords; } /**