Skip to content

Commit 071b4a1

Browse files
authored
Merge pull request #1743 from forgottencreature/filtered-count
[8.0] Add support for manual setting of filtered count (#1516)
2 parents b2d9df3 + 688d2b2 commit 071b4a1

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

src/DataTableAbstract.php

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,19 @@ public function setTotalRecords($total)
413413
return $this;
414414
}
415415

416+
/**
417+
* Set filtered records manually.
418+
*
419+
* @param int $total
420+
* @return $this
421+
*/
422+
public function setFilteredRecords($total)
423+
{
424+
$this->filteredRecords = $total;
425+
426+
return $this;
427+
}
428+
416429
/**
417430
* Skip pagination as needed.
418431
*
@@ -540,6 +553,16 @@ public function toJson($options = 0)
540553
return $this->make();
541554
}
542555

556+
/**
557+
* Count filtered items.
558+
*
559+
* @return int
560+
*/
561+
protected function filteredCount()
562+
{
563+
return $this->filteredRecords ? $this->filteredRecords : $this->count();
564+
}
565+
543566
/**
544567
* Perform necessary filters.
545568
*
@@ -556,7 +579,7 @@ protected function filterRecords()
556579
}
557580

558581
$this->columnSearch();
559-
$this->filteredRecords = $this->isFilterApplied ? $this->count() : $this->totalRecords;
582+
$this->filteredRecords = $this->isFilterApplied ? $this->filteredCount() : $this->totalRecords;
560583
}
561584

562585
/**

0 commit comments

Comments
 (0)