Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add functionality to select count distinct #224

Merged
merged 1 commit into from Sep 3, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions src/SleepingOwl/Admin/Display/DisplayDatatablesAsync.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -231,4 +239,4 @@ public function name($name = null)
return $this;
}

}
}