Skip to content

Hide columns when narrow ​

Since 1.6.0

ColumnDef.hideBelow, the responsiveColumns option, the columnsResponsiveChanged event and getResponsiveHiddenColumns() are available since 1.6.0.

To hide less important columns automatically on a narrow screen, give a column hideBelow (px) and turn on responsiveColumns. When the box that holds the grid gets narrower than hideBelow, the column hides, and it comes back when there is room again.

ts
const options: GridOptions<Member> = {
  columns: [
    { id: 'name', title: 'Name', width: 120 },
    { id: 'team', title: 'Team', width: 110, hideBelow: 620 },
    { id: 'email', title: 'Email', width: 210, hideBelow: 780 },
  ],
  rows,
  rowKey: 'id',
  responsiveColumns: true, // or { debounce: 60 }
};

Rules ​

  • With responsiveColumns off (the default) hideBelow is ignored. If you do not turn it on, the DOM and the behavior stay as they are.
  • The reference is the width of the box that holds the grid, not the browser window. A ResizeObserver reports changes, and the grid waits debounce ms (default 100) after the last change and then rebuilds once. The first draw does not wait.
  • Columns the user hid stay hidden. They do not return when the width grows, and if the user hides a column that is currently hidden by width, that choice is kept.
  • Columns hidden by width are not written to getColumnState(). Restoring a saved state on a screen of another width does not carry the hiding along.
  • A pinned column hides only when you set hideBelow on it yourself.
  • The column menu and the column toolbar chips show only what the user chose to hide (a chip hidden by width is shown in italics).

Checking the result ​

ts
api.on('columnsResponsiveChanged', ({ hidden }) => {
  console.log('hidden by width', hidden); // ['team', 'email']
});

api.getResponsiveHiddenColumns(); // column ids hidden by width right now (user-hidden columns are not listed)
NameDescription
ColumnDef.hideBelowHides the column when the box is narrower than this value (px). A number of 0 or more.
responsiveColumnstrue or { debounce } (ms, default 100). Default false.
columnsResponsiveChanged eventWhen the set of columns hidden by width changes: { hidden: string[] }.
getResponsiveHiddenColumns()An array of the column ids hidden by width.

Invalid values (a negative hideBelow, or a responsiveColumns object with an unknown key) fail with invalid-option when the grid is created.

Example: Hide some columns when the grid gets narrow