Skip to content

Commit

Permalink
Hiding control row if empty
Browse files Browse the repository at this point in the history
  • Loading branch information
Nayjest committed Mar 12, 2016
1 parent c6fc9b5 commit 4af182e
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/Grid.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use RuntimeException;
use ViewComponents\Grids\Component\Column;
use ViewComponents\ViewComponents\Base\ComponentInterface;
use ViewComponents\ViewComponents\Base\Compound\PartInterface;
use ViewComponents\ViewComponents\Component\CollectionView;
use ViewComponents\ViewComponents\Component\Container;
use ViewComponents\ViewComponents\Component\Html\Tag;
Expand Down Expand Up @@ -122,4 +123,30 @@ protected function makeDefaultComponents()
new Part(new Tag('tfoot'), static::TABLE_FOOTER_ID, static::TABLE_ID), // new
];
}

/**
* Prepares component for rendering.
*/
protected function prepare()
{
parent::prepare();
$this->hideControlRowIfEmpty();
}

protected function hideControlRowIfEmpty()
{
$row = $this->getControlRow();
$container = $this->getControlContainer();
if (
!$row
|| !$container
|| !$container->children()->isEmpty()
|| ($row->children()->count() > 2) // submit button + control_container
) {
return;
}
/** @var Part $rowPart */
$rowPart = $this->getComponent(static::CONTROL_ROW_ID, false);
$rowPart->setView(null);
}
}

0 comments on commit 4af182e

Please sign in to comment.