Row Grouping Expanded Collapsed Behaviour

Summary

  • Row Groups in AdapTable can be configured to open as Expanded or Collapsed
  • Users are able to set exceptions to the default for certain Row Groups
  • The same functionality is available in both Table and Pivot Layouts

Developers can configure, when a Layout loads, the collapsed / expanded behaviour for Row Groups.

This is done on a per-Layout basis using the RowGroupValues property in the Base Layout object.

This behaviour is available - and identical - in both - Table Layouts and Pivot Layouts.

Note

Something very similar is available for Column Groups using the ColumnGroupValues property

Deep Dive

Understanding the RowGroupValues Object

There are 4 posible use cases for setting expanded / collapsed behaviour:

Use CaseDefault BehaviourProvide Exceptions
All Groups are always exandedalways-expanded
All Groups are always collapsedalways-collapsed
All Groups are expanded, but exceptions listedexpanded
All Groups are collapsed, but exceptions listedcollapsed

Consistent Behaviour

Each Layout can specify whether all Row Groups are expanded, or are all collapsed, whenever it opens.

This is done via the RowGroupDefaultBehavior property in RowGroupValues which can be set to one of 2 values:

  • always-expanded - every Row Group is always expanded whenever the Layout is selected
  • always-collapsed - every Row Group is always collapsed whenever the Layout is selected
Row Grouping: Setting Default Behaviour
Fork
  • This demo defines 2 Table Layouts in which Row Group behaviour is set, to show no exceptions, when the Layout opens, by configuring the RowGroupValues property:
    • Always Expanded has RowGroupDefaultBehavior set to always-expanded so all Row Groups are open
    • Always Collapsed has RowGroupDefaultBehavior set to always-collapsed so all Row Groups are closed

Listing Exceptions

Layouts also offer a more fine-grained approach to Row Group expanded and collapsed behaviour.

Developers can configure the default behaviour, while saving exceptions on a per-Row Grouped Column basis.

This is also using the RowGroupValues object, but this time 2 properties are required:

  • RowGroupDefaultBehavior: can be set to expanded or collapsed
  • GroupKeys: contains RowGroupedColumns (array of ColIds) and ExceptionGroupKeys (array of Col values)

One Row Group Column

When there is just one Column being Row-Grouped, it is straightforward to set the Exceptions.

// Set default behaviour of collapsed with 2 exceptions when grouping by Language
RowGroupValues: {
  RowGroupDefaultBehavior: 'collapsed',
  GroupKeys: [
  {
    RowGroupedColumns: ['language'],
    ExceptionGroupKeys: [['TypeScript'],['JavaScript']],
  }],
}
Row Grouping Behaviour: Single Row Grouping
Fork
  • In this demo we set the RowGroupDefaultBehavior with exceptions for single Row Grouped Columns:
  • Single Grouping Collapsed Layout has behaviour set to collapsed with exceptions for 2 Columns:
    • Language column - exceptions for "JavaScript" and "HTML"
    • License column - exception for "Other"
  • Single Grouping Expanded Layout has behaviour set to expanded with exception in Language column: "JavaScript"
Try It Out
  • In Single Grouping Collapsed Layout ungroup by Language and then group by License and note that the exception for "Other" is applied

Many Row Group Columns

When there is more than one Column being Row-Grouped, the Exceptions need to be set differently.

The ExceptionGroupKeys should contain a comma separated list to match the columns.

Note

  • This use case deals with multi row grouped columns in one "Group" Column (i.e. RowGroupDisplayType is single)
  • See below for setting exceptions when each Row Group is in its own Column (i.e. RowGroupDisplayType is multi)
RowGroupValues: {
  RowGroupDefaultBehavior: 'collapsed',
  GroupKeys: [
    {
      RowGroupedColumns: ['language', 'license'],
      ExceptionGroupKeys: [['HTML'], ['HTML', 'Other'], ['JavaScript'] ],
    },
  ],
}
Row Grouping Behaviour: Multiple Row Grouping
Fork
  • In this demo we set the RowGroupDefaultBehavior with exceptions for multiple Row Grouped Columns
  • The Multiple Grouping Collapsed Layout groups by Language & Licence and behaviour set to collapsed with 3 exceptions: 'JavaScript', 'JavaScript/Other', 'HTML'

Display Type Multi

Row Group exceptions are also available when using Multi Display Types.

This is when each Row Grouped Column is displayed in its own separate Column.

The syntax for GroupKeys is the same as that used when using Multi Column Grouping.

Row Grouping Behaviour: Display Type Multi
Fork
  • In this demo we have provided 2 Layouts with RowGroupDisplayType of 'multi', with grouping on Language and License columns, and default behaviour of "collapsed":
    • In Multi TypeScript Layout we provide an exception for ["TypeScript"] (so that just that is expanded)
    • In Multi HTML Other Layout we provide an exceptions for ["HTML"] and ["HTML", "Other"] (so that just they are expanded)

Pivot Layouts

The expand / collapse behaviour is exactly the same for Pivot Layouts.

You can either set a consistent behaviour or allow (and provide) exceptions to be saved.

Row Grouping Behaviour: Pivot Layouts
Fork
  • In this demo we have provided Pivot 2 Layouts with grouping on Language and License columns:
    • Pivot Layout Consistent has default behaviour of "always-expanded" so every group is expanded
    • Pivot Layout Exceptions has default behaviour of "collapsed" but with initial exceptions for JavaScript and HTML (so that they are both expanded)
Try It Out
  • Close some groups in Pivot Layout Consistent and then switch Layouts and back and note that the Groups are expanded again when the Layout is reloaded
  • Close /expand some groups in Pivot Layout Expanded and note that these changes are re-rendered when the Layout is reloaded