Web Components Tree Grid Collapsible Column Groups Overview
The Ignite UI for Web Components Collapsible Column Groups feature in Web Components Tree Grid allows you to organize and manage multiple levels of nested columns and column groups in the IgcTreeGridComponent by grouping them together and providing the option to collapse or expand these groups for improved data visualization and navigation.
Web Components Tree Grid Collapsible Column Groups Example
<!DOCTYPE html><html><head><title>Sample | Ignite UI | Web Components | infragistics</title><metacharset="UTF-8" /><linkrel="shortcut icon"href="https://static.infragistics.com/xplatform/images/browsers/wc.png" ><linkrel="stylesheet"href="https://fonts.googleapis.com/icon?family=Material+Icons" /><linkrel="stylesheet"href="https://fonts.googleapis.com/css?family=Kanit&display=swap" /><linkrel="stylesheet"href="https://fonts.googleapis.com/css?family=Titillium Web" /><linkrel="stylesheet"href="https://static.infragistics.com/xplatform/css/samples/shared.v8.css" /><linkrel="stylesheet"href="/src/index.css"type="text/css" /></head><body><divid="root"><divclass="container sample ig-typography"><divclass="container fill"><igc-tree-gridauto-generate="false"name="treeGrid"id="treeGrid"id="treeGrid"primary-key="ID"foreign-key="ParentID"moving="true"row-selection="none"><igc-column-groupheader="General Information"collapsible="true"expanded="false"pinned="false"><igc-columnfield="Name"header="Full Name"data-type="string"sortable="true"resizable="true"width="200"visible-when-collapsed="false"></igc-column><igc-columnfield="LastName"header="Last Name"data-type="string"sortable="true"resizable="true"width="200"visible-when-collapsed="true"></igc-column><igc-columnfield="Title"width="250"data-type="string"sortable="true"resizable="true"></igc-column><igc-columnfield="ID"data-type="number"resizable="true"filterable="false"visible-when-collapsed="false"></igc-column><igc-columnfield="HireDate"data-type="date"sortable="true"resizable="true"visible-when-collapsed="false"></igc-column><igc-columnfield="Age"data-type="number"sortable="true"resizable="true"visible-when-collapsed="false"></igc-column></igc-column-group><igc-column-groupheader="Address Information"><igc-column-groupheader="Location"collapsible="true"><igc-columnfield="FullAddress"width="300"data-type="string"sortable="true"resizable="true"visible-when-collapsed="true"></igc-column><igc-columnfield="Country"data-type="string"sortable="true"resizable="true"visible-when-collapsed="false"></igc-column><igc-columnfield="City"data-type="string"sortable="true"resizable="true"visible-when-collapsed="false"></igc-column><igc-columnfield="Address"data-type="string"sortable="true"resizable="true"visible-when-collapsed="false"></igc-column></igc-column-group><igc-column-groupheader="Contact Information"><igc-columnfield="Phone"data-type="string"sortable="true"resizable="true"></igc-column><igc-columnfield="Fax"data-type="string"sortable="true"resizable="true"></igc-column><igc-columnfield="PostalCode"data-type="string"sortable="true"resizable="true"></igc-column></igc-column-group></igc-column-group></igc-tree-grid></div></div></div><!-- This script is needed only for parcel and it will be excluded for webpack -->
<% if (false) { %><scriptsrc="src/index.ts"></script><% } %>
</body></html>html
Like this sample? Get access to our complete Ignite UI for Web Components toolkit and start building your own apps in minutes. Download it for free.
Setup
To get started with the IgcTreeGridComponent and the Collapsible multi-column headers feature, first you need to install Ignite UI for Web Components by typing the following command:
For a complete introduction to the Ignite UI for Web Components, read the getting started topic.
Also, we strongly suggest that you take a brief look at multi-column headers topic, to see more detailed information on how to setup the column groups in your grid.
Usage
Collapsible Column Groups is a part of the multi-column headers feature which provides a way to collapse/expand a column group to a smaller set of data. When a column group is collapsed, a subset of the columns will be shown to the end-user and the other child columns of the group will hide. Each collapsed/expanded column can be bound to the grid data source, or it may be unbound, thus calculated.
In order to define a column group as collapsible, you need to set the Collapsible property on the columnGroup to true.
You need to define the property visibleWhenCollapsed to at least two child columns. At least one column must be visible when the group is collapsed (visibleWhenCollapsed set to true) and at least one column must be hidden when the group is expanded (visibleWhenCollapsed set to false), otherwise the collapsible functionality will be disabled. If visibleWhenCollapsed is not specified for some of the child columns, then this column will be always visible regardless of whether the parent state is expanded or collapsed.
Let's see the markup below:
<igc-column-groupheader="Customer Information"collapsible="true"><!-- Initially the column groups will be expanded---><!--The column below will be visible when its parent is collapsed--><igc-columnfield="CustomerName"header="Fullname"data-type="String"visible-when-collapsed="true"></igc-column><!--The three columns below will be visible when its parent is expanded--><igc-columnfield="CustomerID"header="Customer ID"data-type="String"visible-when-collapsed="false"></igc-column><igc-columnfield="FirstName"header="First Name"data-type="String"visible-when-collapsed="false"></igc-column><igc-columnfield="LastName"header="Last Name"data-type="String"visible-when-collapsed="false"></igc-column><igc-column-groupheader="Customer Address"><!--This column visibility will not be changed based on parent expand/collapsed state--><igc-columnfield="Country"header="Country"data-type="String"sortable="true"></igc-column><igc-columnfield="City"header="City"data-type="String"sortable="true"></igc-column></igc-column-group></igc-column-group>html
To summarize, every child column has three states:
Can be always visible, no matter the expanded state of its parent.
Can be visible, when its parent is collapsed.
Can be hidden, when its parent is collapsed.
The initial state of the column group which is specified as collapsible is Expanded set to true, but you can easily change this behavior by setting it to false.
constructor() {
var info = document.getElementById('info') as IgcColumnGroupComponent;
var address = document.getElementById('address') as IgcColumnGroupComponent;
info.collapsibleIndicatorTemplate = this.indTemplate;
address.collapsibleIndicatorTemplate = this.indTemplate;
}
public indTemplate = (ctx: IgcColumnTemplateContext) => {
return html`<igc-iconname="${ctx.column.expanded ? 'remove' : 'add'}"draggable="false"></igc-icon>
`;
}
ts
Note
Please keep in mind that initially collapse group option takes precedence over column hidden - If you declared your column to be hidden using the property
hidden and you have a group defined where the same column should be shown, the column will be shown.