React Hierarchical Grid Column Selection Overview
The React Hierarchical Grid Column Selection feature in Ignite UI for React offers a simplified and Excel-like way to select and highlight an entire column with a single click. It can be enabled through the columnSelection
input. Thanks to the rich API, the feature allows for easy manipulation of the selection state, data extraction from the selected fractions, data analysis operations, and visualizations.
React Hierarchical Grid Column Selection Example
The sample below demonstrates the three types of IgrHierarchicalGrid
's column selection behavior. Use the column selection dropdown below to enable each of the available selection modes.
*Photo and Debut are with disabled column selection.
import React from 'react' ;
import ReactDOM from 'react-dom/client' ;
import './index.css' ;
import { IgrPropertyEditorPanelModule } from "@infragistics/igniteui-react-layouts" ;
import { IgrHierarchicalGridModule } from "@infragistics/igniteui-react-grids" ;
import { IgrPropertyEditorPanel, IgrPropertyEditorPropertyDescription } from "@infragistics/igniteui-react-layouts" ;
import { IgrHierarchicalGrid, IgrColumn, IgrRowIsland } from "@infragistics/igniteui-react-grids" ;
import { ComponentRenderer, PropertyEditorPanelDescriptionModule, WebHierarchicalGridDescriptionModule } from "@infragistics/igniteui-react-core" ;
import SingersData from './SingersData.json' ;
import "@infragistics/igniteui-react-grids/grids/combined" ;
import "@infragistics/igniteui-react-grids/grids/themes/light/bootstrap.css" ;
import 'igniteui-webcomponents/themes/light/bootstrap.css' ;
const mods : any [] = [
IgrPropertyEditorPanelModule,
IgrHierarchicalGridModule
];
mods.forEach((m) => m.register());
export default class Sample extends React.Component <any, any> {
private propertyEditor: IgrPropertyEditorPanel
private propertyEditorRef(r: IgrPropertyEditorPanel) {
this .propertyEditor = r;
this .setState({});
}
private columnSelectionEditor: IgrPropertyEditorPropertyDescription
private hierarchicalGrid: IgrHierarchicalGrid
private hierarchicalGridRef(r: IgrHierarchicalGrid) {
this .hierarchicalGrid = r;
this .setState({});
}
constructor (props: any ) {
super (props);
this .propertyEditorRef = this .propertyEditorRef.bind(this );
this .hierarchicalGridRef = this .hierarchicalGridRef.bind(this );
}
public render (): JSX .Element {
return (
<div className ="container sample ig-typography" >
<div className ="options vertical" >
<IgrPropertyEditorPanel
ref ={this.propertyEditorRef}
componentRenderer ={this.renderer}
target ={this.hierarchicalGrid}
descriptionType ="WebHierarchicalGrid"
isHorizontal ="true"
isWrappingEnabled ="true" >
<IgrPropertyEditorPropertyDescription
propertyPath ="ColumnSelection"
name ="columnSelectionEditor"
label ="Column Selection" >
</IgrPropertyEditorPropertyDescription >
</IgrPropertyEditorPanel >
</div >
<div className ="container fill" >
<IgrHierarchicalGrid
autoGenerate ="false"
data ={this.singersData}
ref ={this.hierarchicalGridRef}
id ="hierarchicalGrid"
primaryKey ="ID"
allowFiltering ="true"
columnSelection ="Single" >
<IgrColumn
field ="Artist"
header ="Artist" >
</IgrColumn >
<IgrColumn
field ="Photo"
header ="Photo"
dataType ="Image"
selectable ="false" >
</IgrColumn >
<IgrColumn
field ="Debut"
header ="Debut"
dataType ="Number"
selectable ="false" >
</IgrColumn >
<IgrColumn
field ="GrammyNominations"
header ="Grammy Nominations" >
</IgrColumn >
<IgrColumn
field ="GrammyAwards"
header ="Grammy Awards" >
</IgrColumn >
<IgrRowIsland
childDataKey ="Albums"
autoGenerate ="false"
columnSelection ="Single" >
<IgrColumn
field ="Album"
header ="Album" >
</IgrColumn >
<IgrColumn
field ="LaunchDate"
header ="Launch Date"
dataType ="Date"
selectable ="false" >
</IgrColumn >
<IgrColumn
field ="BillboardReview"
header ="Billboard Review" >
</IgrColumn >
<IgrColumn
field ="USBillboard200"
header ="US Billboard 200" >
</IgrColumn >
<IgrRowIsland
childDataKey ="Songs"
autoGenerate ="false"
columnSelection ="Single" >
<IgrColumn
field ="Number"
header ="No." >
</IgrColumn >
<IgrColumn
field ="Title"
header ="Title" >
</IgrColumn >
<IgrColumn
field ="Released"
header ="Released"
dataType ="Date"
selectable ="false" >
</IgrColumn >
<IgrColumn
field ="Genre"
header ="Genre" >
</IgrColumn >
</IgrRowIsland >
</IgrRowIsland >
<IgrRowIsland
childDataKey ="Tours"
autoGenerate ="false"
columnSelection ="Single" >
<IgrColumn
field ="Tour"
header ="Tour"
selectable ="false" >
</IgrColumn >
<IgrColumn
field ="StartedOn"
header ="Started on"
selectable ="false" >
</IgrColumn >
<IgrColumn
field ="Location"
header ="Location"
selectable ="false" >
</IgrColumn >
<IgrColumn
field ="Headliner"
header ="Headliner" >
</IgrColumn >
</IgrRowIsland >
</IgrHierarchicalGrid >
</div >
</div >
);
}
private _singersData: any [] = SingersData;
public get singersData(): any [] {
return this ._singersData;
}
private _componentRenderer: ComponentRenderer = null ;
public get renderer(): ComponentRenderer {
if (this ._componentRenderer == null ) {
this ._componentRenderer = new ComponentRenderer();
var context = this ._componentRenderer.context;
PropertyEditorPanelDescriptionModule.register(context);
WebHierarchicalGridDescriptionModule.register(context);
}
return this ._componentRenderer;
}
}
const root = ReactDOM.createRoot (document.getElementById('root' ));
root.render (<Sample /> );
tsx コピー
Like this sample? Get access to our complete Ignite UI for React toolkit and start building your own apps in minutes. Download it for free.
Basic Usage
The column selection feature can be enabled through the columnSelection
input, which takes GridSelectionMode
values.
Interactions
The default selection mode is None
. If set to Single
or Multiple
, all of the presented columns will be selectable
. With that being said, in order to select a column, we just need to click on one, which will mark it as selected
. If the column is not selectable, no selection style will be applied on the header, while hovering.
The Multi Column Headers feature does not reflect on the selectable input. The ColumnGroupComponent is selectable, if at least one of its children has the selection behavior enabled. In addition, the component is marked as selected if all of its selectable descendants are selected.
*Under Location Column Group only column City is selectable.
import React from 'react' ;
import ReactDOM from 'react-dom/client' ;
import './index.css' ;
import { IgrHierarchicalGridModule, IgrColumnGroupModule } from "@infragistics/igniteui-react-grids" ;
import { IgrHierarchicalGrid, IgrColumnGroup, IgrColumn, IgrRowIsland } from "@infragistics/igniteui-react-grids" ;
import HierarchicalCustomers from './HierarchicalCustomers.json' ;
import "@infragistics/igniteui-react-grids/grids/combined" ;
import "@infragistics/igniteui-react-grids/grids/themes/light/bootstrap.css" ;
const mods : any [] = [
IgrHierarchicalGridModule,
IgrColumnGroupModule
];
mods.forEach((m) => m.register());
export default class Sample extends React.Component <any, any> {
private hierarchicalGrid1: IgrHierarchicalGrid
private hierarchicalGrid1Ref(r: IgrHierarchicalGrid) {
this .hierarchicalGrid1 = r;
this .setState({});
}
constructor (props: any ) {
super (props);
this .hierarchicalGrid1Ref = this .hierarchicalGrid1Ref.bind(this );
}
public render (): JSX .Element {
return (
<div className ="container sample ig-typography" >
<div className ="container fill" >
<IgrHierarchicalGrid
data ={this.hierarchicalCustomers}
columnSelection ="Multiple"
ref ={this.hierarchicalGrid1Ref} >
<IgrColumnGroup
header ="General Information" >
<IgrColumn
field ="Company"
header ="Company" >
</IgrColumn >
<IgrColumnGroup
header ="Personal Details" >
<IgrColumn
field ="ContactName"
header ="Name" >
</IgrColumn >
<IgrColumn
field ="ContactTitle"
header ="Title" >
</IgrColumn >
</IgrColumnGroup >
</IgrColumnGroup >
<IgrColumnGroup
header ="Address Information" >
<IgrColumnGroup
header ="Location" >
<IgrColumn
field ="Address"
header ="Address"
selectable ="false" >
</IgrColumn >
<IgrColumn
field ="City"
header ="City" >
</IgrColumn >
<IgrColumn
field ="PostalCode"
header ="Postal Code"
selectable ="false" >
</IgrColumn >
<IgrColumn
field ="Country"
header ="Country"
selectable ="false" >
</IgrColumn >
</IgrColumnGroup >
<IgrColumnGroup
header ="Contact Information" >
<IgrColumn
field ="Phone" >
</IgrColumn >
<IgrColumn
field ="Fax" >
</IgrColumn >
</IgrColumnGroup >
</IgrColumnGroup >
<IgrRowIsland
childDataKey ="Orders"
autoGenerate ="false"
columnSelection ="Multiple" >
<IgrColumnGroup
header ="Order Information" >
<IgrColumnGroup
header ="Order Details" >
<IgrColumn
field ="OrderID" >
</IgrColumn >
<IgrColumn
field ="EmployeeID" >
</IgrColumn >
<IgrColumn
field ="OrderDate"
dataType ="Date" >
</IgrColumn >
<IgrColumn
field ="RequiredDate"
dataType ="Date" >
</IgrColumn >
</IgrColumnGroup >
<IgrColumnGroup
header ="General Shipping Information" >
<IgrColumn
field ="ShippedDate"
dataType ="Date" >
</IgrColumn >
<IgrColumn
field ="ShipVia"
selectable ="false" >
</IgrColumn >
<IgrColumn
field ="Freight"
selectable ="false" >
</IgrColumn >
<IgrColumn
field ="ShipName" >
</IgrColumn >
</IgrColumnGroup >
<IgrColumnGroup
header ="Shipping Location" >
<IgrColumn
field ="ShipAddress" >
</IgrColumn >
<IgrColumn
field ="ShipCity" >
</IgrColumn >
<IgrColumn
field ="ShipPostalCode" >
</IgrColumn >
<IgrColumn
field ="ShipCountry" >
</IgrColumn >
</IgrColumnGroup >
</IgrColumnGroup >
<IgrRowIsland
childDataKey ="OrderDetails"
autoGenerate ="false"
columnSelection ="Single" >
<IgrColumn
field ="ProductID" >
</IgrColumn >
<IgrColumn
field ="UnitPrice" >
</IgrColumn >
<IgrColumn
field ="Quantity"
selectable ="false" >
</IgrColumn >
<IgrColumn
field ="Discount" >
</IgrColumn >
</IgrRowIsland >
</IgrRowIsland >
</IgrHierarchicalGrid >
</div >
</div >
);
}
private _hierarchicalCustomers: any [] = HierarchicalCustomers;
public get hierarchicalCustomers(): any [] {
return this ._hierarchicalCustomers;
}
}
const root = ReactDOM.createRoot (document.getElementById('root' ));
root.render (<Sample /> );
tsx コピー
Keyboard Combinations
The keyboard combinations are available only when the grid columnSelection input is set to multiple.
There are two scenarios for keyboard navigation of the Column Selection feature:
Multi-column selection - holding ctrl + click on every selectable header cell.
Range column selection - holding shift + click selects all selectable columns in between.
API Manipulations
The API provides some additional capabilities when it comes to the non-visible columns such that, every hidden column could be marked as selected
by setting the corresponding setter .
The above statement also applies to the ColumnGroupComponent, except that when the selected property is changed it changes the state of its descendants.
More information regarding the API manipulations could be found in the API References section.
Styling
In addition to the predefined themes, the grid could be further customized by setting some of the available CSS properties .
In case you would like to change some of the colors, you need to set a class
for the grid first:
<IgrHierarchicalGrid className ="grid" > </IgrHierarchicalGrid >
tsx
Then set the related CSS properties to this class:
.grid {
--ig-grid-row-selected-background : #0062A3 ;
--ig-grid-row-selected-text-color : #ecaa53 ;
--ig-grid-row-selected-hover-background : #0062A3 ;
--ig-grid-header -selected-text-color : #ecaa53 ;
--ig-grid-header -selected-background : #0062A3 ;
--ig-grid-row-selected-hover-text-color : #ecaa53 ;
--ig-grid-row-selected-hover-background : #0062A3 ;
}
css
Demo
import React from 'react' ;
import ReactDOM from 'react-dom/client' ;
import './index.css' ;
import { IgrHierarchicalGridModule } from "@infragistics/igniteui-react-grids" ;
import { IgrHierarchicalGrid, IgrColumn, IgrRowIsland } from "@infragistics/igniteui-react-grids" ;
import SingersData from './SingersData.json' ;
import "@infragistics/igniteui-react-grids/grids/combined" ;
import "@infragistics/igniteui-react-grids/grids/themes/light/bootstrap.css" ;
const mods : any [] = [
IgrHierarchicalGridModule
];
mods.forEach((m) => m.register());
export default class Sample extends React.Component <any, any> {
private grid: IgrHierarchicalGrid
private gridRef(r: IgrHierarchicalGrid) {
this .grid = r;
this .setState({});
}
constructor (props: any ) {
super (props);
this .gridRef = this .gridRef.bind(this );
}
public render (): JSX .Element {
return (
<div className ="container sample ig-typography" >
<div className ="container fill" >
<IgrHierarchicalGrid
autoGenerate ="false"
data ={this.singersData}
ref ={this.gridRef}
id ="grid"
primaryKey ="ID"
allowFiltering ="true"
columnSelection ="Single" >
<IgrColumn
field ="Artist"
header ="Artist" >
</IgrColumn >
<IgrColumn
field ="Photo"
header ="Photo"
dataType ="Image"
selectable ="false" >
</IgrColumn >
<IgrColumn
field ="Debut"
header ="Debut"
dataType ="Number"
selectable ="false" >
</IgrColumn >
<IgrColumn
field ="GrammyNominations"
header ="Grammy Nominations" >
</IgrColumn >
<IgrColumn
field ="GrammyAwards"
header ="Grammy Awards" >
</IgrColumn >
<IgrRowIsland
childDataKey ="Albums"
autoGenerate ="false"
columnSelection ="Multiple" >
<IgrColumn
field ="Album"
header ="Album" >
</IgrColumn >
<IgrColumn
field ="LaunchDate"
header ="Launch Date"
dataType ="Date"
selectable ="false" >
</IgrColumn >
<IgrColumn
field ="BillboardReview"
header ="Billboard Review" >
</IgrColumn >
<IgrColumn
field ="USBillboard200"
header ="US Billboard 200" >
</IgrColumn >
<IgrRowIsland
childDataKey ="Songs"
autoGenerate ="false"
columnSelection ="Multiple" >
<IgrColumn
field ="Number"
header ="No." >
</IgrColumn >
<IgrColumn
field ="Title"
header ="Title" >
</IgrColumn >
<IgrColumn
field ="Released"
header ="Released"
dataType ="Date"
selectable ="false" >
</IgrColumn >
<IgrColumn
field ="Genre"
header ="Genre" >
</IgrColumn >
</IgrRowIsland >
</IgrRowIsland >
<IgrRowIsland
childDataKey ="Tours"
autoGenerate ="false"
columnSelection ="Single" >
<IgrColumn
field ="Tour"
header ="Tour"
selectable ="false" >
</IgrColumn >
<IgrColumn
field ="StartedOn"
header ="Started on"
selectable ="false" >
</IgrColumn >
<IgrColumn
field ="Location"
header ="Location"
selectable ="false" >
</IgrColumn >
<IgrColumn
field ="Headliner"
header ="Headliner" >
</IgrColumn >
</IgrRowIsland >
</IgrHierarchicalGrid >
</div >
</div >
);
}
private _singersData: any [] = SingersData;
public get singersData(): any [] {
return this ._singersData;
}
}
const root = ReactDOM.createRoot (document.getElementById('root' ));
root.render (<Sample /> );
tsx コピー
#grid {
--ig-grid-row-selected-background : #0062A3 ;
--ig-grid-row-selected-text-color : #ecaa53 ;
--ig-grid-row-selected-hover-background : #0062A3 ;
--ig-grid-header -selected-text-color : #ecaa53 ;
--ig-grid-header -selected-background : #0062A3 ;
--ig-grid-row-selected-hover-text-color : #ecaa53 ;
--ig-grid-row-selected-hover-background : #0062A3 ;
}
css コピー
API References
The column selection UI has a few more APIs to explore, which are listed below.
IgrHierarchicalGrid
properties:
IgrColumn
properties:
columnGroup
properties:
IgrHierarchicalGrid
events:
Additional Resources
Our community is active and always welcoming to new ideas.