Problem Statement
Currently, HTMLTable has no built-in way to add a header row with <th> cells. The existing setFirstColCellType('th') changes the first column, not the first row. To create a header row, developers must manually loop through cells, call getCell(0, $c)->setNodeName('th'), and offset all data rows by 1.
Proposed Solution
Add a setHeaders(array $headers) method that:
- Creates a
<thead> section with a single <tr> containing <th> cells
- Accepts an array of header labels (strings or HTMLNode instances)
- Keeps data row indices 0-based (headers don't count as a data row)
$table = new HTMLTable(3, 4);
$table->setHeaders(['Name', 'Status', 'Owner', 'Created']);
$table->setValue(0, 0, 'Project A'); // First data row, not header
Generated HTML:
<table>
<thead><tr><th>Name</th><th>Status</th><th>Owner</th><th>Created</th></tr></thead>
<tbody>
<tr><td>Project A</td>...</tr>
</tbody>
</table>
This mirrors the CLI Command::$this->table($data, $headers) API which already accepts a separate headers array.
Alternatives Considered
setFirstRowCellType('th') — simpler but doesn't generate semantic <thead>, and wastes a data row for headers
- Manual loop with
getCell(0, $c)->setNodeName('th') — current workaround, verbose and error-prone
Breaking Change
No — purely additive.
Problem Statement
Currently,
HTMLTablehas no built-in way to add a header row with<th>cells. The existingsetFirstColCellType('th')changes the first column, not the first row. To create a header row, developers must manually loop through cells, callgetCell(0, $c)->setNodeName('th'), and offset all data rows by 1.Proposed Solution
Add a
setHeaders(array $headers)method that:<thead>section with a single<tr>containing<th>cellsGenerated HTML:
This mirrors the CLI
Command::$this->table($data, $headers)API which already accepts a separate headers array.Alternatives Considered
setFirstRowCellType('th')— simpler but doesn't generate semantic<thead>, and wastes a data row for headersgetCell(0, $c)->setNodeName('th')— current workaround, verbose and error-proneBreaking Change
No — purely additive.