I wrote a patch to enable adding attributes, such as "colspan", "rowspan" or "class" to the <td> element, via the use of a new form attribute #td_attributes
Example usage:
$form['my_table'] = array(
'#type' => 'tableform',
'#header' => array(
t('ID'),
t('Title'),
),
'#options' => array(
array(
'1',
t('One'),
),
array(
'2',
t('Two'),
),
array(
array(
'#markup' => l(t('Add new'), 'node/add'), // <-----
'#td_attributes' => array( // <-----
'colspan' => 2, // <-----
), // <-----
),
),
),
);
This results in the following markup:
<table class="sticky-enabled">
<thead>
<tr>
<th>ID</th>
<th>Title</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td>1</td>
<td>One</td>
</tr>
<tr class="even">
<td>2</td>
<td>Two</td>
</tr>
<tr class="odd">
<td colspan="2"> <!-- SEE HERE -->
<a href="/en/node/add">Add new</a>
</td>
</tr>
</tbody>
</table>
Comments
Comment #1
khuongkd commentedI wrote for class header but element form '#tree' not work
after i change to #prefix -> worked.
Comment #2
neovinhtru commentedoh nice!
thank you so much.
Comment #3
linhdevil10107 commentedgood job!
Vote for khuongkd!
Comment #4
nikita_ttHere is my version of patch. You just need to add the '#tf_attributes' (array) element to the array of row columns.
Example: