Angular Grid 列選択
列選択機能は、シングルク リックで列全体を選択する簡単な方法を提供します。特定の列の重要性を強調するために、ヘッダー セルとその下のすべてにフォーカスします。この機能は豊富な API
を備えて選択状態の操作、選択した部分からのデータ抽出、データ分析操作、可視化が可能になります。
Angular 列選択の例
以下のサンプルは、Grid の列選択動作の 3 つのタイプを示します。使用可能な各選択モードを有効にするには、以下の [列選択] ドロップダウンを使用します。
*Contact Title、City、および Address 列の選択が無効になっています。
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 { GridColumnSelectionComponent } from "./grid/column-selection-sample/column-selection-sample.component";
import { IgxGridModule } from "igniteui-angular";
@NgModule({
bootstrap: [AppComponent],
declarations: [
AppComponent,
GridColumnSelectionComponent
],
imports: [
BrowserModule,
BrowserAnimationsModule,
FormsModule,
IgxGridModule
],
providers: [],
entryComponents: [],
schemas: []
})
export class AppModule {}
ts
import { AfterViewInit, ChangeDetectorRef, Component, OnInit, ViewChild } from '@angular/core';
import { GridSelectionMode, IgxGridComponent } from 'igniteui-angular';
import { DATA } from '../../data/customers';
@Component({
selector: 'app-grid-column-selection',
templateUrl: './column-selection-sample.component.html',
styleUrls: ['./column-selection-sample.component.scss']
})
export class GridColumnSelectionComponent implements OnInit, AfterViewInit {
@ViewChild(IgxGridComponent)
public grid: IgxGridComponent;
public data: any[];
public columnSelectionType: GridSelectionMode = 'single';
constructor(private cdr: ChangeDetectorRef) {}
public ngOnInit() {
this.data = DATA;
}
public ngAfterViewInit() {
this.grid.getColumnByName('CompanyName').selected = true;
this.cdr.detectChanges();
}
}
ts
<div class="grid-wrapper">
<igx-grid #grid [columnSelection]="columnSelectionType" [data]="data" height="530px" width="100%">
<igx-grid-toolbar>
<igx-select [(ngModel)]="columnSelectionType">
<label igxLabel>Column Selection</label>
<igx-select-item value="none">None</igx-select-item>
<igx-select-item value="single">Single</igx-select-item>
<igx-select-item value="multiple">Mulitple</igx-select-item>
</igx-select>
</igx-grid-toolbar>
<igx-column field="ID"></igx-column>
<igx-column field="CompanyName" header="Company Name" ></igx-column>
<igx-column field="ContactTitle" [selectable]="false" header="Contact Title"></igx-column>
<igx-column field="City" [selectable]="false" ></igx-column>
<igx-column field="Country"></igx-column>
<igx-column field="PostalCode" header="Postal Code"></igx-column>
<igx-column field="Address" [selectable]="false"></igx-column>
</igx-grid>
</div>
html
.grid-wrapper {
padding: 16px;
}
scss
このサンプルが気に入りましたか? 完全な Ignite UI for Angularツールキットにアクセスして、すばやく独自のアプリの作成を開始します。無料でダウンロードできます。
基本的な使用方法
列選択機能は、GridSelectionMode 値を受け取る columnSelection
入力によって有効にすることができます。
インタラクション
デフォルトの選択モードは none
です。single
または multiple
に設定されると、すべての列は selectable
になります。列を選択するには、列をクリックして selected
としてマークします。列が選択不可な場合、ホバー時に選択スタイルはヘッダーに適用されません。
*Country Information 列グループでは、City 列および Postal code 列のみを選択できます。
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 { GridColumnGroupSelectionComponent } from "./grid/column-group-selection-sample/column-group-selection-sample.component";
import { IgxGridModule } from "igniteui-angular";
@NgModule({
bootstrap: [AppComponent],
declarations: [
AppComponent,
GridColumnGroupSelectionComponent
],
imports: [
BrowserModule,
BrowserAnimationsModule,
FormsModule,
IgxGridModule
],
providers: [],
entryComponents: [],
schemas: []
})
export class AppModule {}
ts
import { AfterViewInit, ChangeDetectorRef, Component, OnInit, ViewChild } from '@angular/core';
import { IgxGridComponent } from 'igniteui-angular';
import { DATA } from '../../data/customers';
@Component({
selector: 'app-gird-column-group-selection',
templateUrl: './column-group-selection-sample.component.html',
styleUrls: ['./column-group-selection-sample.component.scss']
})
export class GridColumnGroupSelectionComponent implements OnInit, AfterViewInit {
@ViewChild(IgxGridComponent)
public grid: IgxGridComponent;
public data: any[];
constructor(private cdr: ChangeDetectorRef){}
public ngOnInit() {
this.data = DATA;
}
public ngAfterViewInit() {
this.grid.selectColumns(['City', 'PostalCode']);
this.cdr.detectChanges();
}
}
ts
<div class="grid-wrapper">
<igx-grid #grid [data]="data" height="530px" width="100%" columnSelection="multiple">
<igx-column-group header="General Information" >
<igx-column field="CompanyName" ></igx-column>
<igx-column-group header="Personal Details">
<igx-column field="ContactName" [hidden]="true"></igx-column>
<igx-column field="ContactTitle" [selectable]="false"></igx-column>
</igx-column-group>
</igx-column-group>
<igx-column field="ID"></igx-column>
<igx-column-group header="Country Information">
<igx-column-group header="Region Information">
<igx-column field="Country" [selectable]="false"></igx-column>
<igx-column field="City"></igx-column>
<igx-column field="PostalCode" ></igx-column>
</igx-column-group>
<igx-column-group header="City Information" >
<igx-column field="Fax" [selectable]="false" ></igx-column>
<igx-column field="Address" [selectable]="false"></igx-column>
</igx-column-group>
</igx-column-group>
</igx-grid>
</div>
html
.grid-wrapper{
padding: 16px
}
scss
キーボードの組み合わせ
列の選択機能のキーボード ナビゲーションには 2 つのオプションがあります。
- 複数列選択 - Ctrl キーを押しながら、すべての選択可能なヘッダー セルをクリック。
- 範囲列の選択 - Shift キーを押しながら + クリック、間にあるすべての選択可能な列を選択します。
API 操作
API は、非表示列に関していくつかの追加機能を提供し、対応する setter を設定することにより、すべての非表示列を selected
としてマークできます。
API 操作の詳細については、API リファレンス
セクションを参照してください。
スタイル設定
スタイル設定オプションに移動する前に、core ジュールとすべてのコンポーネント ミックスインをインポートする必要があります。
@use "igniteui-angular/theming" as *;
scss
行選択
と列選択
は個別に操作できないことに注意してください。同じ変数
に依存します。
選択とホバーのスタイル設定を変更します。
最も簡単な方法は、カスタム テーマを定義する方法です。
$custom-grid-theme: grid-theme(
$row-selected-background: #011627,
$row-selected-text-color: #ecaa53,
$row-selected-hover-background: #011627,
$header-selected-text-color: #ecaa53,
$header-selected-background: #011627
);
scss
grid-theme
はいくつかのパラメーターを受け入れますが、選択したすべての列の外観を変更するのは以下の 5 つです。
- $row-selected-background- 選択した部分の背景を設定します。
- $row-selected-text-color - 選択した部分のテキスト色を設定します。
- $row-selected-hover-background - ホバーされたセルまたは複数のセルの色を設定します。
- $header-selected-text-color - 選択した列ヘッダーのテキスト色を設定します。
- $header-selected-background - 選択した列ヘッダーの背景色を設定します。
CSS 変数の使用
最後にカスタム igx-grid
テーマを含めます。
@include css-vars($custom-grid-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 { GridColumnSelectionStylesComponent } from "./grid/column-selection-styles/column-selection-styles.component";
import { IgxGridModule } from "igniteui-angular";
@NgModule({
bootstrap: [AppComponent],
declarations: [
AppComponent,
GridColumnSelectionStylesComponent
],
imports: [
BrowserModule,
BrowserAnimationsModule,
FormsModule,
IgxGridModule
],
providers: [],
entryComponents: [],
schemas: []
})
export class AppModule {}
ts
import { AfterViewInit, ChangeDetectorRef, Component, OnInit, ViewChild } from '@angular/core';
import { IgxGridComponent } from 'igniteui-angular';
import { DATA } from '../../data/customers';
@Component({
selector: 'app-gird-column-selection-styles',
templateUrl: './column-selection-styles.component.html',
styleUrls: ['./column-selection-styles.component.scss']
})
export class GridColumnSelectionStylesComponent implements OnInit, AfterViewInit {
@ViewChild(IgxGridComponent)
public grid: IgxGridComponent;
public data: any[];
constructor(private cdr: ChangeDetectorRef){}
public ngOnInit() {
this.data = DATA;
}
public ngAfterViewInit() {
this.grid.selectColumns(['CompanyName', 'PostalCode']);
this.cdr.detectChanges();
}
}
ts
<div class="grid-wrapper">
<igx-grid #grid [data]="data" height="530px" width="100%" columnSelection="multiple">
<igx-column field="CompanyName" ></igx-column>
<igx-column field="ContactName"></igx-column>
<igx-column field="ContactTitle" [selectable]="false"></igx-column>
<igx-column field="ID"></igx-column>
<igx-column field="Country" [selectable]="false"></igx-column>
<igx-column field="PostalCode" ></igx-column>
<igx-column field="City" [selectable]="false" ></igx-column>
<igx-column field="Address" [selectable]="false"></igx-column>
</igx-grid>
</div>
html
@use '../../../variables' as *;
.grid-wrapper {
padding: 16px;
}
$custom-grid-theme: grid-theme(
$row-selected-background: #011627,
$row-selected-text-color: #ecaa53,
$row-selected-hover-background: #011627,
$header-selected-text-color: #ecaa53,
$header-selected-background: #011627
);
:host ::ng-deep {
@include css-vars($custom-grid-theme);
}
scss
このサンプルは、Change Theme
(テーマの変更) から選択したグローバル テーマに影響を受けません。
API リファレンス
以下は、列選択 UI のその他の API です。
IgxGridComponent
プロパティ:
IgxColumnComponent
プロパティ:
IgxColumnGrpupComponent
プロパティ:
IgxGridComponent
イベント:
その他のリソース
コミュニティに参加して新しいアイデアをご提案ください。