Skip to content

Commit

Permalink
Add displayTable paginate method to provide pagination
Browse files Browse the repository at this point in the history
Use

...
$display = AdminDisplay::table()->paginate(20)->columns(....);
...
  • Loading branch information
butschster committed Feb 21, 2016
1 parent 95af9e3 commit 58bf192
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 4 deletions.
6 changes: 6 additions & 0 deletions resources/views/default/display/table.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,10 @@
@endforeach
</tbody>
</table>

@if($collection instanceof \Illuminate\Contracts\Pagination\Paginator)
<div class="panel-footer">
{!! $collection->render() !!}
</div>
@endif
</div>
40 changes: 36 additions & 4 deletions src/Display/DisplayTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ class DisplayTable implements Renderable, DisplayInterface
*/
protected $actions = [];

/**
* @var int|null
*/
protected $paginate;

/**
* @param string $class
*/
Expand Down Expand Up @@ -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
*/
Expand All @@ -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();
}

/**
Expand Down

0 comments on commit 58bf192

Please sign in to comment.