Skip to content

Commit

Permalink
feat: allow to display responsive table
Browse files Browse the repository at this point in the history
  • Loading branch information
therouv committed Sep 11, 2024
1 parent 956875d commit f67c240
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
9 changes: 9 additions & 0 deletions resources/views/default/grid.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
*/
?>
<form>
<?php if ($grid->getConfig()->isResponsive()): ?>
<div class="table-responsive">
<?php endif; ?>

<table class="table table-striped" id="<?= $grid->getConfig()->getName() ?>">
<?= $grid->header() ? $grid->header()->render() : '' ?>
<?php // ========== TABLE BODY ==========?>
Expand All @@ -17,6 +21,11 @@
</tbody>
<?= $grid->footer() ? $grid->footer()->render() : '' ?>
</table>

<?php // Hidden input for submitting form by pressing enter if there are no other submits?>
<input type="submit" style="display: none;"/>

<?php if ($grid->getConfig()->isResponsive()): ?>
</div>
<?php endif; ?>
</form>
26 changes: 26 additions & 0 deletions src/GridConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ class GridConfig implements RegistryInterface

protected $rowComponent;

protected $isResponsive = false;

/**
* @return RenderableComponentInterface
*/
Expand Down Expand Up @@ -232,6 +234,7 @@ public function addColumn(FieldConfig $column)
if ($this->columns === null) {
$this->setColumns([]);
}

$this->columns->push($column);

return $this;
Expand Down Expand Up @@ -259,4 +262,27 @@ public function getPageSize()
{
return $this->pageSize;
}

/**
* Checks if table should be responsive.
*
* @return bool
*/
public function isResponsive()
{
return $this->isResponsive;
}

/**
* Sets if table should be responsive.
*
* @param bool $isResponsive
* @return $this
*/
public function setIsResponsive($isResponsive)
{
$this->isResponsive = $isResponsive;

return $this;
}
}

0 comments on commit f67c240

Please sign in to comment.