Skip to content

Commit

Permalink
Temporary solution for pseudo header values
Browse files Browse the repository at this point in the history
  • Loading branch information
JPustkuchen committed Jul 2, 2021
1 parent f3371d8 commit 14cde7f
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/Elements/Table.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,15 +182,15 @@ public function removeHeaderlessColumns(): Table {
* @param stromg $class The class name to hide the cell.
* @return Table
*/
public function hideHeaderlessColumns($class = 'hidden'): Table {
public function hideHeaderlessColumns(): Table {
$cellKeys = $this->header->getCellKeys();
if (!empty($this->rows) && !empty($cellKeys)) {
foreach ($this->rows as $row) {
$cells = $row->getCells();
foreach ($cells as $cell) {
$cellKey = $cell->getKey();
if (!in_array($cellKey, $cellKeys)) {
$cell->addClass($class);
$cell->setHidden(true);
}
}
}
Expand Down
22 changes: 22 additions & 0 deletions src/Elements/TableCell.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,15 @@ class TableCell extends HtmlEntity {
*/
private ?string $afterValueRaw = null;

/**
* Defines the cell as hidden.
* Helpfull to allow "pseudo" cells for
* data purposes.
*
* @var bool
*/
private $hidden = false;


public function __construct(string $key, ?string $value = null, ?HtmlAttributes $attributes = null) {
$this->key = $key;
Expand Down Expand Up @@ -85,6 +94,7 @@ public function toArray() {
'beforeValueRaw' => $this->beforeValueRaw,
'afterValueRaw' => $this->afterValueRaw,
'attributes' => $this->getAttributes()->toString(),
'hidden' => $this->hidden,
];

return $result;
Expand Down Expand Up @@ -133,4 +143,16 @@ public function setBeforeValueRaw($beforeValueRaw) {

return $this;
}

/**
* Set the cell hidden.
*
* @return self
*/
public function setHidden(bool $hidden)
{
$this->hidden = $hidden;

return $this;
}
}
2 changes: 1 addition & 1 deletion src/Elements/TableRow.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public static function createFromArray(array $cellsArray) {
$tableCell = new TableCell($key, $cell);
// TODO - Dirty workarund to hide empty (null) values and headers
if($cell === null){
$tableCell->addClass('hidden');
$tableCell->setHidden(true);
}
$cells[] = $tableCell;
} else {
Expand Down
4 changes: 3 additions & 1 deletion src/Resources/views/table.html.twig
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{% block table %}
<table {% if tabledata.attributes is defined and tabledata.attributes is not empty %} {{ tabledata.attributes|raw }} {% endif %}>
{% block table_before %}{% endblock %}
<table {% if id is not empty %}id="{{ id }}"{% endif %} {% if tabledata.attributes is defined and tabledata.attributes is not empty %} {{ tabledata.attributes|raw }} {% endif %}>
{% block thead %}
<thead>
{% block thead_row %}
Expand Down Expand Up @@ -41,4 +42,5 @@
</tbody>
{% endblock %}
</table>
{% block table_after %}{% endblock %}
{% endblock %}

0 comments on commit 14cde7f

Please sign in to comment.