Responsive tables just got committed. Each $header can choose to be Essential (the default - needs no special class), RESPONSIVE_PRIORITY_MEDIUM, or RESPONSIVE_PRIORITY_LOW. For an example, this is from admin/content (node.admin.inc)

// Build the sortable table header.
  $header = array(
    'title' => array(
      'data' => t('Title'),
      'field' => 'n.title',
    ),
    'type' => array(
      'data' => t('Content type'),
      'field' => 'n.type',
      'class' => array(RESPONSIVE_PRIORITY_MEDIUM),
    ),
    'author' => array(
      'data' => t('Author'),
      'class' => array(RESPONSIVE_PRIORITY_LOW),
    ),
    'status' => array(
      'data' => t('Status'),
      'field' => 'n.status',
    ),
    'changed' => array(
      'data' => t('Updated'),
      'field' => 'n.changed',
      'sort' => 'desc',
      'class' => array(RESPONSIVE_PRIORITY_LOW)
    ,)
  );
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

sebas5384’s picture

Nice idea!

I think it doesn't need a constant for that, a simple class would be just fine, like ajax from core("use-ajax") and ctools with modals for example.

Cheers!,
Sebas.

dawehner’s picture

Status: Active » Needs review
FileSize
2.54 KB
3.25 KB
10.67 KB

Some has to explain me this feature ...
I created a table with nid, title, type and set medium to nid, and low to type.
Once i shrink my browser window i only see title and type, though i would expect nid and title,
see screenshot.

Additional to be able to expose this to users, i would suggest more something like
"responsove priority":
none => high
medium => medium
low => low

dawehner’s picture

Issue tags: +VDC

Add missing tag.

hass’s picture

What we need here is a "class per column" as I know. Views currently allows only a "class per row".

moshe weitzman’s picture

Take a look at the HTML Source and see what classes are on the header cells and row cells. If they don't match what you expect, that would explain the result ... theme_table() copies classes from header to cells so it would likely be harmless if Views adds the responsive classes to the rows as well.

hass’s picture

Is there any chance to make this a unified "class per column" feature? I have real theming need to add classes to colums in D7, too.

tim.plunkett’s picture

@hass that is clearly a separate feature request

dawehner’s picture

FileSize
19.06 KB

@hass ... Forgive me to not answer support questions in d8 issues. This is possible all the time,
but i would like to have an addition setting, as many people might not know the class names you need for responsive tables.

The actual rendered css classes are looking fine, at least for me, see screenshot.

moshe weitzman’s picture

You have a leading space in the class name. Doubt that matters but who knows. Next I would look at the media queries in the CSS and see why they are not matching against your classes. make sure to flush caches in case you have an old aggregated css in play.

dawehner’s picture

FileSize
5.24 KB

I'm confused by bartik/style.css, this explains why it works for me in the admin
interface but not on the "frontend".

/**
 * Responsive tables.
 */
@media screen and (max-width:28.125em) { /* 450px */
  th.helpful,
  td.helpful,
  th.priority-medium,
  td.priority-medium {
    display: none;
  }
}
@media screen and (max-width:45em) { /* 720px */
  th.helpful,
  td.helpful {
    display: none;
  }
}

compared to the css of seven/stark:

@media screen and (max-width:28.125em) { /* 450px */
  th.priority-low,
  td.priority-low,
  th.priority-medium,
  td.priority-medium {
    display: none;
  }
}
@media screen and (max-width:45em) { /* 720px */
  th.priority-low,
  td.priority-low {
    display: none;
  }
}

Regarding the space in front, this will be automatically fixed in
another issue, which converts the classes to Attributes objects.

Beside the css classes, i added the javascript for the responsive table js as well.

dawehner’s picture

dawehner’s picture

Status: Needs review » Fixed

Due to the core commit this works fine now, let's get this is as noone seems to have an interest in reviewing.

I really really like this new feature in core!

aspilicious’s picture

I'm interested! I like the patch!

xjm’s picture

Way cool. Thanks @moshe weitzman and @dawehner.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

kaizerking’s picture

Status: Closed (fixed) » Active

I would like to test it if back ported to D7

tim.plunkett’s picture

Status: Active » Closed (fixed)

This issue was only about supporting improvements made in core. Backporting it would mean Views would shoulder the entirety of that improvement, which I'm not sure is reasonable. Either way, please open a new feature request.

DamienMcKenna’s picture

There's always the work Dave Reid and others are putting into backporting the code for D7: http://drupal.org/project/responsive_tables