diff --git a/docs/03. Columns.md b/docs/03. Columns.md
index b918226c..01b25db1 100644
--- a/docs/03. Columns.md
+++ b/docs/03. Columns.md
@@ -78,6 +78,9 @@ $viewAction = new Column\Action\Button();
$viewAction->setLabel('View');
$viewAction->setLink('view/url/id');
+//or set a dynamic column/row value as label
+$viewAction->setLabel($oneColumn);
+
$actions = new Column\Action();
$actions->setLabel('');
$actions->addAction($viewAction);
diff --git a/src/ZfcDatagrid/Column/Action/Button.php b/src/ZfcDatagrid/Column/Action/Button.php
index 991037f1..7f8dbcdb 100644
--- a/src/ZfcDatagrid/Column/Action/Button.php
+++ b/src/ZfcDatagrid/Column/Action/Button.php
@@ -1,6 +1,8 @@
label = (string) $name;
+ $this->label = $name;
}
/**
*
- * @return string
+ * @return string|AbstractColumn
*/
public function getLabel()
{
@@ -36,11 +38,26 @@ public function getLabel()
* @return string
*/
protected function getHtmlType()
+ {
+ throw new \Exception('not needed...since we have toHtml() here directly!');
+ }
+
+ /**
+ *
+ * @param array $row
+ * @return string
+ */
+ public function toHtml(array $row)
{
if ($this->getLabel() == '') {
throw new \InvalidArgumentException('A label is required for this action type, please call $action->setLabel()!');
}
- return $this->getLabel();
+ $label = $this->getLabel();
+ if ($label instanceof AbstractColumn) {
+ $label = $row[$label->getUniqueId()];
+ }
+
+ return 'getAttributesString($row) . '>' . $label . '';
}
}
diff --git a/tests/ZfcDatagridTest/Column/Action/ButtonTest.php b/tests/ZfcDatagridTest/Column/Action/ButtonTest.php
index cc5f0b74..0929b2e0 100644
--- a/tests/ZfcDatagridTest/Column/Action/ButtonTest.php
+++ b/tests/ZfcDatagridTest/Column/Action/ButtonTest.php
@@ -16,21 +16,35 @@ public function testConstruct()
$this->assertEquals([
'href' => '#',
- 'class' => 'btn',
+ 'class' => 'btn btn-default',
], $button->getAttributes());
}
- public function testLabel()
+ public function testLabelAndToHtml()
{
$button = new Button();
$button->setLabel('My label');
$this->assertEquals('My label', $button->getLabel());
- $html = 'My label';
+ $html = 'My label';
$this->assertEquals($html, $button->toHtml([]));
}
+ public function testColumnLabelAndToHtml()
+ {
+ $col = $this->getMockForAbstractClass('ZfcDatagrid\Column\AbstractColumn');
+ $col->setUniqueId('myCol');
+
+ $button = new Button();
+
+ $button->setLabel($col);
+ $this->assertInstanceOf('ZfcDatagrid\Column\AbstractColumn', $button->getLabel());
+
+ $html = 'Blubb';
+ $this->assertEquals($html, $button->toHtml(['myCol' => 'Blubb']));
+ }
+
public function testHtmlException()
{
$button = new Button();