Responsive tables in Drupal 8

Posted by
on September 28, 2012

I'm thrilled to announce that all HTML tables in Drupal 8 will be responsive. This is a huge win for the Drupal 8 Mobile Initiative.. This is especially important in Drupal's admin section, which traditionally featured wide tables listing recently created content, comments, users, terms, etc. I believe we struck a great balance by hiding unimportant columns by default at narrow widths, and letting user expose those columns on demand. Our technique is a simplified version of this great Filament Group article and demo.


There is a new, simple API for callers to theme_table(). Less important columns should get a RESPONSIVE_PRIORITY_MEDIUM class or a RESPONSIVE_PRIORITY_LOW class in their $header array. Both of these column types are hidden for narrow devices; MEDIUM shows up for tablet widths, and LOW columns join the party for desktop widths. Columns with no responsive class are assumed to be essential and always shown. Hidden colmns can always be exposed on demand by the user by clicking a 'Show all columns' link.

Here is an example from admin/content (

// Build the sortable table header.<br />  $header = array(<br />    'title' =&gt; array(<br />      'data' =&gt; t('Title'),<br />      'field' =&gt; 'n.title',<br />    ),<br />    'type' =&gt; array(<br />      'data' =&gt; t('Content type'),<br />      'field' =&gt; 'n.type',<br />      'class' =&gt; array(RESPONSIVE_PRIORITY_MEDIUM),<br />    ),<br />    'author' =&gt; array(<br />      'data' =&gt; t('Author'),<br />      'class' =&gt; array(RESPONSIVE_PRIORITY_LOW),<br />    ),<br />    'status' =&gt; array(<br />      'data' =&gt; t('Status'),<br />      'field' =&gt; 'n.status',<br />    ),<br />    'changed' =&gt; array(<br />      'data' =&gt; t('Updated'),<br />      'field' =&gt; 'n.changed',<br />      'sort' =&gt; 'desc',<br />      'class' =&gt; array(RESPONSIVE_PRIORITY_LOW)<br />    ,)<br />  );

Themes need to add media queries to their CSS in order to support this feature. See core/themes/stark/css/layout.css for an example.

Folks might want to help out or follow along as we add responsive table support to Views.


Sign up for our developer Blog Newsletter


Add comment

By submitting this form, you accept the Mollom privacy policy.