I am trying to create a table in a Drupal 8 form and would like to set grid-based column width similar to Boostrap or any other front-end framework, i.e. each column should have a weight out of 12. Say I have three columns, two should have 5/12 each and one should be 2/12.
I am running into two problems:
- How do I apply whatever properties I'm using to the cell/column, and not the element inside?
- Are there any classes that I can out out of the box, without installing Bootstrap or another framework?
My current code looks like this (the class
col-sm-5 is an example from Bootstrap, it doesn't actually work, and if it did it would be applied to the text field):
$test_field_array = array( 'col1' => array( '#type' => 'textfield', '#attributes' => array( 'class' => array('col-sm-5'), ), '#title' => 'Field1', '#title_display' => 'invisible', ), 'col2' => array( '#type' => 'textfield', '#title' => 'Field2', '#title_display' => 'invisible', ), 'col3' => array( ), ); $form['my_table']['fields'] = array( '#type' => 'table', '#header' => array( $this->t('col1'), $this->t('col2'), $this->t('col3'), ), '#empty' => t('No rows found'), ); $form['my_table']['fields'] = $test_field_array;