Skip to content

Commit

Permalink
Issue #24: Add shortcut methods on RowHandle.
Browse files Browse the repository at this point in the history
  • Loading branch information
donquixote committed Oct 27, 2024
1 parent ee52b15 commit 872d902
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
21 changes: 21 additions & 0 deletions src/Handle/RowHandle.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,25 @@ public function thOpenEnd($colName, $content) {
return $this;
}

/**
* @param string $class
*
* @return $this
*/
public function addClass($class) {
$this->tsection->addRowClass($this->rowName, $class);
return $this;
}

/**
* @param string $key
* @param string $value
*
* @return $this
*/
public function setAttribute($key, $value) {
$this->tsection->setRowAttribute($this->rowName, $key, $value);
return $this;
}

}
7 changes: 5 additions & 2 deletions tests/src/CellbrushTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,10 @@ function testRowClass() {

function testRowAttributes() {
$table = Table::create()->addColNames(['col0', 'col1']);
$table->addRow('row0');
$table->addRow('row0')
->addClass('row0-class')
->setAttribute('title', 'Row 0 title')
;
$table->addRow('row1')->td('col1', '1/1');
$table->setRowAttribute('row1', 'title', 'row 1 title');
$table->addRow('group')->td('col0', 'AB left');
Expand All @@ -545,7 +548,7 @@ function testRowAttributes() {
$expected = <<<EOT
<table>
<tbody>
<tr><td></td><td></td></tr>
<tr title="Row 0 title" class="row0-class"><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>
Expand Down

0 comments on commit 872d902

Please sign in to comment.