Angular Data Grid の縮小可能な列グループ
複数列ヘッダーを使用すると、複数レベルのネストされた列と列グループを使用できるため、各列グループを縮小可能 としてマークできます。縮小可能な複数列ヘッダー では、縮小/展開が可能です。現在のヘッダーの下にネストされたヘッダーを表示および非表示にします。これにより、たとえば短縮/要約された情報を示すことができます。
Angular グリッド列グループの縮小の例
import { NgModule } from "@angular/core" ;
import { FormsModule } from "@angular/forms" ;
import { BrowserModule } from "@angular/platform-browser" ;
import { BrowserAnimationsModule } from "@angular/platform-browser/animations" ;
import { AppComponent } from "./app.component" ;
import {
IgxHierarchicalGridModule,
IgxTooltipModule
} from "igniteui-angular" ;
import { HGridCollapsibleColumnGroupComponent } from "./hierarchical-grid/hierarchical-grid-collapsible-column-groups/hierarchical-grid-collapsible-column-groups.component" ;
import { IgxPreventDocumentScrollModule } from "./directives/prevent-scroll.directive" ;
@NgModule ({
bootstrap : [AppComponent],
declarations : [
AppComponent,
HGridCollapsibleColumnGroupComponent
],
imports : [
BrowserModule,
BrowserAnimationsModule,
FormsModule,
IgxPreventDocumentScrollModule,
IgxHierarchicalGridModule,
IgxTooltipModule
],
providers : [],
entryComponents : [],
schemas : []
})
export class AppModule {}
ts コピー import { Component, OnInit, ViewChild } from '@angular/core' ;
import { IgxHierarchicalGridComponent } from 'igniteui-angular' ;
import { CUSTOMERS } from '../../data/hierarchical-data' ;
@Component ({
selector : 'app-hierarchical-grid-collapsible-column-groups' ,
styleUrls : ['./hierarchical-grid-collapsible-column-groups.component.scss' ],
templateUrl : 'hierarchical-grid-collapsible-column-groups.component.html'
})
export class HGridCollapsibleColumnGroupComponent implements OnInit {
@ViewChild ('hierarchicalGrid' , { static : true })
private hierarchicalGrid: IgxHierarchicalGridComponent;
public localdata;
constructor ( ) {
}
public ngOnInit(): void {
this .localdata = CUSTOMERS;
for (const item of this .localdata) {
const names = item.ContactName.split(' ' );
item.FirstName = names[0 ];
item.LastName = names[names.length - 1 ];
item.FullAddress = `${item.Address} , ${item.City} , ${item.Country} ` ;
}
}
public getTooltipText (expanded ) {
return expanded ?
'The column is expanded! Click here to collapse.' : 'The column is collapsed! Click here to expand' ;
}
}
ts コピー <div class ="wrapper theme" >
<div class ="sample-content" >
<div class ="sample-column" >
<igx-hierarchical-grid [igxPreventDocumentScroll ]="true" #hierarchicalGrid [data ]="localdata" [moving ]="true" [height ]="'560px'" displayDensity ="compact" [allowFiltering ]="true" >
<igx-column-group [pinned ]="false" header ="General Information" [collapsible ]="true" [expanded ]="false" >
<ng-template igxCollapsibleIndicator let-column ="column" >
<igx-icon [attr.draggable ]="false" #target ="tooltipTarget" [igxTooltipTarget ]="tooltipRef" [showDelay ]="0" [hideDelay ]="0" > {{column.expanded ? 'expand_more' : 'chevron_right'}} </igx-icon >
<div #tooltipRef ="tooltip" igxTooltip >
{{getTooltipText(column.expanded)}}
</div >
</ng-template >
<igx-column field ="ContactName" header ="Full Name" dataType ="string" [sortable ]="true" [resizable ]="true" width ="200px" [visibleWhenCollapsed ]="false" > </igx-column >
<igx-column field ="LastName" header ="Last Name" dataType ="string" [sortable ]="true" [resizable ]="true" width ="200px" [visibleWhenCollapsed ]="true" > </igx-column >
<igx-column field ="ContactTitle" header ="Title" [width ]="'250px'" dataType ="string" [sortable ]="true" [resizable ]="true" > </igx-column >
<igx-column field ="CustomerID" [width ]="'140px'" [resizable ]="true" [filterable ]="false" [visibleWhenCollapsed ]="false" > </igx-column >
<igx-column field ="CompanyName" header ="Company" [width ]="'140px'" [sortable ]="true" [resizable ]="true" [visibleWhenCollapsed ]="false" > </igx-column >
<igx-column field ="Phone" dataType ="string" [width ]="'140px'" [sortable ]="true" [resizable ]="true" [visibleWhenCollapsed ]="false" > </igx-column >
</igx-column-group >
<igx-column-group header ="Address Information" >
<igx-column-group header ="Location" [collapsible ]="true" >
<ng-template igxCollapsibleIndicator let-column ="column" >
<igx-icon [attr.draggable ]="false" #target ="tooltipTarget" [igxTooltipTarget ]="tooltipRef" [showDelay ]="0" [hideDelay ]="0" > {{column.expanded ? 'expand_more' : 'chevron_right'}} </igx-icon >
<div #tooltipRef ="tooltip" igxTooltip >
<span style ="width: 200px" > {{getTooltipText(column.expanded)}}</span >
</div >
</ng-template >
<igx-column field ="FullAddress" [width ]="'300px'" dataType ="string" [sortable ]="true" [resizable ]="true" [visibleWhenCollapsed ]="true" > </igx-column >
<igx-column field ="Country" dataType ="string" [width ]="'200px'" [sortable ]="true" [resizable ]="true" [visibleWhenCollapsed ]="false" > </igx-column >
<igx-column field ="City" dataType ="string" [width ]="'200px'" [sortable ]="true" [resizable ]="true" [visibleWhenCollapsed ]="false" > </igx-column >
<igx-column field ="Address" dataType ="string" [width ]="'200px'" [sortable ]="true" [resizable ]="true" [visibleWhenCollapsed ]="false" > </igx-column >
<igx-column field ="PostalCode" dataType ="string" [width ]="'200px'" [sortable ]="true" [resizable ]="true" [visibleWhenCollapsed ]="false" > </igx-column >
</igx-column-group >
</igx-column-group >
<igx-row-island [height ]="null" [key ]="'Orders'" [autoGenerate ]="false" [moving ]="true" >
<igx-column-group header ="Order Information" >
<igx-column-group header ="Order Details" >
<igx-column field ="OrderID" [sortable ]="true" [resizable ]="true" > </igx-column >
<igx-column field ="EmployeeID" [sortable ]="true" [resizable ]="true" > </igx-column >
<igx-column field ="OrderDate" [sortable ]="true" [resizable ]="true" [dataType ]="'date'" > </igx-column >
<igx-column field ="RequiredDate" [sortable ]="true" [resizable ]="true" [dataType ]="'date'" > </igx-column >
</igx-column-group >
<igx-column-group header ="General Shipping Information" >
<igx-column field ="ShippedDate" [sortable ]="true" [resizable ]="true" [dataType ]="'date'" > </igx-column >
<igx-column field ="ShipVia" [sortable ]="true" [resizable ]="true" > </igx-column >
<igx-column field ="Freight" [sortable ]="true" [resizable ]="true" > </igx-column >
<igx-column field ="ShipName" [sortable ]="true" [resizable ]="true" > </igx-column >
</igx-column-group >
<igx-column-group header ="Shipping Location" >
<igx-column field ="ShipAddress" [sortable ]="true" [resizable ]="true" > </igx-column >
<igx-column field ="ShipCity" [sortable ]="true" [resizable ]="true" > </igx-column >
<igx-column field ="ShipPostalCode" [sortable ]="true" [resizable ]="true" > </igx-column >
<igx-column field ="ShipCountry" [sortable ]="true" [resizable ]="true" > </igx-column >
</igx-column-group >
</igx-column-group >
<igx-row-island [height ]="null" [key ]="'OrderDetails'" [autoGenerate ]="false" >
<igx-column field ="ProductID" [sortable ]="true" [resizable ]="true" > </igx-column >
<igx-column field ="UnitPrice" [sortable ]="true" [resizable ]="true" > </igx-column >
<igx-column field ="Quantity" [sortable ]="true" [resizable ]="true" > </igx-column >
<igx-column field ="Discount" [sortable ]="true" [resizable ]="true" > </igx-column >
</igx-row-island >
</igx-row-island >
</igx-hierarchical-grid >
</div >
</div >
</div >
html コピー
このサンプルが気に入りましたか? 完全な Ignite UI for Angularツールキットにアクセスして、すばやく独自のアプリの作成を開始します。無料でダウンロードできます。
構成
IgxHierarchicalGrid および縮小可能な複数列ヘッダーを使用するには、まず以下のコマンドを入力して、Ignite UI for Angular をインストールする必要があります。
ng add igniteui-angular
cmd
Ignite UI for Angular については、「はじめに 」トピックをご覧ください。
次に app.module.ts ファイルに IgxHierarchicalGridModule
をインポートします。そのため、複数列グループ のトピックを簡単に確認することを強くお勧めします。グリッドで列グループを設定する方法の詳細情報を参照してください。
使用方法
縮小可能な列グループは複数列ヘッダー機能の一部で、列グループをより小さいデータ セットに縮小/展開する方法を提供します。列グループが縮小されると、列のサブセットがエンドユーザーに表示され、グループの他の子列が非表示になります。縮小された/展開された各列は、グリッド データソースにバインドすることも、非バインドにして計算することもできます。
列グループを collapsible
に定義するには、プロパティを [collapsible]="true"
に設定する必要があり、プロパティ visibleWhenCollapsed
を少なくとも 2 つの子列に定義する必要があることに注意してください。グループが縮小されたときに少なくとも 1 列が表示され ([visibleWhenCollapsed]="true"
)、グループが展開されたときは少なくとも 1 列が非表示になります ([visibleWhenCollapsed]="false"
)。それ以外は、縮小機能は無効になります。子列の一部に visibleWhenCollapsed
が指定されていない場合、この列は、親の状態が展開または縮小されているかに関係なく常に表示されます。
それでは、以下のマークアップを見てみましょう。
<igx-column-group header ="Customer Information" [collapsible ]="true" >
<igx-column field ="CustomerName" header ="Fullname" [dataType ]="'string'" [visibleWhenCollapsed ]="true" > </igx-column >
<igx-column field ="CustomerID" header ="Customer ID" [dataType ]="'string'" [visibleWhenCollapsed ]="false" > </igx-column >
<igx-column field ="FirstName" header ="First Name" [dataType ]="'string'" [visibleWhenCollapsed ]="false" >
</igx-column >
<igx-column field ="LastName" header ="Last Name" [dataType ]="'string'" [visibleWhenCollapsed ]="false" >
</igx-column >
<igx-column-group header ="Customer Address" >
<igx-column field ="Country" header ="Country" [dataType ]="'string'" [sortable ]="true" >
</igx-column >
<igx-column field ="City" header ="City" [dataType ]="'string'" [sortable ]="true" >
</igx-column >
</igx-column-group >
</igx-column-group >
html
すべての子列にツリー状態があります。
親の展開状態に関係なく、常に表示できます。
親が展開されているときに表示できます。
親が縮小されているときに非表示にできます
縮小可能として指定されている列グループの初期状態は、[expanded]="true"
です。ただし、プロパティ [expanded]="false"
を設定することにより、この動作を簡単に変更できます。
展開 / 縮小インジケーター (ハンドル)
igxGrid のデフォルトの展開インジケーターは次のとおりです。
igxGrid のデフォルトの展開インジケーターは次のとおりです。
また、デフォルトの展開/縮小インジケーターを変更する必要がある場合は、入力プロパティまたはディレクティブを使用して、2 つの簡単な方法を提供します。
入力プロパティの使用
collapsibleIndicatorTemplate 入力プロパティを使用して、カスタムの展開/縮小テンプレートを定義し、それを各縮小可能な列グループに提供できます。以下のマークアップを確認してください。
<ng-template #indTemplate let-column ="column" >
<igx-icon [attr.draggable ]="false" > {{column.expanded ? 'remove' : 'add'}} </igx-icon >
</ng-template >
<igx-column-group header ="Customer Information" [collapsible ]="true" [collapsibleIndicatorTemplate ]="indTemplate" >
<igx-column field ="CustomerName" header ="Fullname" [dataType ]="'string'" [visibleWhenCollapsed ]="true" > </igx-column >
<igx-column field ="CustomerID" header ="Customer ID" [dataType ]="'string'" [visibleWhenCollapsed ]="false" > </igx-column >
<igx-column-group header ="Customer Address" [collapsible ]="true" [collapsibleIndicatorTemplate ]="indTemplate" >
<igx-column field ="Country" header ="Country" [dataType ]="'string'" [sortable ]="true" [visibleWhenCollapsed ]="true" > </igx-column >
<igx-column field ="City" header ="City" [dataType ]="'string'" [sortable ]="true" [visibleWhenCollapsed ]="false" > </igx-column >
</igx-column-group >
</igx-column-group >
html
igxCollapsibleIndicator ディレクティブの使用
この動作を実現する別の方法は、以下の例に示すように igxCollapsibleIndicator ディレクティブを使用することです。
<igx-column-group header ="Customer Information" [collapsible ]="true" >
<ng-template igxCollapsibleIndicator let-column ="column" >
<igx-icon [attr.draggable ]="false" > {{column.expanded ? 'remove' : 'add'}} </<igx-icon >
</ng-template >
<igx-column field ="CustomerName" header ="Fullname" [dataType ]="'string'" [visibleWhenCollapsed ]="true" > </igx-column >
<igx-column field ="CustomerID" header ="Customer ID" [dataType ]="'string'" [visibleWhenCollapsed ]="false" > </igx-column >
<igx-column-group header ="Customer Address" [collapsible ]="true" >
<igx-column field ="Country" header ="Country" [dataType ]="'string'" [sortable ]="true" [visibleWhenCollapsed ]="true" > </igx-column >
<igx-column field ="City" header ="City" [dataType ]="'string'" [sortable ]="true" [visibleWhenCollapsed ]="false" > </igx-column >
</igx-column-group >
</igx-column-group >
html
プロパティを使用して列を非表示にすると宣言した場合、最初にグループを折りたたむオプションは非表示の列よりも優先されることに注意してください。
非表示で、同じ列が表示される場所にグループが定義されている場合、列が表示されます。
API リファレンス
その他のリソース
コミュニティに参加して新しいアイデアをご提案ください。