Skip to content

Commit

Permalink
Issue #24: Add setRowAttribute().
Browse files Browse the repository at this point in the history
  • Loading branch information
donquixote committed Oct 27, 2024
1 parent 113b88e commit ee52b15
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/TSection/TableSection.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,18 @@ public function addRowClass($rowName, $class) {
return $this;
}

/**
* @param string $rowName
* @param string $name
* @param string $value
*
* @return $this
*/
public function setRowAttribute($rowName, $name, $value) {
$this->rowAttributes->nameSetAttribute($rowName, $name, $value);
return $this;
}

/**
* @param string[] $rowClasses
* Format: $[$rowName] = $class
Expand Down
11 changes: 11 additions & 0 deletions src/Table/TBodyWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,17 @@ public function addRowClass($rowName, $class) {
return $this;
}

/**
* @param string $rowName
* @param string $class
*
* @return $this
*/
public function setRowAttribute($rowName, $name, $value) {
$this->tbody->setRowAttribute($rowName, $name, $value);
return $this;
}

/**
* @param string[] $rowClasses
* Format: $[$rowName] = $class
Expand Down
28 changes: 28 additions & 0 deletions tests/src/CellbrushTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,34 @@ function testRowClass() {
</tbody>
</table>
EOT;

$this->assertEquals($expected, $table->render());
}

function testRowAttributes() {
$table = Table::create()->addColNames(['col0', 'col1']);
$table->addRow('row0');
$table->addRow('row1')->td('col1', '1/1');
$table->setRowAttribute('row1', 'title', 'row 1 title');
$table->addRow('group')->td('col0', 'AB left');
$table->addRow('group.a')->td('col1', 'A right');
$table->addRow('group.b')->td('col1', 'B right');
// A row attribute on a rowspan group is ignored.
$table->setRowAttribute('group', 'title', 'Group AB');
$table->setRowAttribute('group.a', 'title', 'Group part A');
$table->setRowAttribute('group.b', 'title', 'Group part B');

$expected = <<<EOT
<table>
<tbody>
<tr><td></td><td></td></tr>
<tr title="row 1 title"><td></td><td>1/1</td></tr>
<tr title="Group part A"><td rowspan="2">AB left</td><td>A right</td></tr>
<tr title="Group part B"><td>B right</td></tr>
</tbody>
</table>
EOT;

$this->assertEquals($expected, $table->render());
Expand Down

0 comments on commit ee52b15

Please sign in to comment.