I need to create a table that will have a header with 4 columns and then all the rows will have 5 columns, so I need to add a colspan in the header.
This is an example of what I trying to do:
// The table header.
$header = [
$this->t('Name'),
$this->t('Description'),
$this->t('Weight'),
$this->t('Package'),
];
// The table.
$form['modules'] = [
'#type' => 'table',
'#header' => $header,
'#rows' => [[1, 2, 3, 4, 5]],
'#sticky' => TRUE,
];
This code just give something like this:
But I trying to obtain something like this:
I tried the last example in Add a class to a Drupal table cell containing ['data'] but just give some errors.
If you go to see the class Table you will see an example using the colspan
in the '#wrapper_attributes'
but it seems not works for the '#header'
I can obtain a similar output just adding an empty header column like this:
// The table header.
$header = [
$this->t('Name'),
$this->t('Description'),
$this->t('Weight'),
'',
$this->t('Package'),
];
This will give something like this:
But I think that the correct way is adding the colspan property to the header.
Maybe I'm missing something or we just need to wait for Multi level (multirow) header for table FAPI element to use the colspan in the table header?