diff --git a/src/SleepingOwl/Admin/Display/DisplayDatatablesAsync.php b/src/SleepingOwl/Admin/Display/DisplayDatatablesAsync.php index a4ec57d7..4be4888e 100644 --- a/src/SleepingOwl/Admin/Display/DisplayDatatablesAsync.php +++ b/src/SleepingOwl/Admin/Display/DisplayDatatablesAsync.php @@ -22,9 +22,11 @@ class DisplayDatatablesAsync extends DisplayDatatables implements WithRoutesInte /** * @param string|null $name */ - function __construct($name = null) + protected $distinct; + function __construct($name = null, $distinct=null) { $this->name($name); + $this->distinct=$distinct; } /** @@ -92,11 +94,17 @@ public function renderAsync() $query = $this->repository->query(); $totalCount = $query->count(); + if(!is_null($this->distinct)){ + $filteredCount = $query->distinct()->count($this->distinct); + } + $this->modifyQuery($query); $this->applySearch($query); $this->applyColumnSearch($query); - - $filteredCount = $query->count(); + + if(is_null($this->distinct)){ + $filteredCount = $query->count(); + } $this->applyOrders($query); $this->applyOffset($query); @@ -231,4 +239,4 @@ public function name($name = null) return $this; } -} \ No newline at end of file +}