Angular 계층형 그리드 다중 열 헤더 개요
IgxHierarchicalGrid supports multi-column headers which allows you to group columns by placing them under a common multi headers. Each multi-column headers group could be a representation of combinations between other groups or columns within the Material UI grid.
Angular Hierarchical Grid Multi-column Headers Overview Example
The declaration of Multi-column header could be achieved by wrapping a set of columns into igx-column-group component with header title passed.
<igx-hierarchical-grid [data]="localdata" [moving]="true" [allowFiltering]="true">
<igx-column field="CustomerID" sortable="true" resizable="true"></igx-column>
<igx-column-group header="Address Information">
<igx-column-group header="Location">
<igx-column field="Address" sortable="true" resizable="true"></igx-column>
<igx-column field="City" sortable="true" resizable="true"></igx-column>
<igx-column field="PostalCode" sortable="true" resizable="true"></igx-column>
<igx-column field="Country" sortable="true" resizable="true"></igx-column>
</igx-column-group>
<igx-column-group header="Contact Information">
<igx-column field="Phone" sortable="true" resizable="true"></igx-column>
<igx-column field="Fax" sortable="true" resizable="true"></igx-column>
</igx-column-group>
</igx-column-group>
</igx-hierarchical-grid>
For achieving n-th level of nested headers, the declaration above should be followed. So by nesting igx-column-group leads to the desired result.
<igx-hierarchical-grid [data]="localdata" [allowFiltering]="true" [moving]="true">
<igx-column field="CustomerID" sortable="true" resizable="true"></igx-column>
<igx-column-group pinned]="false" header="General Information">
<igx-column field="CompanyName" sortable="true" resizable="true"></igx-column>
<igx-column-group header="Person Details">
<igx-column field="ContactName" sortable="true" resizable="true"></igx-column>
<igx-column field="ContactTitle" sortable="true" resizable="true"></igx-column>
</igx-column-group>
</igx-column-group>
</igx-hierarchical-grid>
Every igx-column-group supports moving, pinning and hiding.
Note
When there is a set of columns and column groups, pinning works only for top level column parents. More specifically pinning per nested column groups or columns is not allowed.
Please note that when using Pinning with Multi-Column Headers, the entire Group gets pinned.
Moving between columns and column groups is allowed only when they are at the same level in the hierarchy and both are in the same group.
When columns/column-groups are not wrapped by current group which means they are top level columns, moving is allowed between whole visible columns.
<igx-hierarchical-grid [data]="localdata" [allowFiltering]="true" [moving]="true">
<igx-column field="CustomerID" sortable="true" resizable="true"></igx-column>
<igx-column-group [pinned]="false" header="General Information">
<igx-column field="CompanyName" sortable="true" resizable="true"></igx-column>
<igx-column-group header="Person Details">
<igx-column field="ContactName" sortable="true" resizable="true"></igx-column>
<igx-column field="ContactTitle" sortable="true" resizable="true"></igx-column>
</igx-column-group>
</igx-column-group>
...
</igx-hierarchical-grid>
Multi-column Header Template
Each of the column groups of the grid can be templated separately. The column group expects ng-template tag decorated with the igxHeader directive.
The ng-template is provided with the column group object as a context.
...
<igx-column-group header="General Information">
<ng-template igxHeader let-columnGroup>
{{ columnGroup.header | uppercase }}
</ng-template>
...
</igx-column-group>
...
If you want to re-use a single template for several column groups, you could set the headerTemplate property of the column group like this:
<ng-template #columnGroupHeaderTemplate let-columnGroup>
{{ columnGroup.header | uppercase }}
</ng-template>
...
<igx-column-group header="General Information" [headerTemplate]="columnGroupHeaderTemplate">
...
</igx-column-group>
<igx-column-group header="Address Information" [headerTemplate]="columnGroupHeaderTemplate">
...
</igx-column-group>
...
Note
열 헤더가 다시 템플릿화되고 그리드 이동이 활성화된 경우 템플릿 요소에서 해당 열의 draggable 속성을 false로 설정해야 적용되는 모든 이벤트를 처리할 수 있습니다!
<ng-template igxHeader>
<igx-icon [attr.draggable]="false" (click)="onClick()"></igx-icon>
</ng-template>
다음 샘플은 헤더 템플릿을 사용하여 축소 가능한 열 그룹을 구현하는 방법을 보여줍니다.
스타일링
To get started with styling the sorting behavior, we need to import the index file, where all the theme functions and component mixins live:
@use "igniteui-angular/theming" as *;
// IMPORTANT: Prior to Ignite UI for Angular version 13 use:
// @import '~igniteui-angular/lib/core/styles/themes/index';
Following the simplest approach, we create a new theme that extends the grid-theme and accepts the $header-background, $header-text-color, $header-border-width, $header-border-style and $header-border-color parameters.
$custom-theme: grid-theme(
$header-background: #e0f3ff,
$header-text-color: #e41c77,
$header-border-width: 1px,
$header-border-style: solid,
$header-border-color: rgba(0, 0, 0, 0.08)
);
Note
Instead of hardcoding the color values like we just did, we can achieve greater flexibility in terms of colors by using the palette and color functions. Please refer to Palettes topic for detailed guidance on how to use them.
마지막 단계는 구성요소 믹스인을 포함하는 것입니다.
@include css-vars($custom-theme);
Demo
Note
The sample will not be affected by the selected global theme from Change Theme.