diff --git a/resources/views/default/display/table.blade.php b/resources/views/default/display/table.blade.php index d1f4fcffa..402a92d08 100644 --- a/resources/views/default/display/table.blade.php +++ b/resources/views/default/display/table.blade.php @@ -44,4 +44,10 @@ @endforeach + + @if($collection instanceof \Illuminate\Contracts\Pagination\Paginator) +
+ @endif diff --git a/src/Display/DisplayTable.php b/src/Display/DisplayTable.php index c065f38c5..7bc0f1b2a 100644 --- a/src/Display/DisplayTable.php +++ b/src/Display/DisplayTable.php @@ -82,6 +82,11 @@ class DisplayTable implements Renderable, DisplayInterface */ protected $actions = []; + /** + * @var int|null + */ + protected $paginate; + /** * @param string $class */ @@ -383,6 +388,26 @@ public function getTitle() return implode(', ', $titles); } + /** + * @param int $perPage + * + * @return $this + */ + public function paginate($perPage = 20) + { + $this->paginate = (int) $perPage; + + return $this; + } + + /** + * @return bool + */ + public function usePagination() + { + return $this->paginate > 0; + } + /** * @return array */ @@ -405,17 +430,24 @@ public function getParams() */ public function render() { - $query = $this->getRepository()->getQuery(); - $this->modifyQuery($query); $params = $this->getParams(); - $params['collection'] = $query->get(); + $params['collection'] = $this->getCollection(); return app('sleeping_owl.template')->view('display.'.$this->view, $params); } - public function getColection() + /** + * @return + */ + protected function getCollection() { + $query = $this->getRepository()->getQuery(); + + $this->modifyQuery($query); + return $this->usePagination() + ? $query->paginate($this->paginate) + : $query->get(); } /**