Consider the following code:
$table = new html_table();
|
$table->head = array('Name', 'Actions');
|
|
$row = new html_table_row(array('Item #1', 'Example'));
|
$row->attributes['data-id'] = '1';
|
$table->data[] = $row;
|
|
$row = new html_table_row(array('Item #2', 'Example'));
|
$row->attributes['data-id'] = '2';
|
$row->attributes['data-parentid'] = '1';
|
$table->data[] = $row;
|
|
echo html_writer::table($table);
|
Which yields the following markup; notice the missing data-* attributes:
<table class="generaltable">
|
<thead>
|
<tr>
|
<th class="header c0" style="" scope="col">Name</th>
|
<th class="header c1 lastcol" style="" scope="col">Actions</th>
|
</tr>
|
</thead>
|
<tbody>
|
<tr class="r0">
|
<td class="cell c0" style="">Item #1</td>
|
<td class="cell c1 lastcol" style="">Example</td>
|
</tr>
|
<tr class="r1 lastrow">
|
<td class="cell c0" style="">Item #2</td>
|
<td class="cell c1 lastcol" style="">Example</td>
|
</tr>
|
</tbody>
|
</table>
|
With the patch applied, the output is correct:
<table class="generaltable">
|
<thead>
|
<tr>
|
<th class="header c0" style="" scope="col">Name</th>
|
<th class="header c1 lastcol" style="" scope="col">Actions</th>
|
</tr>
|
</thead>
|
<tbody>
|
<tr class=" r0" data-id="1">
|
<td class="cell c0" style="">Item #1</td>
|
<td class="cell c1 lastcol" style="">Example</td>
|
</tr>
|
<tr class=" r1 lastrow" data-id="2" data-parentid="1">
|
<td class="cell c0" style="">Item #2</td>
|
<td class="cell c1 lastcol" style="">Example</td>
|
</tr>
|
</tbody>
|
</table>
|
I have only tested this against 2.2.x, but a quick check of the 2.4 source indicates that this issue would occur on newer releases too.
- is duplicated by
-
MDL-46772 html_writer::table Ignore attributes for rows
-
- Closed
-