Class logic

Responsive has three modes of operation for controlling the visibility of columns in a table:

  • Automatic - whereby Responsive will automatically determine if a columns should be shown or not
  • Manual - where you tell Responsive what columns to show on what screen sizes.
  • Priority - Using columns.responsivePriority to tell Responsive which columns should be given visibility priority - see priority documentation - (2.0.0).

These three modes are not mutually exclusive in a table, columns of all three types can be used in a single table.

Manual mode is triggered by assigning a specific class to a column - one which matches a set of logic rules for the breakpoints defined in Responsive. This is fully detailed below. The class can be added either to the plain HTML table before the DataTable is initialised, or using the DataTables columns.className option.

If Responsive does not detect a class name for a column that matches a breakpoint, or one of the special cases noted below (all, none and control) the column visibility will be controlled automatically, with the column priority defining the hiding order.

Breakpoints

To define which columns are displayed on screen for different screen sizes, Responsive has the concept of breakpoints. A breakpoint is a width, in pixels, of the browser viewport at which a breakpoint is activated. For example, a tablet breakpoint might be activated at 1024 pixels while a mobile phone breakpoint would be 480 pixels. By naming these breakpoints we can add classes to the table to control if a column is visible at those breakpoints. As an example, if a column has the class tablet it will be visible on tablet devices, but not mobile or desktop browsers.

Responsive has five breakpoints built in:

Name Width (x) range
desktop x > 1024
tablet-l (landscape) 768 < x <= 1024
tablet-p (portrait) 480 < x <= 768
mobile-l (landscape) 320 < x <= 768
mobile-p (portrait) x <= 320

Breakpoints can be customised using the responsive.breakpoints initialisation option, or by modifying the $.fn.dataTable.Responsive.breakpoints array which contains the default breakpoints.

Special classes

In addition to detecting classes based upon class name, Responsive will also detect the three following special classes:

  • all - Column will always be visible, regardless of the browser width
  • none - Column will never be visible, regardless of the browser width, but the data will be shown in a child row
  • never - Column will never be visible, regardless of the browser width and the data will not be shown in a child row (1.0.2). Note as of Responsive 2.0.0 this option is no longer required as v2 fully supports DataTables' native column visibility (i.e. use columns.visible or column().visible() to hide a column).
  • control - This is a special class which is used by the column option for the responsive.details.type option to designate which column is the control column in the table. This allows the Responsive stylesheet to add the required styling information for the column.

These classes can be used on any column and will take precedent over a breakpoint class.

Breakpoint logic operations

Using the full breakpoint names you can specify exactly which columns are to be shown at each breakpoint, but this can be quite verbose. For example if you wanted to specify a column should be visible at all breakpoints but the desktop breakpoint, four classes would be needed. You can do that, but to make complex combinations more succinct Responsive provides the ability to add logic operations to a class name for a breakpoint:

  • Prefix:
    • not- - Visible in all but the named breakpoint. For example not-desktop would be visible at mobile and tablet widths only.
    • min- - Visible in breakpoints greater or equal in width to the named breakpoint. For example min-tablet-l would be visible at tablet-l and desktop widths only.
    • max- - Visible in breakpoints less than or equal in width to the named breakpoint. For example min-tablet-p is visible at the tablet-p and mobile breakpoints.
  • Postfix:
    • The -l and -p options to designate the landscape and portrait breakpoints for tablets and mobiles are optional. This makes it easier to specify a column's visiblity for a device group. For example tablet will be visible at the tablet-l and tablet-p breakpoints.
    • The postfix (or rather, the lack of a postfix) and also be used in combination with the prefix logic operations. For example min-tablet will be visible in the tablet and mobile breakpoints.

Logic reference

The following table gives a list of the class names that will be automatically detected by Responsive.

Class name Breakpoints included in
desktop desktop
not-desktop tablet-l, tablet-p, mobile-l, mobile-p
min-desktop desktop
max-desktop desktop, tablet-l, tablet-p, mobile-l, mobile-p
tablet tablet-l, tablet-p
not-tablet desktop, mobile-l, mobile-p
min-tablet desktop, tablet-l, tablet-p
max-tablet tablet-l, tablet-p, mobile-l, mobile-p
tablet-l tablet-l
not-tablet-l desktop, tablet-p, mobile-l, mobile-p
min-tablet-l desktop, tablet-l
max-tablet-l tablet-l, tablet-p, mobile-l, mobile-p
tablet-p tablet-p
not-tablet-p desktop, tablet-l, mobile-l, mobile-p
min-tablet-p desktop, tablet-l, tablet-p
max-tablet-p tablet-p, mobile-l, mobile-p
mobile mobile-l, mobile-p
not-mobile desktop, tablet-l, tablet-p
min-mobile desktop, tablet-l, tablet-p, mobile-l, mobile-p
max-mobile mobile-l, mobile-p
mobile-l mobile-l
not-mobile-l desktop, tablet-p, tablet-l, mobile-p
min-mobile-l desktop, tablet-l, tablet-p, mobile-l
max-mobile-l mobile-l, mobile-p
mobile-p mobile-p
not-mobile-p desktop, tablet-l, tablet-p, mobile-l
min-mobile-p desktop, tablet-l, tablet-p, mobile-l, mobile-p
max-mobile-p mobile-p