The Ignite UI for Web Components Data Sorting feature in Web Components Hierarchical Grid is enabled on a per-column level, meaning that the IgcHierarchicalGridComponent can have a mix of sortable and non-sortable columns. Performing Web Components sort actions enables you to change the display order of the records based on specified criteria.
Web Components Hierarchical Grid Sorting Overview Example
Additionally there is a custom contextmenu added for sorting using IgcHierarchicalGridComponent's ContextMenu Output.
<!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"sortable="true"></igc-column><igc-columnfield="Photo"header="Photo"data-type="image"></igc-column><igc-columnfield="Debut"header="Debut"data-type="number"sortable="true"></igc-column><igc-columnfield="GrammyNominations"header="Grammy Nominations"data-type="number"sortable="true"></igc-column><igc-columnfield="GrammyAwards"header="Grammy Awards"data-type="number"sortable="true"></igc-column><igc-row-islandchild-data-key="Albums"auto-generate="false"><igc-columnfield="Album"header="Album"data-type="string"sortable="true"></igc-column><igc-columnfield="LaunchDate"header="Launch Date"data-type="date"sortable="true"></igc-column><igc-columnfield="BillboardReview"header="Billboard Review"data-type="string"sortable="true"></igc-column><igc-columnfield="USBillboard200"header="US Billboard 200"data-type="string"sortable="true"></igc-column><igc-row-islandchild-data-key="Songs"auto-generate="false"><igc-columnfield="Number"header="No."data-type="string"sortable="true"></igc-column><igc-columnfield="Title"header="Title"data-type="string"sortable="true"></igc-column><igc-columnfield="Released"header="Released"data-type="date"sortable="true"></igc-column><igc-columnfield="Genre"header="Genre"data-type="string"sortable="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"sortable="true"></igc-column><igc-columnfield="StartedOn"header="Started on"data-type="string"sortable="true"></igc-column><igc-columnfield="Location"header="Location"data-type="string"sortable="true"></igc-column><igc-columnfield="Headliner"header="Headliner"data-type="string"sortable="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
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.
<!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"sortable="true"></igc-column><igc-columnfield="Photo"header="Photo"data-type="image"></igc-column><igc-columnfield="Debut"header="Debut"data-type="number"sortable="true"></igc-column><igc-columnfield="GrammyNominations"header="Grammy Nominations"data-type="number"sortable="true"></igc-column><igc-columnfield="GrammyAwards"header="Grammy Awards"data-type="number"sortable="true"></igc-column><igc-row-islandchild-data-key="Albums"auto-generate="false"><igc-columnfield="Album"header="Album"data-type="string"sortable="true"></igc-column><igc-columnfield="LaunchDate"header="Launch Date"data-type="date"sortable="true"></igc-column><igc-columnfield="BillboardReview"header="Billboard Review"data-type="string"sortable="true"></igc-column><igc-columnfield="USBillboard200"header="US Billboard 200"data-type="string"sortable="true"></igc-column><igc-row-islandchild-data-key="Songs"auto-generate="false"><igc-columnfield="Number"header="No."data-type="string"sortable="true"></igc-column><igc-columnfield="Title"header="Title"data-type="string"sortable="true"></igc-column><igc-columnfield="Released"header="Released"data-type="date"sortable="true"></igc-column><igc-columnfield="Genre"header="Genre"data-type="string"sortable="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"sortable="true"></igc-column><igc-columnfield="StartedOn"header="Started on"data-type="string"sortable="true"></igc-column><igc-columnfield="Location"header="Location"data-type="string"sortable="true"></igc-column><igc-columnfield="Headliner"header="Headliner"data-type="string"sortable="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
// Perform a case insensitive ascending sort on the ProductName column.this.hierarchicalGrid.sort([{ fieldName: 'ProductName', dir: SortingDirection.Asc, ignoreCase: true }]);
// Perform sorting on both the ProductName and Price columns.this.hierarchicalGrid.sort([
{ fieldName: 'ProductName', dir: SortingDirection.Asc, ignoreCase: true },
{ fieldName: 'Price', dir: SortingDirection.Desc }
]);
typescript
Sorting is performed using our DefaultSortingStrategy algorithm. Any IgcColumnComponent or ISortingExpression can use a custom implementation of the ISortingStrategy as a substitute algorithm. This is useful when custom sorting needs to be defined for complex template columns, or image columns, for example.
As with the filtering behavior, you can clear the sorting state by using the clearSort method:
// Removes the sorting state from the ProductName columnthis.hierarchicalGrid.clearSort('ProductName');
// Removes the sorting state from every column in the Hierarchical Gridthis.hierarchicalGrid.clearSort();
typescript
The sortStrategy of the IgcHierarchicalGridComponent is of different type compared to the sortStrategy of the IgcColumnComponent, since they work in different scopes and expose different parameters.
The sorting operation DOES NOT change the underlying data source of the IgcHierarchicalGridComponent.
If values of type string are used by a column of dataType Date, the IgcHierarchicalGridComponent won't parse them to Date objects and using IgcHierarchicalGridComponent Sorting won't work as expected. If you want to use string objects, additional logic should be implemented on an application level, in order to parse the values to Date objects.
Sorting Indicators Templates
The sorting indicator icon in the column header can be customized using a template. The following properties are available for templating the sorting indicator for any sorting state (ascending, descending, none):
constructor() {
var grid = this.grid = document.getElementById('grid') as IgcHierarchicalGridComponent;
grid.data = this.data;
grid.sortDescendingHeaderIconTemplate = this.sortDescendingHeaderIconTemplate;
}
public sortDescendingHeaderIconTemplate = (ctx: IgcGridHeaderTemplateContext) => {
return html`<igc-iconname="expand_more"></igc-icon>`;
}
ts
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:
<!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"name="hierarchicalGrid"id="hierarchicalGrid"id="hierarchicalGrid"primary-key="ID"><igc-columnfield="Artist"header="Artist"data-type="string"sortable="true"></igc-column><igc-columnfield="Photo"header="Photo"data-type="image"></igc-column><igc-columnfield="Debut"header="Debut"data-type="number"sortable="true"></igc-column><igc-columnfield="GrammyNominations"header="Grammy Nominations"data-type="number"sortable="true"></igc-column><igc-columnfield="GrammyAwards"header="Grammy Awards"data-type="number"sortable="true"></igc-column><igc-row-islandchild-data-key="Albums"auto-generate="false"><igc-columnfield="Album"header="Album"data-type="string"sortable="true"></igc-column><igc-columnfield="LaunchDate"header="Launch Date"data-type="date"sortable="true"></igc-column><igc-columnfield="BillboardReview"header="Billboard Review"data-type="string"sortable="true"></igc-column><igc-columnfield="USBillboard200"header="US Billboard 200"data-type="string"sortable="true"></igc-column><igc-row-islandchild-data-key="Songs"auto-generate="false"><igc-columnfield="Number"header="No."data-type="string"sortable="true"></igc-column><igc-columnfield="Title"header="Title"data-type="string"sortable="true"></igc-column><igc-columnfield="Released"header="Released"data-type="date"sortable="true"></igc-column><igc-columnfield="Genre"header="Genre"data-type="string"sortable="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"sortable="true"></igc-column><igc-columnfield="StartedOn"header="Started on"data-type="string"sortable="true"></igc-column><igc-columnfield="Location"header="Location"data-type="string"sortable="true"></igc-column><igc-columnfield="Headliner"header="Headliner"data-type="string"sortable="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