Web Components Hierarchical Grid Conditional Styling
The Ignite UI for Web Components Conditional Styling feature in Web Components Hierarchical Grid allows custom styling on a row or cell level. The IgcHierarchicalGridComponent Conditional Styling functionality is used to visually emphasize or highlight data that meets certain criteria, making it easier for users to identify important information or trends within the grid.
Hierarchical Grid Conditional Row Styling
The IgcHierarchicalGridComponent component in Ignite UI for Web Components provides two ways to conditional styling of rows based on custom rules.
constructor() {
var grid = this.grid = document.getElementById('grid') as IgcHierarchicalGrid;
grid.rowClasses = this.rowClasses;
}
ts
The rowClasses input accepts an object literal, containing key-value pairs, where the key is the name of the CSS class, while the value is either a callback function that returns a boolean, or boolean value.
<!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-hierarchical-gridauto-generate="false"primary-key="ID"name="hierarchicalGrid1"id="hierarchicalGrid1"><igc-columnfield="Artist"header="Artist"data-type="string"resizable="true"></igc-column><igc-columnfield="Photo"header="Photo"data-type="image"min-width="115px"resizable="true"></igc-column><igc-columnfield="Debut"header="Debut"data-type="number"min-width="88px"max-width="230px"resizable="true"></igc-column><igc-columnfield="GrammyNominations"header="Grammy Nominations"data-type="string"resizable="true"></igc-column><igc-columnfield="GrammyAwards"header="Grammy Awards"data-type="string"resizable="true"></igc-column><igc-row-islandchild-data-key="Albums"auto-generate="false"name="rowIsland1"id="rowIsland1"><igc-columnfield="Album"header="Album"data-type="string"resizable="true"></igc-column><igc-columnfield="LaunchDate"header="Launch Date"data-type="date"resizable="true"></igc-column><igc-columnfield="BillboardReview"header="Billboard Review"data-type="string"resizable="true"></igc-column><igc-columnfield="USBillboard200"header="US Billboard 200"data-type="string"resizable="true"></igc-column><igc-row-islandchild-data-key="Songs"auto-generate="false"name="rowIsland2"id="rowIsland2"><igc-columnfield="Number"header="No."data-type="string"resizable="true"></igc-column><igc-columnfield="Title"header="Title"data-type="string"resizable="true"></igc-column><igc-columnfield="Released"header="Released"data-type="string"resizable="true"></igc-column><igc-columnfield="Genre"header="Genre"data-type="string"resizable="true"></igc-column></igc-row-island></igc-row-island><igc-row-islandchild-data-key="Tours"auto-generate="false"name="rowIsland3"id="rowIsland3"><igc-columnfield="Tour"header="Tour"data-type="string"resizable="true"></igc-column><igc-columnfield="StartedOn"header="Started on"data-type="string"resizable="true"></igc-column><igc-columnfield="Location"header="Location"data-type="string"resizable="true"></igc-column><igc-columnfield="Headliner"header="Headliner"data-type="string"resizable="true"></igc-column></igc-row-island></igc-hierarchical-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.
Using Row Styles
The IgcHierarchicalGridComponent control exposes the rowStyles property which allows conditional styling of the data rows. Similar to rowClasses it accepts an object literal where the keys are style properties and the values are expressions for evaluation. Also, you can apply regular styling (without any conditions).
<!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-hierarchical-gridauto-generate="false"primary-key="ID"name="hierarchicalGrid1"id="hierarchicalGrid1"><igc-columnfield="Artist"header="Artist"data-type="string"resizable="true"></igc-column><igc-columnfield="Photo"header="Photo"data-type="image"min-width="115px"resizable="true"></igc-column><igc-columnfield="Debut"header="Debut"data-type="number"min-width="88px"max-width="230px"resizable="true"></igc-column><igc-columnfield="GrammyNominations"header="Grammy Nominations"data-type="string"resizable="true"></igc-column><igc-columnfield="GrammyAwards"header="Grammy Awards"data-type="string"resizable="true"></igc-column><igc-row-islandchild-data-key="Albums"auto-generate="false"name="rowIsland1"id="rowIsland1"><igc-columnfield="Album"header="Album"data-type="string"resizable="true"></igc-column><igc-columnfield="LaunchDate"header="Launch Date"data-type="date"resizable="true"></igc-column><igc-columnfield="BillboardReview"header="Billboard Review"data-type="string"resizable="true"></igc-column><igc-columnfield="USBillboard200"header="US Billboard 200"data-type="string"resizable="true"></igc-column><igc-row-islandchild-data-key="Songs"auto-generate="false"><igc-columnfield="Number"header="No."data-type="string"resizable="true"></igc-column><igc-columnfield="Title"header="Title"data-type="string"resizable="true"></igc-column><igc-columnfield="Released"header="Released"data-type="string"resizable="true"></igc-column><igc-columnfield="Genre"header="Genre"data-type="string"resizable="true"></igc-column></igc-row-island></igc-row-island><igc-row-islandchild-data-key="Tours"auto-generate="false"><igc-columnfield="Tour"header="Tour"data-type="string"resizable="true"></igc-column><igc-columnfield="StartedOn"header="Started on"data-type="string"resizable="true"></igc-column><igc-columnfield="Location"header="Location"data-type="string"resizable="true"></igc-column><igc-columnfield="Headliner"header="Headliner"data-type="string"resizable="true"></igc-column></igc-row-island></igc-hierarchical-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
/* shared styles are loaded from: *//* https://static.infragistics.com/xplatform/css/samples */css
Hierarchical Grid Conditional Cell Styling
Overview
The IgcHierarchicalGridComponent component in Ignite UI for Web Components provides two ways to conditional styling of cells based on custom rules.
By setting the IgcColumnComponent input cellClasses to an object literal containing key-value pairs. The key is the name of the CSS class, while the value is either a callback function that returns a boolean, or boolean value. The result is a convenient material styling of the cell.
constructor() {
var grammyNominations = document.getElementById('grammyNominations') as IgcColumnComponent;
grammyNominations.cellClasses = this.grammyNominationsCellClassesHandler;
}
ts
The cellClasses input accepts an object literal, containing key-value pairs, where the key is the name of the CSS class, while the value is either a callback function that returns a boolean, or boolean value.
<!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-hierarchical-gridauto-generate="false"primary-key="ID"name="hierarchicalGrid1"id="hierarchicalGrid1"><igc-columnfield="Artist"header="Artist"data-type="string"resizable="true"></igc-column><igc-columnfield="Photo"header="Photo"data-type="image"min-width="115px"resizable="true"></igc-column><igc-columnfield="Debut"header="Debut"data-type="number"min-width="88px"max-width="230px"resizable="true"></igc-column><igc-columnfield="GrammyNominations"header="Grammy Nominations"data-type="string"resizable="true"name="column1"id="column1"></igc-column><igc-columnfield="GrammyAwards"header="Grammy Awards"data-type="string"resizable="true"></igc-column><igc-row-islandchild-data-key="Albums"auto-generate="false"><igc-columnfield="Album"header="Album"data-type="string"resizable="true"></igc-column><igc-columnfield="LaunchDate"header="Launch Date"data-type="date"resizable="true"></igc-column><igc-columnfield="BillboardReview"header="Billboard Review"data-type="string"resizable="true"></igc-column><igc-columnfield="USBillboard200"header="US Billboard 200"data-type="string"resizable="true"></igc-column><igc-row-islandchild-data-key="Songs"auto-generate="false"><igc-columnfield="Number"header="No."data-type="string"resizable="true"></igc-column><igc-columnfield="Title"header="Title"data-type="string"resizable="true"></igc-column><igc-columnfield="Released"header="Released"data-type="string"resizable="true"></igc-column><igc-columnfield="Genre"header="Genre"data-type="string"resizable="true"></igc-column></igc-row-island></igc-row-island><igc-row-islandchild-data-key="Tours"auto-generate="false"><igc-columnfield="Tour"header="Tour"data-type="string"resizable="true"></igc-column><igc-columnfield="StartedOn"header="Started on"data-type="string"resizable="true"></igc-column><igc-columnfield="Location"header="Location"data-type="string"resizable="true"></igc-column><igc-columnfield="Headliner"header="Headliner"data-type="string"resizable="true"></igc-column></igc-row-island></igc-hierarchical-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
/* shared styles are loaded from: *//* https://static.infragistics.com/xplatform/css/samples */.upFont {
color: green !important;
}
.downFont {
color: red !important;
}
css
By using the IgcColumnComponent input cellStyles which accepts an object literal where the keys are style properties and the values are expressions for evaluation.
The callback signature for both cellStyles and cellClasses is now changed to:
Columns expose the cellStyles property which allows conditional styling of the column cells. Similar to cellClasses it accepts an object literal where the keys are style properties and the values are expressions for evaluation. Also, you can apply regular styling with ease (without any conditions).
<!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-hierarchical-gridauto-generate="false"primary-key="ID"name="hierarchicalGrid1"id="hierarchicalGrid1"><igc-columnfield="Artist"header="Artist"data-type="string"resizable="true"name="column1"id="column1"></igc-column><igc-columnfield="HasGrammyAward"header="Has Grammy Award?"data-type="boolean"resizable="true"name="column2"id="column2"></igc-column><igc-columnfield="Photo"header="Photo"data-type="image"min-width="115px"resizable="true"name="column3"id="column3"></igc-column><igc-columnfield="Debut"header="Debut"data-type="number"min-width="88px"max-width="230px"resizable="true"name="column4"id="column4"></igc-column><igc-columnfield="GrammyNominations"header="Grammy Nominations"data-type="string"resizable="true"name="column5"id="column5"></igc-column><igc-columnfield="GrammyAwards"header="Grammy Awards"data-type="string"resizable="true"name="column6"id="column6"></igc-column><igc-row-islandchild-data-key="Albums"auto-generate="false"><igc-columnfield="Album"header="Album"data-type="string"resizable="true"></igc-column><igc-columnfield="LaunchDate"header="Launch Date"data-type="date"resizable="true"></igc-column><igc-columnfield="BillboardReview"header="Billboard Review"data-type="string"resizable="true"></igc-column><igc-columnfield="USBillboard200"header="US Billboard 200"data-type="string"resizable="true"></igc-column><igc-row-islandchild-data-key="Songs"auto-generate="false"><igc-columnfield="Number"header="No."data-type="string"resizable="true"></igc-column><igc-columnfield="Title"header="Title"data-type="string"resizable="true"></igc-column><igc-columnfield="Released"header="Released"data-type="string"resizable="true"></igc-column><igc-columnfield="Genre"header="Genre"data-type="string"resizable="true"></igc-column></igc-row-island></igc-row-island><igc-row-islandchild-data-key="Tours"auto-generate="false"><igc-columnfield="Tour"header="Tour"data-type="string"resizable="true"></igc-column><igc-columnfield="StartedOn"header="Started on"data-type="string"resizable="true"></igc-column><igc-columnfield="Location"header="Location"data-type="string"resizable="true"></igc-column><igc-columnfield="Headliner"header="Headliner"data-type="string"resizable="true"></igc-column></igc-row-island></igc-hierarchical-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
/* shared styles are loaded from: *//* https://static.infragistics.com/xplatform/css/samples */css
Known issues and limitations
If there are cells bind to the same condition (from different columns) and one cell is updated, the other cells won't be updated based on the new value, if the condition is met.
A check should be performed in order to apply the changes to the rest of the cells. The example below shows how to do that.