Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions src/Bootstrapper/Table.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ class Table extends RenderedObject
*/
protected $only = [];

/**
* @var bool|array An array of aliases of columns. False if none.
*/
protected $aliases = false;

/**
* @var array An array of classes to apply to body tds
*/
Expand Down Expand Up @@ -314,6 +319,19 @@ public function only(array $only)
return $this;
}

/**
* Sets columns aliases
*
* @param array $only
* @return $this
*/
public function alias(array $aliases)
{
$this->aliases = $aliases;

return $this;
}

private function renderHeaders()
{
$headers = $this->getHeaders();
Expand All @@ -324,10 +342,11 @@ private function renderHeaders()

$string = '<thead><tr>';
foreach ($headers as $heading) {
$heading_title = $this->aliases && array_key_exists($heading, $this->aliases) ? $this->aliases[$heading] : $heading;
if (isset($this->columnClasses[$heading])) {
$string .= "<th class='{$this->columnClasses[$heading]}'>{$heading}</th>";
$string .= "<th class='{$this->columnClasses[$heading]}'>{$heading_title}</th>";
} else {
$string .= "<th>{$heading}</th>";
$string .= "<th>{$heading_title}</th>";
}
}
$string .= '</tr></thead>';
Expand Down