Ignite UI for Angular の Tree Grid は、UI 操作のコンテナーとなる IgxGridToolbarComponent
機能をサポートします。Angular ツールバーは Angular コンポーネントの一番上、つまり Tree Grid にあり、水平方向のサイズと一致します。ツールバー コンテナーは、次の Tree Grid の機能、またはその他のカスタム コンテンツ用に事前定義された UI コントロールをホストできます:
列の非表示
列のピン固定
Excel エクスポート
高度なフィルタリング
ツールバーと事前定義された UI コンポーネントは、Angular イベントをサポートし、開発者向けに API を公開します。
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 { IgxPreventDocumentScrollModule } from "./directives/prevent-scroll.directive" ;
import {
IgxTreeGridModule,
IgxAvatarModule
} from "igniteui-angular" ;
import { TreeGridToolbarSample4Component } from "./tree-grid-toolbar-sample-4/tree-grid-toolbar-sample-4.component" ;
@NgModule ({
bootstrap : [AppComponent],
declarations : [
AppComponent,
TreeGridToolbarSample4Component
],
imports : [
BrowserModule,
BrowserAnimationsModule,
FormsModule,
IgxPreventDocumentScrollModule,
IgxTreeGridModule,
IgxAvatarModule
],
providers : [],
entryComponents : [],
schemas : []
})
export class AppModule {}
ts コピー import { Component } from '@angular/core' ;
import { EMPLOYEE_FLAT_AVATARS_DATA } from '../data/employees-flat-avatars' ;
@Component ({
selector : 'app-tree-grid-toolbar-sample-4' ,
styleUrls : ['./tree-grid-toolbar-sample-4.component.scss' ],
templateUrl : './tree-grid-toolbar-sample-4.component.html'
})
export class TreeGridToolbarSample4Component {
public data: any [];
constructor ( ) {
this .data = EMPLOYEE_FLAT_AVATARS_DATA();
}
}
ts コピー <div class ="grid__wrapper" >
<igx-tree-grid [igxPreventDocumentScroll ]="true" #treeGrid [data ]="data" primaryKey ="ID" foreignKey ="ParentID" [autoGenerate ]="false" height ="400px" >
<igx-grid-toolbar >
<igx-grid-toolbar-title > Tree Grid Toolbar</igx-grid-toolbar-title >
<igx-grid-toolbar-actions >
<igx-grid-toolbar-advanced-filtering > </igx-grid-toolbar-advanced-filtering >
<igx-grid-toolbar-hiding > </igx-grid-toolbar-hiding >
<igx-grid-toolbar-pinning > </igx-grid-toolbar-pinning >
<igx-grid-toolbar-exporter > </igx-grid-toolbar-exporter >
</igx-grid-toolbar-actions >
</igx-grid-toolbar >
<igx-column field ="Name" width ="25%" >
<ng-template igxCell let-cell ="cell" >
<div class ="cell__inner" >
<igx-avatar [src ]="cell.row.data.Avatar" [roundShape ]="true" size ="small" > </igx-avatar >
<span class ="name" > {{ cell.value }}</span >
</div >
</ng-template >
</igx-column >
<igx-column field ="Title" dataType ="string" width ="25%" > </igx-column >
<igx-column field ="ID" dataType ="number" width ="15%" > </igx-column >
<igx-column field ="Age" dataType ="number" width ="15%" > </igx-column >
<igx-column field ="HireDate" dataType ="date" width ="20%" > </igx-column >
</igx-tree-grid >
</div >
html コピー .grid__wrapper {
margin : 10px ;
display : flex;
align-items : center;
justify-content : center;
}
.cell__inner {
display : flex;
align-items : center;
height : 100% ;
position : relative;
justify-content : space-between;
}
.name {
margin-left : 30px ;
}
scss コピー
このサンプルが気に入りましたか? 完全な Ignite UI for Angularツールキットにアクセスして、すばやく独自のアプリの作成を開始します。無料でダウンロードできます。
事前定義された actions
および title
UI コンポーネントが <igx-grid-toolbar>
内に追加されます。これはすべて、対応するグリッド機能とのデフォルトのインタラクションを提供するツールバーを持つために必要です。
<igx-tree-grid [data ]="data" primaryKey ="ID" foreignKey ="ParentID" [autoGenerate ]="true" >
<igx-grid-toolbar >
<igx-grid-toolbar-title > Tree Grid Toolbar</igx-grid-toolbar-title >
<igx-grid-toolbar-actions >
<igx-grid-toolbar-advanced-filtering > <igx-grid-toolbar-advanced-filtering >
<igx-grid-toolbar-hiding > </igx-grid-toolbar-hiding >
<igx-grid-toolbar-pinning > </igx-grid-toolbar-pinning >
<igx-grid-toolbar-exporter > </igx-grid-toolbar-exporter >
</igx-grid-toolbar-actions >
</igx-grid-toolbar >
</igx-tree-grid >
html
注: 上記のコード スニペットに示されているように、事前定義された actions
UI コンポーネントは <igx-grid-toolbar-actions>
コンテナー にラップされています。このように、ツールバーのタイトルはツールバーの左側に配置され、アクションはツールバーの右側に配置されます。
これらの UI はそれぞれ独立して追加することも、まったく追加しないこともできます。このようにして、ツールバー コンテナーは空になります。
<igx-tree-grid [data ]="data" primaryKey ="ID" foreignKey ="ParentID" [autoGenerate ]="true" >
<igx-grid-toolbar >
</igx-grid-toolbar >
</igx-tree-grid >
html
デフォルトの各 UI コンポーネントの詳細については、以下の機能 セクションを読み続けてください。
機能
ツールバーは、グリッド全体に影響を与えるロジック/インタラクションを分離するのに最適です。
上記のように、制御、列の非表示、列のピン固定、高度なフィルタリング、およびグリッドからのデータのエクスポートのためのデフォルトのコンポーネントを提供するように構成できます。
これらの機能は、Ignite UI for 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 { IgxPreventDocumentScrollModule } from "./directives/prevent-scroll.directive" ;
import {
IgxTreeGridModule,
IgxAvatarModule,
IgxExcelExporterService,
IgxCsvExporterService,
IgxSwitchModule
} from "igniteui-angular" ;
import { TreeGridToolbarSample1Component } from "./tree-grid-toolbar-sample-1/tree-grid-toolbar-sample-1.component" ;
@NgModule ({
bootstrap : [AppComponent],
declarations : [
AppComponent,
TreeGridToolbarSample1Component
],
imports : [
BrowserModule,
BrowserAnimationsModule,
FormsModule,
IgxPreventDocumentScrollModule,
IgxTreeGridModule,
IgxAvatarModule,
IgxSwitchModule
],
providers : [
IgxExcelExporterService,
IgxCsvExporterService
],
entryComponents : [],
schemas : []
})
export class AppModule {}
ts コピー import { Component } from '@angular/core' ;
import { EMPLOYEE_FLAT_AVATARS_DATA } from '../data/employees-flat-avatars' ;
@Component ({
selector : 'app-tree-grid-toolbar-sample-1' ,
styleUrls : ['./tree-grid-toolbar-sample-1.component.scss' ],
templateUrl : './tree-grid-toolbar-sample-1.component.html'
})
export class TreeGridToolbarSample1Component {
data : any [];
toolbarTitle = 'Tree grid toolbar' ;
enableHiding = true ;
enablePinning = true ;
enableExport = true ;
enableFiltering = true ;
constructor ( ) {
this .data = EMPLOYEE_FLAT_AVATARS_DATA();
}
}
ts コピー <div class ="grid__wrapper" >
<div class ="control_panel" >
<igx-input-group >
<label for ="toolbarTitle" igxLabel > Toolbar title</label >
<input name ="toolbarTitle" type ="text" igxInput [(ngModel )]="toolbarTitle" />
</igx-input-group >
<div >
<igx-switch [(ngModel )]="enableFiltering" > Advanced Filtering</igx-switch >
<igx-switch [(ngModel )]="enableHiding" > Column hiding</igx-switch >
<igx-switch [(ngModel )]="enablePinning" > Column pinning</igx-switch >
<igx-switch [(ngModel )]="enableExport" > Exporting</igx-switch >
</div >
</div >
<igx-tree-grid [igxPreventDocumentScroll ]="true" #treeGrid [data ]="data" primaryKey ="ID" foreignKey ="ParentID" [autoGenerate ]="false" height ="310px" >
<igx-grid-toolbar >
<igx-grid-toolbar-title > {{ toolbarTitle }}</igx-grid-toolbar-title >
<igx-grid-toolbar-actions >
<igx-grid-toolbar-advanced-filtering *ngIf ="enableFiltering" > </igx-grid-toolbar-advanced-filtering >
<igx-grid-toolbar-hiding *ngIf ="enableHiding" > </igx-grid-toolbar-hiding >
<igx-grid-toolbar-pinning *ngIf ="enablePinning" > </igx-grid-toolbar-pinning >
<igx-grid-toolbar-exporter *ngIf ="enableExport" > </igx-grid-toolbar-exporter >
</igx-grid-toolbar-actions >
</igx-grid-toolbar >
<igx-column field ="Name" width ="25%" >
<ng-template igxCell let-cell ="cell" >
<div class ="cell__inner" >
<igx-avatar [src ]="cell.row.data.Avatar" [roundShape ]="true" size ="small" > </igx-avatar >
<span class ="name" > {{ cell.value }}</span >
</div >
</ng-template >
</igx-column >
<igx-column field ="Title" dataType ="string" > </igx-column >
<igx-column field ="ID" dataType ="number" > </igx-column >
<igx-column field ="Age" dataType ="number" > </igx-column >
<igx-column field ="HireDate" dataType ="date" > </igx-column >
</igx-tree-grid >
</div >
html コピー .grid__wrapper {
margin : 10px ;
}
.control_panel {
width : 700px ;
margin-bottom : 10px ;
}
.cell__inner {
display : flex;
align-items : center;
height : 100% ;
position : relative;
justify-content : space-between;
}
.name {
margin-left : 30px ;
}
scss コピー
タイトル
グリッドのツールバーのタイトルを設定するには、IgxGridToolbarTitleComponent を使用します。
ユーザーは、単純なテキストからより複雑なテンプレートまで、どんなものでも提供できます。
<igx-grid-toolbar >
<igx-grid-toolbar-title > Grid toolbar title</igx-grid-toolbar-title >
</igx-grid-toolbar >
html
操作
ツールバーは、ユーザーが親グリッドに関連して操作/インタラクションを配置できる特定のコンテナー を公開します。
ツールバーのタイトル部分と同様に、ユーザーは、デフォルトのツールバー インタラクション コンポーネントを含め、そのテンプレート部分内にどんなものでも提供できます。
<igx-grid-toolbar >
<igx-grid-toolbar-actions >
<button igxButton > Action</button >
<igx-select > </igx-select >
...
</igx-grid-toolbar-actions >
</igx-grid-toolbar >
html
各アクションは、overlaySettings
入力を使用して、アクション ダイアログのオーバーレイ設定を変更する方法を公開するようになりました。例:
<igx-grid-toolbar-actions >
<igx-grid-toolbar-pinning [overlaySettings ]="overlaySettingsScaleCenter" > </igx-grid-toolbar-pinning >
<igx-grid-toolbar-hiding [overlaySettings ]="overlaySettingsAuto" > </igx-grid-toolbar-hiding >
</igx-grid-toolbar-actions >
html
public data: any [];
public positionStrategyScaleCenter = new GlobalPositionStrategy({
openAnimation : scaleInCenter,
closeAnimation : scaleOutCenter
});
public overlaySettingsScaleCenter = {
positionStrategy : this .positionStrategyScaleCenter,
scrollStrategy : new AbsoluteScrollStrategy(),
modal : true ,
closeOnEscape : true
};
public positionStrategyAuto = new AutoPositionStrategy();
public overlaySettingsAuto = {
positionStrategy : this .positionStrategyAuto,
scrollStrategy : new AbsoluteScrollStrategy(),
modal : false ,
closeOnEscape : false
};
constructor ( ) {
this .data = athletesData;
}
ts
デフォルトの overlaySettings は、ConnectedPositionStrategy と Absolute スクロール方法を使用しています。モーダルは false に設定されており、[Esc] キーを押して閉じるインタラクションと外側のクリックで閉じるインタラクションが有効になっています。
列のピン固定
Toolbar Pinning コンポーネント は、グリッド内の列のピン固定を操作するためのデフォルトの UI を提供します。
コンポーネントは、ツールバーを含む親グリッドと、コンポーネントのタイトル、コンポーネント入力のプレースホルダー、ドロップダウン自体の高さなど、UI をカスタマイズするためのいくつかの入力プロパティを使用して、そのまま動作します。
<igx-grid-toolbar >
<igx-grid-toolbar-actions >
<igx-grid-toolbar-pinning
title ="Grid pinned columns"
prompt ="Filter column collection"
columnListHeight ="400px"
>
</igx-grid-toolbar-pinning >
</igx-grid-toolbar-actions >
</igx-grid-toolbar >
html
列の非表示
Toolbar Hiding コンポーネント は、列非表示を操作するためのデフォルトの UI を提供します。コンポーネントのタイトル、コンポーネント入力のプレースホルダー、ドロップダウン自体の高さなど、UI をカスタマイズするための同じ入力プロパティを公開します。
<igx-grid-toolbar >
<igx-grid-toolbar-actions >
<igx-grid-toolbar-hiding
title ="Grid column hiding"
prompt ="Filter column collection"
columnListHeight ="400px"
>
</igx-grid-toolbar-hiding >
</igx-grid-toolbar-actions >
</igx-grid-toolbar >
html
高度なフィルタリング
Toolbar Advanced Filtering コンポーネント は、高度なフィルタリング機能のデフォルトの UI を提供します。コンポーネントは、ボタンのデフォルトのテキストを変更する方法を公開します。
<igx-grid-toolbar >
<igx-grid-toolbar-actions >
<igx-grid-toolbar-advanced-filtering > Custom text for the toggle button</igx-grid-toolbar-advanced-filtering >
</igx-grid-toolbar-actions >
</igx-grid-toolbar >
html
データのエクスポート
残りのツールバー操作と同様に、エクスポートは、すぐに使用できる Toolbar Exporter コンポーネント を介して提供されます。
エクスポート コンポーネントは、ターゲット データ形式 (Excel CSV) のそれぞれのサービスを使用しています。つまり、それぞれのサービスが依存関係挿入チェーンを通じて提供されない場合、コンポーネントは何もエクスポートできません。
Angular の DI の復習が必要な場合は、公式ガイド をご覧ください。これは、アプリケーションのすべてのエクスポート サービスを有効にする方法を示すサンプル スニペットです。
import { IgxExcelExporterService, IgxCsvExporterService } from 'igniteui-angular' ;
@NgModule ({
...
providers : [IgxExcelExporterService, IgxCsvExporterService ]
})
export class AppModule { ... }
typescript
v12.2.1 以降では、エクスポーター サービスは root で提供されます。つまり、AppModule プロバイダーでそれらを宣言する必要はありません。
ツールバー エクスポーター コンポーネントは、UI とエクスポート エクスペリエンスの両方をカスタマイズするためのいくつかの入力プロパティを公開します。
これらは、表示テキストの変更から、ドロップダウンのオプションの有効化/無効化、生成されたファイルの名前のカスタマイズまで多岐にわたります。
完全なリファレンスについては、ツールバー エクスポータ コンポーネントの API ヘルプ を参照してください。
これは、Angular テンプレートを介してカスタマイズできるいくつかのオプションを示すスニペットです。
<igx-grid-toolbar >
<igx-grid-toolbar-actions >
<igx-grid-toolbar-exporter
<!-- If active , enables the csv export entry in the dropdown UI -- >
[exportCSV]="csvExportEnabled"
[exportExcel]="excelExportEnabled"
filename="exported_data"
>
Custom text for the exporter button
<span excelText > Custom text for the excel export entry</span >
<span csvText > Custom text for the CSV export entry</span >
</igx-grid-toolbar-exporter >
</igx-grid-toolbar-actions >
</igx-grid-toolbar >
html
エクスポートされたファイル名を変更することに加えて、ユーザーは toolbarExporting イベントを待機し、イベント プロパティのオプション エントリをカスタマイズすることで、エクスポーター オプションをさらに構成できます。
デフォルトで CSV にエクスポートした際にエクスポーターがカンマ区切りセパレーターを使用してエクスポートし、出力ファイルに .csv 拡張しを使用します。
エクスポーターのイベントにサブスクライブまたはエクスポーター オプション フィールドの値を変更して、エクスポート パラメーターをカスタマイズできます。
またイベント引数のキャンセル フィールドを true に設定してエクスポートをキャンセルすることもできます。
次のコード スニペットは、ツールバーのエクスポート イベントのサブスクライブとエクスポーター オプションの構成を示しています。
<igx-tree-grid (toolbarExporting )="configureExport($event)" > </igx-tree-grid >
html
configureExport (args: IGridToolbarExportEventArgs ) {
const options: IgxExporterOptionsBase = args.options;
options.fileName = `Report_${new Date ().toDateString()} ` ;
if (options instanceof IgxExcelExporterOptions) {
options.columnWidth = 10 ;
} else {
options.fileType = CsvFileTypes.TSV;
options.valueDelimiter = '\t' ;
}
args.exporter.columnExporting.subscribe((columnArgs: IColumnExportingEventArgs ) => {
columnArgs.cancel = columnArgs.header === 'Name' ;
});
}
typescript
以下のサンプルは、エクスポート ファイルをカスタマイズする方法を示します。
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 { IgxPreventDocumentScrollModule } from "./directives/prevent-scroll.directive" ;
import {
IgxTreeGridModule,
IgxAvatarModule,
IgxExcelExporterService,
IgxCsvExporterService
} from "igniteui-angular" ;
import { TreeGridToolbarSample2Component } from "./tree-grid-toolbar-sample-2/tree-grid-toolbar-sample-2.component" ;
@NgModule ({
bootstrap : [AppComponent],
declarations : [
AppComponent,
TreeGridToolbarSample2Component
],
imports : [
BrowserModule,
BrowserAnimationsModule,
FormsModule,
IgxPreventDocumentScrollModule,
IgxTreeGridModule,
IgxAvatarModule
],
providers : [
IgxExcelExporterService,
IgxCsvExporterService
],
entryComponents : [],
schemas : []
})
export class AppModule {}
ts コピー import { Component } from '@angular/core' ;
import {
CsvFileTypes,
IColumnExportingEventArgs,
IGridToolbarExportEventArgs,
IgxCsvExporterOptions,
IgxExcelExporterOptions,
IgxExporterOptionsBase
} from 'igniteui-angular' ;
import { EMPLOYEE_FLAT_AVATARS_DATA } from '../data/employees-flat-avatars' ;
@Component ({
selector : 'app-tree-grid-toolbar-sample-2' ,
styleUrls : ['./tree-grid-toolbar-sample-2.component.scss' ],
templateUrl : './tree-grid-toolbar-sample-2.component.html'
})
export class TreeGridToolbarSample2Component {
public data: any [];
constructor ( ) {
this .data = EMPLOYEE_FLAT_AVATARS_DATA();
}
public configureExport (args: IGridToolbarExportEventArgs ) {
const options: IgxExporterOptionsBase = args.options;
options.fileName = 'Custom Title' ;
if (options instanceof IgxExcelExporterOptions) {
const excelOptions = options as IgxExcelExporterOptions;
excelOptions.columnWidth = 10 ;
} else {
const csvOptions = options as IgxCsvExporterOptions;
csvOptions.fileType = CsvFileTypes.TSV;
csvOptions.valueDelimiter = '\t' ;
}
args.exporter.columnExporting.subscribe((columnArgs: IColumnExportingEventArgs ) => {
columnArgs.cancel = columnArgs.header === 'Name' ;
});
}
}
ts コピー <div class ="grid__wrapper" >
<igx-tree-grid [igxPreventDocumentScroll ]="true" #treeGrid [data ]="data" primaryKey ="ID" foreignKey ="ParentID"
[autoGenerate ]="false" height ="400px" (toolbarExporting )="configureExport($event)" >
<igx-grid-toolbar >
<igx-grid-toolbar-title > Grid toolbar</igx-grid-toolbar-title >
<igx-grid-toolbar-actions >
<igx-grid-toolbar-exporter > </igx-grid-toolbar-exporter >
</igx-grid-toolbar-actions >
</igx-grid-toolbar >
<igx-column field ="Name" header ="Name" width ="25%" >
<ng-template igxCell let-cell ="cell" >
<div class ="cell__inner" >
<igx-avatar [src ]="cell.row.data.Avatar" [roundShape ]="true" size ="small" > </igx-avatar >
<span class ="name" > {{ cell.value }}</span >
</div >
</ng-template >
</igx-column >
<igx-column field ="Title" dataType ="string" width ="25%" > </igx-column >
<igx-column field ="ID" dataType ="number" width ="15%" > </igx-column >
<igx-column field ="Age" dataType ="number" width ="15%" > </igx-column >
<igx-column field ="HireDate" dataType ="date" width ="20%" > </igx-column >
</igx-tree-grid >
</div >
html コピー .grid__wrapper {
margin : 10px ;
display : flex;
align-items : center;
justify-content : center;
}
.cell__inner {
display : flex;
align-items : center;
height : 100% ;
position : relative;
justify-content : space-between;
}
.name {
margin-left : 30px ;
}
scss コピー
エクスポート インジケーター
デフォルトのツールバー エクスポーター コンポーネントを使用する場合、エクスポート操作が行われると、操作の進行中にツールバーに進行状況インジケーターが表示されます。
さらに、ユーザーはツールバーの showProgress プロパティを設定して、自分の長時間実行操作に使用するか、グリッドで実行されている操作を示す別の方法として使用できます。
以下のサンプルには大量のデータが含まれています。データのエクスポート中はプログレス バーが表示されます。さらに、グリッドで長時間実行される操作をシミュレートする別のボタンがあります。
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 { IgxPreventDocumentScrollModule } from "./directives/prevent-scroll.directive" ;
import {
IgxTreeGridModule,
IgxToggleModule,
IgxExcelExporterService,
IgxCsvExporterService
} from "igniteui-angular" ;
import { TreeGridExportVisualizationComponent } from "./tree-grid-export-visualization/tree-grid-export-visualization.component" ;
@NgModule ({
bootstrap : [AppComponent],
declarations : [
AppComponent,
TreeGridExportVisualizationComponent
],
imports : [
BrowserModule,
BrowserAnimationsModule,
FormsModule,
IgxPreventDocumentScrollModule,
IgxTreeGridModule,
IgxToggleModule
],
providers : [
IgxExcelExporterService,
IgxCsvExporterService
],
entryComponents : [],
schemas : []
})
export class AppModule {}
ts コピー import { Component } from '@angular/core' ;
import { FOODS_DATA } from '../data/foods' ;
@Component ({
selector : 'app-tree-grid-export-visualization' ,
templateUrl : './tree-grid-export-visualization.component.html' ,
styleUrls : ['./tree-grid-export-visualization.component.scss' ]
})
export class TreeGridExportVisualizationComponent {
public localData = [];
private data = FOODS_DATA();
constructor ( ) {
for (let i = 0 ; i < 15000 ; i += 3 ) {
for (let c = 0 ; c < this .data.length; c++) {
this .localData.push(this .data[c]);
}
}
}
longRunning (toolbar: any ) {
toolbar.showProgress = true ;
setTimeout (() => toolbar.showProgress = false , 5000 );
}
}
ts コピー <div class ="grid__wrapper" >
<igx-tree-grid [igxPreventDocumentScroll ]="true" [data ]="localData" [autoGenerate ]="false" primaryKey ="ID"
foreignKey ="ParentID" height ="350px" width ="100%" primaryKey ="ID" >
<igx-grid-toolbar #toolbar >
<igx-grid-toolbar-actions >
<button [disabled ]="toolbar.showProgress" (click )="longRunning(toolbar)" igxButton >
Simulate long running operation
</button >
<igx-grid-toolbar-exporter > </igx-grid-toolbar-exporter >
</igx-grid-toolbar-actions >
</igx-grid-toolbar >
<igx-column field ="ID" header ="Product ID" [dataType ]="'string'" >
</igx-column >
<igx-column field ="Name" header ="Product Name" [dataType ]="'string'" >
</igx-column >
<igx-column field ="UnitPrice" header ="Unit Price" dataType ="number" >
<ng-template igxCell let-cell ="cell" let-val let-row >
{{+val | currency}}
</ng-template >
</igx-column >
<igx-column field ="AddedDate" header ="Added Date" [dataType ]="'date'" >
</igx-column >
</igx-tree-grid >
</div >
html コピー .grid__wrapper {
margin : 10px ;
}
scss コピー
カスタム コンテンツ
これは、古いツールバー テンプレート ディレクティブを置き換えます。v11 より前のバージョンから移行する場合は、マイグレーションによってテンプレート コンテンツの移動が処理されます。
ただし、テンプレート内のバインディングは処理しないため、マイグレーションの完了後に、変更されたテンプレート ファイルを再確認してください。
ツールバー コンポーネントのアクション部分が特定のユース ケースに十分でない場合、ツールバー自体には、ユーザーが追加の UI を提供できる一般的なコンテンツ プロジェクションがあります。
ユーザーが API 呼び出しまたはバインディングにそれぞれのグリッド インスタンスを必要とする場合は、テンプレート参照変数を作成できます。
サンプル スニペットは次のとおりです。
<igx-tree-grid #gridRef ... >
...
<igx-grid-toolbar >
<igx-grid-toolbar-title > {{ titleBinding }}</igx-grid-toolbar-title >
<button igxButton ="flat" igxRipple (click )="#gridRef.clearSort()" >
<igx-icon fontSet ="material" > clear</igx-icon >
Clear Sort
</button >
<igx-grid-toolbar-actions >
...
</igx-grid-toolbar-actions >
</igx-grid-toolbar >
</igx-tree-grid >
html
以下のサンプルは、列ヘッダーをクリックして並べ替えセットをクリアするためのボタンをツールバーに追加する方法です。
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 { IgxPreventDocumentScrollModule } from "./directives/prevent-scroll.directive" ;
import {
IgxTreeGridModule,
IgxAvatarModule,
IgxButtonModule,
IgxRippleModule,
IgxIconModule
} from "igniteui-angular" ;
import { TreeGridToolbarSample3Component } from "./tree-grid-toolbar-sample-3/tree-grid-toolbar-sample-3.component" ;
@NgModule ({
bootstrap : [AppComponent],
declarations : [
AppComponent,
TreeGridToolbarSample3Component
],
imports : [
BrowserModule,
BrowserAnimationsModule,
FormsModule,
IgxPreventDocumentScrollModule,
IgxTreeGridModule,
IgxAvatarModule,
IgxButtonModule,
IgxRippleModule,
IgxIconModule
],
providers : [],
entryComponents : [],
schemas : []
})
export class AppModule {}
ts コピー import { Component } from '@angular/core' ;
import { EMPLOYEE_FLAT_AVATARS_DATA } from '../data/employees-flat-avatars' ;
@Component ({
selector : 'app-tree-grid-toolbar-sample-3' ,
styleUrls : ['./tree-grid-toolbar-sample-3.component.scss' ],
templateUrl : './tree-grid-toolbar-sample-3.component.html'
})
export class TreeGridToolbarSample3Component {
public data: any [];
constructor ( ) {
this .data = EMPLOYEE_FLAT_AVATARS_DATA();
}
}
ts コピー <div class ="grid__wrapper" >
<igx-tree-grid [igxPreventDocumentScroll ]="true" #treeGrid [data ]="data" primaryKey ="ID" foreignKey ="ParentID"
[autoGenerate ]="false" height ="400px" >
<igx-grid-toolbar >
<igx-grid-toolbar-title > Tree Grid Toolbar</igx-grid-toolbar-title >
<igx-grid-toolbar-actions >
<button igxButton ="flat" igxRipple (click )="treeGrid.clearSort()" >
<igx-icon family ="material" > clear</igx-icon >
<span > Clear Sort</span >
</button >
<igx-grid-toolbar-hiding > </igx-grid-toolbar-hiding >
<igx-grid-toolbar-pinning > </igx-grid-toolbar-pinning >
<igx-grid-toolbar-exporter > </igx-grid-toolbar-exporter >
</igx-grid-toolbar-actions >
</igx-grid-toolbar >
<igx-column field ="Name" header ="Name" width ="25%" >
<ng-template igxCell let-cell ="cell" >
<div class ="cell__inner" >
<igx-avatar [src ]="cell.row.data.Avatar" [roundShape ]="true" size ="small" > </igx-avatar >
<span class ="name" > {{ cell.value }}</span >
</div >
</ng-template >
</igx-column >
<igx-column field ="Title" dataType ="string" [sortable ]="true" width ="25%" > </igx-column >
<igx-column field ="ID" dataType ="number" [sortable ]="true" width ="15%" > </igx-column >
<igx-column field ="Age" dataType ="number" [sortable ]="true" width ="15%" > </igx-column >
<igx-column field ="HireDate" dataType ="date" [sortable ]="true" width ="20%" > </igx-column >
</igx-tree-grid >
</div >
html コピー .grid__wrapper {
margin : 10px ;
display : flex;
align-items : center;
justify-content : center;
}
.cell__inner {
display : flex;
align-items : center;
height : 100% ;
position : relative;
justify-content : space-between;
}
.name {
margin-left : 30px ;
}
scss コピー
スタイル設定
ツールバーのスタイル設定を始めるには、すべてのテーマ関数とコンポーネント ミックスインが存在する index ファイルをインポートする必要があります。
@use "igniteui-angular/theming" as *;
scss
まず、新しいパレットを作成します。
$my-dark-palette : palette(
$primary : #2466ff ,
$secondary : #ffcd0f ,
$surface : #2a2b2f ,
$grays : #fff ,
);
$my-dark-color : color($my-dark-palette , 'surface' );
scss
grid-toolbar-theme
を拡張する新しいテーマを作成し、$background-color
と $title-text-color
パラメーターを変更します。
$dark-grid-toolbar-theme : grid-toolbar-theme(
$background-color : $my-dark-color ,
$title-text-color : color($my-dark-palette , 'secondary' ),
$dropdown-background : $my-dark-color ,
);
scss
ツールバーの列操作メニューにテーマを設定するには、column-actions-theme
コンポーネントのテーマを変更する必要があります。
$dark-column-actions-theme : column-actions-theme(
$title-color : color($my-dark-palette , 'secondary' ),
$background-color : color($my-dark-palette , 'surface' )
);
scss
列操作は他のコンポーネント (igx-button
、igx-checkbox
) を使用しているため、新しいツールバー テーマに一致するようにテーマを変更する必要があります。
$dark-button-theme : button-theme(
$outlined-background : color($my-dark-palette , 'secondary' ),
$outlined-hover-background : color($my-dark-palette , 'grays' , 100 ),
$outlined-hover-text-color : color($my-dark-palette , 'secondary' )
);
$dark-checkbox-theme : checkbox-theme(
$tick-color : $my-dark-color ,
);
scss
最後にコンポーネントのテーマを含めます 。
@include css-vars($dark-grid-toolbar-theme );
@include css-vars($dark-column-actions-theme );
@include css-vars($dark-checkbox-theme );
@include css-vars($dark-button-theme );
scss
コンポーネントが Emulated
ViewEncapsulation を使用している場合、グリッド ツールバー コンポーネント内のコンポーネントのスタイルを設定するために、::ng-deep
を使用してこのカプセル化を解除する
必要があります。
@include css-vars($dark-grid-toolbar-theme );
:host {
::ng-deep {
@include css-vars($dark-column-actions-theme );
@include css-vars($dark-checkbox-theme );
@include css-vars($dark-button-theme );
}
}
scss
デモ
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 { IgxPreventDocumentScrollModule } from "./directives/prevent-scroll.directive" ;
import {
IgxTreeGridModule,
IgxAvatarModule,
IgxExcelExporterService,
IgxCsvExporterService
} from "igniteui-angular" ;
import { TreeGridToolbarStyleComponent } from "./tree-grid-toolbar-style/tree-grid-toolbar-style.component" ;
@NgModule ({
bootstrap : [AppComponent],
declarations : [
AppComponent,
TreeGridToolbarStyleComponent
],
imports : [
BrowserModule,
BrowserAnimationsModule,
FormsModule,
IgxPreventDocumentScrollModule,
IgxTreeGridModule,
IgxAvatarModule
],
providers : [
IgxExcelExporterService,
IgxCsvExporterService
],
entryComponents : [],
schemas : []
})
export class AppModule {}
ts コピー import { Component } from '@angular/core' ;
import { EMPLOYEE_FLAT_AVATARS_DATA } from '../data/employees-flat-avatars' ;
@Component ({
selector : 'app-tree-grid-toolbar-style' ,
styleUrls : ['./tree-grid-toolbar-style.component.scss' ],
templateUrl : './tree-grid-toolbar-style.component.html'
})
export class TreeGridToolbarStyleComponent {
public data: any [];
constructor ( ) {
this .data = EMPLOYEE_FLAT_AVATARS_DATA();
}
}
ts コピー <div class ="grid__wrapper" >
<igx-tree-grid [igxPreventDocumentScroll ]="true" #treeGrid [data ]="data" primaryKey ="ID" foreignKey ="ParentID"
[autoGenerate ]="false" height ="400px" >
<igx-grid-toolbar >
<igx-grid-toolbar-title > Tree Grid Toolbar</igx-grid-toolbar-title >
<igx-grid-toolbar-actions >
<igx-grid-toolbar-hiding > </igx-grid-toolbar-hiding >
<igx-grid-toolbar-pinning > </igx-grid-toolbar-pinning >
<igx-grid-toolbar-exporter > </igx-grid-toolbar-exporter >
</igx-grid-toolbar-actions >
</igx-grid-toolbar >
<igx-column field ="Name" width ="250px" >
<ng-template igxCell let-cell ="cell" >
<div class ="cell__inner" >
<igx-avatar [src ]="cell.row.data.Avatar" [roundShape ]="true" size ="small" > </igx-avatar >
<span class ="name" > {{ cell.value }}</span >
</div >
</ng-template >
</igx-column >
<igx-column [field ]="'Title'" dataType ="string" width ="200px" > </igx-column >
<igx-column [field ]="'ID'" dataType ="number" width ="200px" > </igx-column >
<igx-column [field ]="'Age'" dataType ="number" width ="200px" > </igx-column >
<igx-column [field ]="'HireDate'" dataType ="date" width ="200px" > </igx-column >
</igx-tree-grid >
</div >
html コピー @use '../../variables' as *;
$dark-button-theme : button-theme(
$background : #FFCD0F ,
$foreground : #292826 ,
$hover-background : #404040 ,
$hover-foreground : #FFCD0F
);
$dark-grid-toolbar-theme : grid-toolbar-theme(
$background-color : #292826 ,
$title-text-color : #FFCD0F
);
:host {
::ng-deep {
@include css-vars($dark-grid-toolbar-theme );
.igx-grid-toolbar__actions {
@include css-vars($dark-button-theme );
.igx-button--outlined {
margin-left : 0.5rem ;
border : none;
}
}
}
}
.grid__wrapper {
margin : 10px ;
}
.cell__inner {
display : flex;
align-items : center;
height : 100% ;
position : relative;
justify-content : space-between;
}
.name {
margin-left : 30px ;
}
scss コピー
API リファレンス
以下は、Grid Toolbar サービスのその他の API です。
IgxTreeGridComponent
イベント:
スタイル:
その他のリソース
コミュニティに参加して新しいアイデアをご提案ください。