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; } /**