Web Components Grid 概要と構成
Ignite UI for Web Components Data Table / Data Grid は、コーディングや構成をほとんど行わずにデータをすばやくバインドして表示できる表形式の Web Components グリッド コンポーネントです。ツールボックスの Web Components データ グリッドの機能には、フィルタリング、ソート、テンプレート、行の選択、行のグループ化、行の固定、および移動可能な列が含まれます。
Web Components テーブルは、ライブのストリーミング データ用に最適化されており、多数の行または列で無制限のデータ セット サイズを処理できます。
Web Components Data Grid の例
この Ignite UI for Web Components Grid の例では、ユーザーが基本スタイルと Excel スタイルの両方のフィルタリング、ライブ データのソート、およびグリッド集計とセル テンプレートの使用を実行する方法を確認できます。デモには、1 ページあたり 10 項目を表示するように設定されたページングも含まれています。
import 'igniteui-webcomponents-grids/grids/combined' ;
import { IgcGridComponent, IgcColumnComponent } from 'igniteui-webcomponents-grids/grids' ;
import NwindData from './NwindData.json' ;
import { IgcCellTemplateContext } from 'igniteui-webcomponents-grids/grids' ;
import { html, nothing } from 'lit-html' ;
import "igniteui-webcomponents-grids/grids/themes/light/bootstrap.css" ;
import "./index.css" ;
export class Sample {
private grid: IgcGridComponent
private column1: IgcColumnComponent
private _bind: () => void ;
constructor ( ) {
var grid = this .grid = document .getElementById('grid' ) as IgcGridComponent;
var column1 = this .column1 = document .getElementById('column1' ) as IgcColumnComponent;
this ._bind = () => {
grid.data = this .nwindData;
column1.bodyTemplate = this .webGridBooleanCellTemplate;
}
this ._bind();
}
private _nwindData: any [] = NwindData;
public get nwindData (): any [] {
return this ._nwindData;
}
public webGridBooleanCellTemplate = (ctx: IgcCellTemplateContext ) => {
if (ctx.cell.value) {
return html`<img src ="https://static.infragistics.com/xplatform/images/grid/active.png" title ="Continued" alt ="Continued" /> `
} else {
return html`<img src ="https://static.infragistics.com/xplatform/images/grid/expired.png" title ="Discontinued" alt ="Discontinued" /> ` ;
}
}
}
new Sample();
ts コピー <!DOCTYPE html >
<html >
<head >
<title > Sample | Ignite UI | Web Components | infragistics</title >
<meta charset ="UTF-8" />
<link rel ="shortcut icon" href ="https://static.infragistics.com/xplatform/images/browsers/wc.png" >
<link rel ="stylesheet" href ="https://fonts.googleapis.com/icon?family=Material+Icons" />
<link rel ="stylesheet" href ="https://fonts.googleapis.com/css?family=Kanit&display=swap" />
<link rel ="stylesheet" href ="https://fonts.googleapis.com/css?family=Titillium Web" />
<link rel ="stylesheet" href ="https://static.infragistics.com/xplatform/css/samples/shared.v8.css" />
<link rel ="stylesheet" href ="/src/index.css" type ="text/css" />
</head >
<body >
<div id ="root" >
<div class ="container sample ig-typography" >
<div class ="container fill" >
<igc-grid
auto-generate ="false"
id ="grid"
name ="grid"
id ="grid"
primary-key ="ProductID"
allow-filtering ="true"
filter-mode ="excelStyleFilter" >
<igc-paginator
per-page ="10" >
</igc-paginator >
<igc-column
field ="ProductName"
header ="Product Name"
data-type ="string"
sortable ="true"
has-summary ="true"
editable ="true"
resizable ="true" >
</igc-column >
<igc-column
field ="UnitPrice"
header ="Unit Price"
data-type ="number"
sortable ="true"
has-summary ="true"
editable ="true"
resizable ="true" >
</igc-column >
<igc-column
field ="UnitsInStock"
header ="Units in Stock"
data-type ="number"
sortable ="true"
has-summary ="true"
editable ="true"
resizable ="true" >
</igc-column >
<igc-column
field ="OrderDate"
header ="Order Date"
data-type ="date"
sortable ="true"
has-summary ="true"
editable ="true"
resizable ="true" >
</igc-column >
<igc-column
field ="Discontinued"
header ="Discontinued"
data-type ="boolean"
sortable ="true"
has-summary ="true"
editable ="true"
name ="column1"
id ="column1" >
</igc-column >
<igc-column
field ="ReorderLevel"
header ="Reorder Level"
data-type ="number"
sortable ="true"
has-summary ="true"
editable ="true"
filterable ="true" >
</igc-column >
</igc-grid >
</div >
</div >
</div >
<% if (false) { %><script src ="src/index.ts" > </script > <% } %>
</body >
</html >
html コピー
#grid {
--ig-size: var (--ig-size-medium);
}
css コピー
このサンプルが気に入りましたか? 完全な Ignite UI for Web Componentsツールキットにアクセスして、すばやく独自のアプリの作成を開始します。無料でダウンロードできます。
Ignite UI for Web Components Data Grid で作業を開始
依存関係
Web Components Data Grid を初期化するには、igniteui-webcomponents-grids
パッケージをインストールする必要があります。
npm install --save igniteui-webcomponents-grids
cmd
グリッドを使用するには、次のインポートも含める必要があります。
import 'igniteui-webcomponents-grids/grids/combined.js' ;
typescript
対応するスタイルも参照する必要があります。テーマ の 1 つにライトモードのオプションまたはダークモードのオプションを選択し、プロジェクト構成に基づいてインポートできます:
import 'igniteui-webcomponents-grids/grids/themes/light/bootstrap.css' ;
typescript
またはそれをリンクするには:
<link rel='stylesheet' href='node_modules/igniteui-webcomponents-grids/grids/themes/light/bootstrap.css' >
typescript
グリッドの外観をカスタマイズする方法の詳細については、スタイル設定 セクションを参照してください。
使用方法
グリッド パッケージをインポートしたので、基本的な構成と、ローカル データへのバインドから始めていきましょう。
<igc-grid id ="grid1" auto-generate ="true" > </igc-grid >
html
constructor ( ) {
let grid1 = document .getElementById("grid1" ) as IgcGridComponent;
grid1.data = data;
}
typescript
id
プロパティは文字列値で、設定されない場合に自動生成生成されるグリッドの一意識別子です。data
はグリッドをローカル データにバインドします。
autoGenerate
プロパティは、データ ソース フィールドに基づいてグリッドの IgcColumnComponent
コンポーネントを自動生成するようにグリッドに指示します。列の適切なデータ型の決定を試みます。それ以外の場合、開発者は列およびデータ ソース フィールドへのマッピングを明示的に定義する必要があります。
編集可能な Web Components グリッド
グリッド編集の各操作にはバッチ操作が含まれます。つまり、API には、編集を単一のサーバー呼び出しにグループ化するオプションがあります。または、グリッドの操作を使用して、グリッドの編集を実行したり、発生した操作を更新したりできます。CRUD 操作を備えた編集グリッドとしての優れた開発者エクスペリエンスに加えて、Angular グリッドには Excel のようなキーボード ナビゲーションが含まれます。一般的なデフォルトのグリッド ナビゲーションに加えて、お客様のニーズを満たすためにナビゲーション オプションを上書きするオプションが含まれています。優れたナビゲーション スキームを備えた編集可能なグリッドは、最新の業務アプリケーションにとって重要であり、Ignite UI グリッドを使用すると簡単になります。
このトピックに続いて、セル テンプレート とセル編集テンプレート および編集について詳しく学習します。
グリッドの列構成
IgcColumnComponent
は、グリッドの列コレクションを定義し、ソート やフィルタリング などの列ごとの機能を有効にするために使用されます。セル、ヘッダー、およびフッター テンプレートも利用できます。
列の定義
autoGenerate
プロパティを無効にし、マークアップで列コレクションを定義します。
<igc-grid id ="grid1" auto-generate ="false" allow-filtering ="true" >
<igc-column field ="Name" sortable ="true" header =" " > </igc-column >
<igc-column field ="AthleteNumber" sortable ="true" header ="Athlete number" filterable ="false" > </igc-column >
<igc-column id ="trackProgress" field ="TrackProgress" header ="Track progress" filterable ="false" > </igc-column >
</igc-grid >
html
constructor ( ) {
var grid1 = this .grid1 = document .getElementById('grid1' ) as IgcGridComponent;
grid1.data = this .data;
}
typescript
ヘッダー テンプレート
ヘッダー テンプレートを設定して、列ヘッダーを変更できます。以下のスニペットは、ヘッダー テキストを大文字に書式設定する方法を示しています。
<igc-column id ="name" field ="Name" > </igc-column >
html
constructor ( ) {
var name = this .name = document .getElementById('name' ) as IgcColumnComponent;
this ._bind = () => {
name.headerTemplate = this .nameHeaderTemplate;
}
this ._bind();
}
public nameHeaderTemplate = (ctx: IgcColumnTemplateContext ) => {
return html`
${this .formatUppercase(ctx.column.field)}
` ;
}
public formatUppercase (value: string ) {
return value.toUpperCase();
}
typescript
注 :
グループ化 / 移動機能と一緒にヘッダー テンプレートを使用すると、列ヘッダー領域はドラッグ可能になりヘッダー テンプレートのカスタム要素部分にドラッグ不可としてマークするまでアクセスできません。以下の例をご覧ください。
<igc-column id ="productName" field ="ProductName" header ="Product Name" groupable ="true" has-summary ="true" > </igc-column >
html
constructor ( ) {
var productName = this .productName = document .getElementById('productName' ) as IgcColumnComponent;
productName.headerTemplate = this .productNameHeaderTemplate;
}
public productNameHeaderTemplate = (ctx: IgcColumnTemplateContext ) => {
return html`
<div class ="text" > ${ctx.column.field} </div >
<igc-icon @click =" ${() => this .toggleSummary(ctx.column)} " name ="functions" draggable ="false" ></igc-icon >
` ;
}
public toggleSummary (column: IgcColumnComponent ) {
}
typescript
Draggable
属性を false に設定して追加しています。
セル テンプレート
セル テンプレートを設定すると、列内のすべてのセルが変更されます。テンプレートで提供されるコンテキスト オブジェクトは暗示的に提供されたセル値およびセル オブジェクトです。セルのテキストを書式設定できるテンプレートを定義するために使用できます。たとえば、タイトル ケースなどです。
<igc-column id ="name" field ="Name" > </igc-column >
html
constructor ( ) {
var name = this .name = document .getElementById('name' ) as IgcColumnComponent;
name.bodyTemplate = this .nameCellTemplate;
}
public nameCellTemplate = (ctx: IgcCellTemplateContext ) => {
return html`
${this .formatTitleCase(ctx.implicit)}
` ;
}
public formatTitleCase (value: string ) {
return value.toUpperCase();
}
typescript
上記のスニペットで暗示的に提供されたセル値への参照を取得します。データを表示し、セルの値にカスタム スタイル設定およびパイプ変換を適用する場合に使用します。ただし、Cell
インスタンスを以下のように使用するとより効果的です。
<igc-grid id ="grid" auto-generate ="false" >
<igc-column id ="name" field ="Name" data-type ="string" > </igc-column >
<igc-column id ="subscription" field ="Subscription" data-type ="boolean" > </igc-column >
</igc-grid >
html
constructor ( ) {
var grid = this .grid = document .getElementById('grid' ) as IgcGridComponent;
var name = this .name = document .getElementById('name' ) as IgcColumnComponent;
var subscription = this .subscription = document .getElementById('subscription' ) as IgcColumnComponent;
grid.data = this .data;
name.bodyTemplate = this .nameCellTemplate;
subscription.bodyTemplate = this .subscriptionCellTemplate;
}
public nameCellTemplate = (ctx: IgcCellTemplateContext ) => {
return html`
<span tabindex ="0" @keydown =" ${() => this .deleteRow(ctx.cell.id.rowIndex)} " >${this .formatTitleCase(ctx.cell.value)} </span >
` ;
}
public subscriptionCellTemplate = (ctx: IgcCellTemplateContext ) => {
if (ctx.cell.value) {
return html` <input type ="checkbox" checked /> ` ;
} else {
return html` <input type ="checkbox" /> ` ;
}
}
public deleteRow (rowIndex: number ) {
this .grid.deleteRow(rowIndex);
}
public formatTitleCase (value: string ) {
return value.toUpperCase();
}
typescript
注 :
グリッドは、数値、文字列、日付、およびブール列タイプのデフォルトの処理を公開します。例えば、ブール列タイプの場合に列はデフォルトで true/false の代わりに check
または close
アイコンを表示します。
適切に実装されると、セル編集テンプレートは、セルの EditValue
がグリッド編集イベント サイクル を正しく渡します。
セル編集テンプレート
列は、セルが編集モードにある場合に使用されるテンプレートを使用します。その他の列テンプレートと同じように、提供されるコンテキスト オブジェクトはセル値およびセル オブジェクトです。編集モード テンプレートをユーザー アクセス可能にするには、列の editable
プロパティを true に設定します。
<igc-column id ="price" field ="Price" data-type ="number" editable ="true" > </igc-column >
html
constructor ( ) {
var price = this .price = document .getElementById('price' ) as IgcColumnComponent;
price.inlineEditorTemplate = this .priceCellTemplate;
}
public priceCellTemplate = (ctx: IgcCellTemplateContext ) => {
return html`
<label >
Enter the new price tag
</label >
<input name ="price" type ="number" value =" ${ctx.cell.value} " @change =" ${() => this .updateValue(ctx.cell.value)} " />
` ;
}
public updateValue (value: number ) {
}
typescript
テンプレートで使用可能なプロパティの詳細については、Cell
の API を参照してください。
列テンプレート API
各列テンプレートが IgcColumnComponent
オブジェクトでコードによって変更可能です。以下のコード例で、ユーザー データの 2 つのテンプレートを宣言しました。TypeScript コードでテンプレートへの参照を取得し、条件に基づいてアプリケーションで列の適切なテンプレートを描画します。
<igc-grid >
</igc-grid >
html
var user = this .user = document .getElementById('user' ) as IgcColumnComponent;
user.bodyTemplate = this .smallView;
public normalViewTemplate = (ctx: IgcCellTemplateContext ) => {
return html`
<div class ="user-details" > ${ ctx.cell.value } </div >
<user-details-component > </user-details-component >
` ;
}
public smallViewTemplate = (ctx: IgcCellTemplateContext ) => {
return html`
<div class ="user-details-small" > ${ ctx.cell.value } </div >
` ;
}
typescript
列プロパティもグリッドで列が初期化されるときに発生される ColumnInit
イベントのコードで設定できます。
public initColumns (column: IgcGridColumn ) {
if (column.field === 'ProductName' ) {
column.sortable = true ;
column.editable = true ;
}
}
typescript
上記のコードは ProductName 列のソートや編集機能を有効にし、対応する機能の UI (編集の入力など) をインスタンス化します。
カスタム表示形式
書式設定のためのオプションのパラメーターがあります:
format
- 表示される日付 / 時間部分を決定します。デフォルト 'mediumDate'
です ('MMM d, y' )。
timezone
- 日付のタイムゾーン オフセット。デフォルトでは、エンドユーザーのローカル システムのタイムゾーンを使用します。
digitsInfo
- 10 進表現オブジェクト。デフォルトの設定は 1.0-3 です。
これらのパラメーターによって表示形式をカスタマイズできるようにするには、pipeArgs
入力公開します。pipeArgs
が設定されている場合、列はそのデータ型の対応するプロパティのみに遵守します。例:
<igc-column id ="orderDate" field ="OrderDate" data-type ="date" > </igc-column >
html
private _columnPipeArgs: any | null = null ;
public get columnPipeArgs (): any {
if (this ._columnPipeArgs == null )
{
var columnPipeArgs: any = {};
columnPipeArgs.format = "longDate" ;
columnPipeArgs.timezone = "UTC" ;
columnPipeArgs.digitsInfo = "1.2-2"
this ._columnPipeArgs = columnPipeArgs;
}
return this ._columnPipeArgs;
}
constructor ( ) {
var orderDate = this .orderDate = document .getElementById('orderDate' ) as IgcColumnComponent;
orderDate.pipeArgs = this .columnPipeArgs;
}
typescript
OrderDate
列は format
および timezone
プロパティのみに遵守しますが、UnitPrice
は digitsInfo
のみに遵守します。
すべての利用可能な列データ型は、公式の列タイプ トピック にあります。
グリッド データの構造
IgcGridComponent
はフラット データ とネストされた POJO (Plain old Java objects) を処理します。描画に固有のデータ構造はフォームにあります。
const OBJECT_ARRAY = [{
ObjectKey1 : value1,
ObjectKey2 : value2,
ObjectKeyN : valueN
},
}];
const POJO = [{
ObjectKey1 : value1,
ObjectKey2 : value2,
ObjectKeyN : {
ObjectKeyN1 : value1,
ObjectKeyN2 : value2,
ObjectKeyNM : valueNM,
}
},
}];
typescript
警告 :
キー値に配列を含まないでください。
autoGenerate
列を使用する場合、データ キーが同一である必要があります 。
グリッドのデータ バインディング
はじめにリモート データ サービスにバインドするためにグリッドを変更します。大規模なアプリケーション レベルでは一般的なシナリオです。
これを行うには、JSON 応答を受信して指定された URL からデータを取得し、それをグリッドのデータ ソースとして使用されるグリッドの data
プロパティに割り当てます。
<igc-grid id ="grid1" > </igc-grid >
html
public fetchData(url: string ): void {
fetch(url)
.then(response => response.json())
.then(data => this .onDataLoaded(data));
}
public onDataLoaded (jsonData: any [] ) {
var grid1 = document .getElementById("grid1" ) as IgcGridComponent;
grid1.data = jsonData;
}
typescript
注 : リモート データにバインドする場合、グリッドの autoGenerate
プロパティは使用しないことをお勧めします。データを検証して適切な列を生成するためにデータが利用可能である必要があります。リモート サービスの応答が完了するまでデータが利用できないため、グリッドはエラーを発生します。リモート サービスへバインド時に autoGenerate
を使用する機能は今後追加予定です。
複雑なデータ バインディング
IgcGridComponent
は、データ レコード内のプロパティのパスを介した複合オブジェクト (1 レベルより深いネストを含む) へのバインドをサポートします。
次のデータ モデルを見てください。
interface AminoAcid {
name : string ;
abbreviation: {
short : string ;
long: string ;
}
weight : {
molecular : number ;
residue: number ;
},
formula : {
molecular : string ;
residue: string ;
}
}
typescript
たとえば、グリッド内の特定のアミノ酸の重みを表示するには、次のスニペットで十分です。
<igc-column field ="weight.molecular" > </igc-column >
<igc-column field ="weight.residue" > </igc-column >
html
IgcGridComponent
で複雑なデータをバインドまたは複合データ (複数の列から) を可視化する別の方法は、列にカスタム ボディ テンプレートを使用することです。通常、以下のことができます。
ネストされたデータを含むセルの value
を使用します。
テンプレート内の cell
オブジェクトを使用し、そこから ctx.cell.id.rowIndex
または ctx.cell.id.rowID
にアクセスして、グリッドの API 経由で行を取得します。そこから任意の値を取得し、テンプレートに補間します。
<igc-column id ="abbreviationLong" field ="abbreviation.long" > </igc-column >
html
constructor ( ) {
var grid = (this .grid = document .getElementById("grid" ) as IgcGridComponent);
var abbreviationLong = this .abbreviationLong = document .getElementById('abbreviationLong' ) as IgcColumnComponent;
abbreviationLong.bodyTemplate = this .abbreviationLongCellTemplate;
}
public abbreviationLongCellTemplate = (ctx: IgcCellTemplateContext ) => {
return html`
<div >
<div >
${ ctx.cell.value }
${this .getName(ctx.cell.id.rowIndex)}
${this .getWeight(ctx.cell.id.rowIndex)}
</div >
</div >
` ;
}
public getName (rowIndex: number ) {
return this .grid.getRowByIndex(rowIndex).data["Name" ];
}
public getWeight (rowIndex: number ) {
return this .grid.getRowByIndex(rowIndex).data["weight" ]["molecular" ];
}
typescript
本文テンプレートを使用して複雑なデータを表示する方法の例を次に示します。以下は使用するデータです。
export const EMPLOYEE_DATA = [
{
Age : 55 ,
Employees : [
{
Age : 43 ,
HireDate : new Date (2011 , 6 , 3 ),
ID : 3 ,
Name : "Michael Burke" ,
Title : "Senior Software Developer"
},
{
Age : 29 ,
HireDate : new Date (2009 , 6 , 19 ),
ID : 2 ,
Name : "Thomas Anderson" ,
Title : "Senior Software Developer"
},
{
Age : 31 ,
HireDate : new Date (2014 , 8 , 18 ),
ID : 11 ,
Name : "Monica Reyes" ,
Title : "Software Development Team Lead"
},
{
Age : 35 ,
HireDate : new Date (2015 , 9 , 17 ),
ID : 6 ,
Name : "Roland Mendel" ,
Title : "Senior Software Developer"
}],
HireDate : new Date (2008 , 3 , 20 ),
ID : 1 ,
Name : "John Winchester" ,
Title : "Development Manager"
}
]
typescript
ネスト データをレンダリングする列のカスタム テンプレート。
<igc-column id ="employees" field ="Employees" header ="Employees" width ="40%" > </igc-column >
html
constructor ( ) {
var employees = this .employees = document .getElementById('employees' ) as IgcColumnComponent;
employees.bodyTemplate = this .addressCellTemplate;
}
public addressCellTemplate = (ctx: IgcCellTemplateContext ) => {
return html`
<igc-expansion-panel >
<div slot ="title" style ="font-size: 1.1em; font-weight: bold; margin-top: 1rem; margin-bottom: 0.25rem;" >
${ctx.cell.value[0 ].Name}
</div >
<div class ="description" >
<div style ="display: flex; align-items: center;" >
<div for ="title" style ="width: 2rem; margin: 0rem;" > Title</div >
<input id ='Title' type ="text" name ="title" value =" ${ctx.cell.value[0 ].Title} " style ="text-overflow: ellipsis;" />
</div >
<div style ="display: flex; align-items: center;" >
<div for ="age" style ="width: 2rem; margin: 0rem;" > Age</div >
<input id ='Age' type ="text" name ="title" value =" ${ctx.cell.value[0 ].Age} " style ="text-overflow: ellipsis;" />
</div >
</div >
</igc-expansion-panel >
` ;
}
typescript
以下は、この設定の結果です。
export class EmployeesNestedDataItem {
public constructor (init: Partial<EmployeesNestedDataItem> ) {
Object .assign(this , init);
}
public ID: number ;
public Age: number ;
public Salary: number ;
public Productivity: number ;
public City: string ;
public Country: string ;
public Phone: string ;
public HireDate: string ;
public Name: string ;
public Title: string ;
public Employees: EmployeesNestedDataItem_EmployeesItem[];
}
export class EmployeesNestedDataItem_EmployeesItem {
public constructor (init: Partial<EmployeesNestedDataItem_EmployeesItem> ) {
Object .assign(this , init);
}
public Age: number ;
public Salary: number ;
public Productivity: number ;
public City: string ;
public Country: string ;
public Phone: string ;
public HireDate: string ;
public ID: number ;
public Name: string ;
public Title: string ;
}
export class EmployeesNestedData extends Array <EmployeesNestedDataItem > {
public constructor (items: Array <EmployeesNestedDataItem> | number = -1 ) {
if (Array .isArray(items)) {
super (...items);
} else {
const newItems = [
new EmployeesNestedDataItem(
{
ID : 1 ,
Age : 55 ,
Salary : 80000 ,
Productivity : 90 ,
City : `Berlin` ,
Country : `Germany` ,
Phone : `609-202-505` ,
HireDate : `2008-03-20` ,
Name : `John Winchester` ,
Title : `Development Manager` ,
Employees : [
new EmployeesNestedDataItem_EmployeesItem(
{
Age : 43 ,
Salary : 70000 ,
Productivity : 80 ,
City : `Hamburg` ,
Country : `Germany` ,
Phone : `609-444-555` ,
HireDate : `2011-06-03` ,
ID : 3 ,
Name : `Michael Burke` ,
Title : `Senior Software Developer`
}),
new EmployeesNestedDataItem_EmployeesItem(
{
Age : 29 ,
Salary : 60000 ,
Productivity : 80 ,
City : `Munich` ,
Country : `Germany` ,
Phone : `609-333-444` ,
HireDate : `2009-06-19` ,
ID : 2 ,
Name : `Thomas Anderson` ,
Title : `Senior Software Developer`
}),
new EmployeesNestedDataItem_EmployeesItem(
{
Age : 31 ,
Salary : 90000 ,
Productivity : 80 ,
City : `Warasw` ,
Country : `Poland` ,
Phone : `609-222-205` ,
HireDate : `2014-08-18` ,
ID : 11 ,
Name : `Monica Reyes` ,
Title : `Software Development Team Lead`
}),
new EmployeesNestedDataItem_EmployeesItem(
{
Age : 35 ,
Salary : 70000 ,
Productivity : 70 ,
City : `Koln` ,
Country : `Germany` ,
Phone : `609-502-525` ,
HireDate : `2015-09-17` ,
ID : 6 ,
Name : `Roland Mendel` ,
Title : `Senior Software Developer`
})]
}),
new EmployeesNestedDataItem(
{
ID : 4 ,
Age : 42 ,
Salary : 90000 ,
Productivity : 80 ,
City : `Kielce` ,
Country : `Poland` ,
Phone : `609-202-505` ,
HireDate : `2014-01-22` ,
Name : `Ana Sanders` ,
Title : `CEO` ,
Employees : [
new EmployeesNestedDataItem_EmployeesItem(
{
Age : 44 ,
Salary : 80000 ,
Productivity : 80 ,
City : `Warasw` ,
Country : `Poland` ,
Phone : `609-202-505` ,
HireDate : `2014-04-04` ,
ID : 14 ,
Name : `Laurence Johnson` ,
Title : `Director`
}),
new EmployeesNestedDataItem_EmployeesItem(
{
Age : 25 ,
Salary : 85000 ,
Productivity : 55 ,
City : `Paris` ,
Country : `France` ,
Phone : `609-202-505` ,
HireDate : `2017-11-09` ,
ID : 5 ,
Name : `Elizabeth Richards` ,
Title : `Vice President`
}),
new EmployeesNestedDataItem_EmployeesItem(
{
Age : 39 ,
Salary : 88000 ,
Productivity : 88 ,
City : `London` ,
Country : `UK` ,
Phone : `609-202-505` ,
HireDate : `2010-03-22` ,
ID : 13 ,
Name : `Trevor Ashworth` ,
Title : `Director`
})]
}),
new EmployeesNestedDataItem(
{
ID : 18 ,
Age : 49 ,
Salary : 77000 ,
Productivity : 70 ,
City : `Manchester` ,
Country : `UK` ,
Phone : `222-555-577` ,
HireDate : `2014-01-22` ,
Name : `Victoria Lincoln` ,
Title : `Senior Accountant` ,
Employees : [
new EmployeesNestedDataItem_EmployeesItem(
{
Age : 43 ,
Salary : 70000 ,
Productivity : 80 ,
City : `Hamburg` ,
Country : `Germany` ,
Phone : `609-444-555` ,
HireDate : `2011-06-03` ,
ID : 23 ,
Name : `Thomas Burke` ,
Title : `Senior Accountant`
}),
new EmployeesNestedDataItem_EmployeesItem(
{
Age : 29 ,
Salary : 60000 ,
Productivity : 80 ,
City : `Munich` ,
Country : `Germany` ,
Phone : `609-333-444` ,
HireDate : `2009-06-19` ,
ID : 22 ,
Name : `Michael Anderson` ,
Title : `Junior Accountant`
}),
new EmployeesNestedDataItem_EmployeesItem(
{
Age : 31 ,
Salary : 90000 ,
Productivity : 80 ,
City : `Warasw` ,
Country : `Poland` ,
Phone : `609-222-205` ,
HireDate : `2014-08-18` ,
ID : 21 ,
Name : `Roland Reyes` ,
Title : `Accountant Team Lead`
}),
new EmployeesNestedDataItem_EmployeesItem(
{
Age : 35 ,
Salary : 70000 ,
Productivity : 70 ,
City : `Koln` ,
Country : `Germany` ,
Phone : `609-502-525` ,
HireDate : `2015-09-17` ,
ID : 24 ,
Name : `Monica Mendel` ,
Title : `Senior Software Developer`
})]
}),
new EmployeesNestedDataItem(
{
ID : 10 ,
Age : 61 ,
Salary : 85000 ,
Productivity : 890 ,
City : `Lyon` ,
Country : `France` ,
Phone : `259-266-887` ,
HireDate : `2010-01-01` ,
Name : `Yang Wang` ,
Title : `Localization Developer` ,
Employees : [
new EmployeesNestedDataItem_EmployeesItem(
{
Age : 31 ,
Salary : 90000 ,
Productivity : 80 ,
City : `Warasw` ,
Country : `Poland` ,
Phone : `609-222-205` ,
HireDate : `2014-08-18` ,
ID : 11 ,
Name : `Monica Reyes` ,
Title : `Software Development Team Lead`
}),
new EmployeesNestedDataItem_EmployeesItem(
{
Age : 35 ,
Salary : 70000 ,
Productivity : 70 ,
City : `Koln` ,
Country : `Germany` ,
Phone : `609-502-525` ,
HireDate : `2015-09-17` ,
ID : 6 ,
Name : `Roland Mendel` ,
Title : `Senior Software Developer`
})]
}),
new EmployeesNestedDataItem(
{
ID : 35 ,
Age : 35 ,
Salary : 75000 ,
Productivity : 75 ,
City : `Warasw` ,
Country : `Poland` ,
Phone : `688-244-844` ,
HireDate : `2014-01-22` ,
Name : `Janine Munoz` ,
Title : `HR` ,
Employees : [
new EmployeesNestedDataItem_EmployeesItem(
{
Age : 43 ,
Salary : 70000 ,
Productivity : 80 ,
City : `Hamburg` ,
Country : `Germany` ,
Phone : `609-444-555` ,
HireDate : `2011-06-03` ,
ID : 3 ,
Name : `Michael Burke` ,
Title : `Senior Software Developer`
}),
new EmployeesNestedDataItem_EmployeesItem(
{
Age : 31 ,
Salary : 90000 ,
Productivity : 80 ,
City : `Warasw` ,
Country : `Poland` ,
Phone : `609-222-205` ,
HireDate : `2014-08-18` ,
ID : 11 ,
Name : `Monica Reyes` ,
Title : `Software Development Team Lead`
})]
}),
new EmployeesNestedDataItem(
{
ID : 10 ,
Age : 49 ,
Salary : 95000 ,
Productivity : 80 ,
City : `Krakow` ,
Country : `Poland` ,
Phone : `677-266-555` ,
HireDate : `2010-01-01` ,
Name : `Yang Wang` ,
Title : `Sales Manager` ,
Employees : [
new EmployeesNestedDataItem_EmployeesItem(
{
Age : 29 ,
Salary : 60000 ,
Productivity : 80 ,
City : `Munich` ,
Country : `Germany` ,
Phone : `609-333-444` ,
HireDate : `2009-06-19` ,
ID : 2 ,
Name : `Thomas Anderson` ,
Title : `Senior Software Developer`
}),
new EmployeesNestedDataItem_EmployeesItem(
{
Age : 35 ,
Salary : 70000 ,
Productivity : 70 ,
City : `Koln` ,
Country : `Germany` ,
Phone : `609-502-525` ,
HireDate : `2015-09-17` ,
ID : 6 ,
Name : `Roland Mendel` ,
Title : `Senior Software Developer`
})]
}),
];
super (...newItems.slice(0 ));
}
}
}
ts コピー import 'igniteui-webcomponents-grids/grids/combined' ;
import { IgcGridComponent, IgcColumnComponent } from 'igniteui-webcomponents-grids/grids' ;
import { EmployeesNestedDataItem, EmployeesNestedDataItem_EmployeesItem, EmployeesNestedData } from './EmployeesNestedData' ;
import { IgcCellTemplateContext } from 'igniteui-webcomponents-grids/grids' ;
import { html, nothing } from 'lit-html' ;
import "igniteui-webcomponents-grids/grids/themes/light/bootstrap.css" ;
import 'igniteui-webcomponents/themes/light/bootstrap.css' ;
import { defineAllComponents } from 'igniteui-webcomponents' ;
defineAllComponents();
import "./index.css" ;
export class Sample {
private grid: IgcGridComponent
private column1: IgcColumnComponent
private _bind: () => void ;
constructor ( ) {
var grid = this .grid = document .getElementById('grid' ) as IgcGridComponent;
var column1 = this .column1 = document .getElementById('column1' ) as IgcColumnComponent;
this ._bind = () => {
grid.data = this .employeesNestedData;
column1.bodyTemplate = this .webGridNestedDataCellTemplate;
}
this ._bind();
}
private _employeesNestedData: EmployeesNestedData = null ;
public get employeesNestedData (): EmployeesNestedData {
if (this ._employeesNestedData == null )
{
this ._employeesNestedData = new EmployeesNestedData();
}
return this ._employeesNestedData;
}
public webGridNestedDataCellTemplate = (ctx: IgcCellTemplateContext ) => {
if (ctx.cell.value != null ) {
if (ctx.cell.value.length === 0 ) return html`` ;
return html`
<igc-expansion-panel >
<div slot ="title" style ="font-size: 1.1em; font-weight: bold; margin-top: 1rem; margin-bottom: 0.25rem;" >
${ctx.cell.value[0 ].Name}
</div >
<div class ="description" >
<igc-input label ='Title' type ="text" name ="title" value =" ${ctx.cell.value[0 ].Title} " style ="text-overflow: ellipsis;" ></igc-input >
<igc-input label ="Age" type ="text" name ="title" value =" ${ctx.cell.value[0 ].Age} " style ="text-overflow: ellipsis;" ></igc-input >
</div >
</igc-expansion-panel >
` ;
}
return nothing;
};
}
new Sample();
ts コピー <!DOCTYPE html >
<html >
<head >
<title > Sample | Ignite UI | Web Components | infragistics</title >
<meta charset ="UTF-8" />
<link rel ="shortcut icon" href ="https://static.infragistics.com/xplatform/images/browsers/wc.png" >
<link rel ="stylesheet" href ="https://fonts.googleapis.com/icon?family=Material+Icons" />
<link rel ="stylesheet" href ="https://fonts.googleapis.com/css?family=Kanit&display=swap" />
<link rel ="stylesheet" href ="https://fonts.googleapis.com/css?family=Titillium Web" />
<link rel ="stylesheet" href ="https://static.infragistics.com/xplatform/css/samples/shared.v8.css" />
<link rel ="stylesheet" href ="/src/index.css" type ="text/css" />
</head >
<body >
<div id ="root" >
<div class ="container sample ig-typography" >
<div class ="container fill" >
<igc-grid
auto-generate ="false"
name ="grid"
id ="grid"
id ="grid" >
<igc-column
header ="Name"
field ="Name"
width ="15%" >
</igc-column >
<igc-column
field ="Title"
header ="Title"
width ="15%" >
</igc-column >
<igc-column
field ="Salary"
header ="Salary"
width ="10%" >
</igc-column >
<igc-column
field ="Employees"
header ="Employees"
width ="20%"
name ="column1"
id ="column1" >
</igc-column >
<igc-column
field ="City"
header ="City"
width ="15%" >
</igc-column >
<igc-column
field ="Country"
header ="Country"
width ="15%" >
</igc-column >
<igc-column
field ="Age"
header ="Age"
width ="10%" >
</igc-column >
<igc-column
field ="HireDate"
header ="Hire Date"
data-type ="date" >
</igc-column >
</igc-grid >
</div >
</div >
</div >
<% if (false) { %><script src ="src/index.ts" > </script > <% } %>
</body >
</html >
html コピー
フラット データの操作の概要
フラット データ バインディングのアプローチは既に説明したものと似ていますが、セル値 の代わりに、IgcGridRow
の data
プロパティを使用します。
Web Components グリッドはデータ レコードをレンダリング 、操作 、保存する ためのコンポーネントのため、すべてのデータ レコード へアクセスすることで、それを処理する方法をカスタマイズすることができます。それには、data
プロパティを使用します。
以下は使用するデータです。
export const DATA: any [] = [
{
Address : "Obere Str. 57" ,
City : "Berlin" ,
CompanyName : "Alfreds Futterkiste" ,
ContactName : "Maria Anders" ,
ContactTitle : "Sales Representative" ,
Country : "Germany" ,
Fax : "030-0076545" ,
ID : "ALFKI" ,
Phone : "030-0074321" ,
PostalCode : "12209" ,
Region : null
}
]
typescript
カスタム テンプレート:
<igc-column id ="address" field ="Address" header ="Address" width ="25%" editable ="true" > </igc-column >
html
constructor ( ) {
var address = this .address = document .getElementById('address' ) as IgcColumnComponent;
address.bodyTemplate = this .addressCellTemplate;
}
public addressCellTemplate = (ctx: IgcCellTemplateContext ) => {
return html`
<div class ="address-container" >
<span > <strong > Country:</strong > ${this .getCountry(ctx.cell.id.rowIndex)} </span >
<br />
<span > <strong > City:</strong > ${this .getCity(ctx.cell.id.rowIndex)} </span >
<br />
<span > <strong > Postal Code:</strong > ${this .getPostalCode(ctx.cell.id.rowIndex)} </span >
</div >
` ;
}
public getCountry (rowIndex: number ) {
return this .grid.getRowByIndex(rowIndex).data["Country" ];
}
public getCity (rowIndex: number ) {
return this .grid.getRowByIndex(rowIndex).data["City" ];
}
public getPostalCode (rowIndex: number ) {
return this .grid.getRowByIndex(rowIndex).data["PostalCode" ];
}
typescript
上記で定義したテンプレートでは編集操作ができないため、エディター テンプレートが必要であることに注意してください。
<igc-column id ="address" field ="Address" data-type ="number" width ="25%" editable ="true" > </igc-column >
html
constructor ( ) {
var address = this .address = document .getElementById('address' ) as IgcColumnComponent;
address.inlineEditorTemplate = this .webGridCompositeAddressEditCellTemplate;
}
public webGridCompositeAddressEditCellTemplate = (ctx: IgcCellTemplateContext ) => {
var cell = ctx.cell as any ;
if (cell === undefined || cell.row === undefined || cell.row.data === undefined ) {
return html``
}
function keyUpHandler (event: any , ctx: IgcCellTemplateContext ) {
var cell = ctx.cell as any ;
if (cell !== undefined && cell.row !== undefined && cell.row.data !== undefined ) {
cell.row.data[event.target.id] = event.target.value;
}
}
return html`<div class ="address-container--edit" style ="display: inline-grid" >
<div >
<span > <strong > Country:</strong > </span >
<input id ='Country' @keyup = ${(e: any ) => keyUpHandler(e, ctx)} value =" ${cell.row.data.Country} " ></input >
<br >
<span > <strong > City:</strong > </span >
<input id ='City' @keyup = ${(e: any ) => keyUpHandler(e, ctx)} value =" ${cell.row.data.City} " ></input >
</div >
<div >
<span > <strong > Postal Code:</strong > </span >
<input id ='PostalCode' @keyup = ${(e: any ) => keyUpHandler(e, ctx)} value =" ${cell.row.data.PostalCode} " ></input >
<br >
<span > <strong > Selected:</strong > </span >
<input id ='Phone' @keyup = ${(e: any ) => keyUpHandler(e, ctx)} value =" ${cell.row.data.Phone} " ></input >
</div >
<br >
</div > ` ;
}
typescript
フラット データの操作の例
前のセクションのコード スニペットを使用すると、次の IgcGridComponent
の例になります。
export class CustomersDataItem {
public constructor (init: Partial<CustomersDataItem> ) {
Object .assign(this , init);
}
public ID: string ;
public Company: string ;
public ContactName: string ;
public ContactTitle: string ;
public Address: string ;
public City: string ;
public Region: string ;
public PostalCode: number ;
public Country: string ;
public Phone: string ;
public Fax: string ;
}
export class CustomersData extends Array <CustomersDataItem > {
public constructor (items: Array <CustomersDataItem> | number = -1 ) {
if (Array .isArray(items)) {
super (...items);
} else {
const newItems = [
new CustomersDataItem(
{
ID : `ALFKI` ,
Company : `Alfreds Futterkiste` ,
ContactName : `Maria Anders` ,
ContactTitle : `Sales Representative` ,
Address : `Obere Str. 57` ,
City : `Berlin` ,
Region : `East` ,
PostalCode : 12209 ,
Country : `Germany` ,
Phone : `030-0074321` ,
Fax : `030-0076545`
}),
new CustomersDataItem(
{
ID : `ANATR` ,
Company : `Ana Trujillo Emparedados y helados` ,
ContactName : `Ana Trujillo` ,
ContactTitle : `Owner` ,
Address : `Avda. de la Constitución 2222` ,
City : `México D.F.` ,
Region : `South` ,
PostalCode : 5021 ,
Country : `Mexico` ,
Phone : `(5) 555-4729` ,
Fax : `(5) 555-3745`
}),
new CustomersDataItem(
{
ID : `ANTON` ,
Company : `Antonio Moreno Taquería` ,
ContactName : `Antonio Moreno` ,
ContactTitle : `Owner` ,
Address : `Mataderos 2312` ,
City : `México D.F.` ,
Region : `South` ,
PostalCode : 5023 ,
Country : `Mexico` ,
Phone : `(5) 555-3932` ,
Fax : `(5) 555-3745`
}),
new CustomersDataItem(
{
ID : `AROUT` ,
Company : `Around the Horn` ,
ContactName : `Thomas Hardy` ,
ContactTitle : `Sales Representative` ,
Address : `120 Hanover Sq.` ,
City : `London` ,
Region : `East` ,
PostalCode : 22000 ,
Country : `UK` ,
Phone : `(171) 555-7788` ,
Fax : `(171) 555-6750`
}),
new CustomersDataItem(
{
ID : `BERGS` ,
Company : `Berglunds snabbköp` ,
ContactName : `Christina Berglund` ,
ContactTitle : `Order Administrator` ,
Address : `Berguvsvägen 8` ,
City : `Luleå` ,
Region : `South` ,
PostalCode : 17000 ,
Country : `Sweden` ,
Phone : `0921-12 34 65` ,
Fax : `0921-12 34 67`
}),
new CustomersDataItem(
{
ID : `BLAUS` ,
Company : `Blauer See Delikatessen` ,
ContactName : `Hanna Moos` ,
ContactTitle : `Sales Representative` ,
Address : `Forsterstr. 57` ,
City : `Mannheim` ,
Region : `East` ,
PostalCode : 68306 ,
Country : `Germany` ,
Phone : `0621-08460` ,
Fax : `0621-08924`
}),
new CustomersDataItem(
{
ID : `BLONP` ,
Company : `Blondesddsl père et fils` ,
ContactName : `Frédérique Citeaux` ,
ContactTitle : `Marketing Manager` ,
Address : `24, place Kléber` ,
City : `Strasbourg` ,
Region : `East` ,
PostalCode : 67000 ,
Country : `France` ,
Phone : `88.60.15.31` ,
Fax : `88.60.15.32`
}),
new CustomersDataItem(
{
ID : `BOLID` ,
Company : `Bólido Comidas preparadas` ,
ContactName : `Martín Sommer` ,
ContactTitle : `Owner` ,
Address : `C/ Araquil, 67` ,
City : `Madrid` ,
Region : `East` ,
PostalCode : 28023 ,
Country : `Spain` ,
Phone : `(91) 555 22 82` ,
Fax : `(91) 555 91 99`
}),
new CustomersDataItem(
{
ID : `BONAP` ,
Company : `Bon app'` ,
ContactName : `Laurence Lebihan` ,
ContactTitle : `Owner` ,
Address : `12, rue des Bouchers` ,
City : `Marseille` ,
Region : `West` ,
PostalCode : 13008 ,
Country : `France` ,
Phone : `91.24.45.40` ,
Fax : `91.24.45.41`
}),
new CustomersDataItem(
{
ID : `BOTTM` ,
Company : `Bottom-Dollar Markets` ,
ContactName : `Elizabeth Lincoln` ,
ContactTitle : `Accounting Manager` ,
Address : `23 Tsawassen Blvd.` ,
City : `Tsawassen` ,
Region : `BC` ,
PostalCode : 28000 ,
Country : `Canada` ,
Phone : `(604) 555-4729` ,
Fax : `(604) 555-3745`
}),
new CustomersDataItem(
{
ID : `BSBEV` ,
Company : `B's Beverages` ,
ContactName : `Victoria Ashworth` ,
ContactTitle : `Sales Representative` ,
Address : `Fauntleroy Circus` ,
City : `London` ,
Region : `South` ,
PostalCode : 10000 ,
Country : `UK` ,
Phone : `(171) 555-1212` ,
Fax : `(5) 555-3745`
}),
new CustomersDataItem(
{
ID : `CACTU` ,
Company : `Cactus Comidas para llevar` ,
ContactName : `Patricio Simpson` ,
ContactTitle : `Sales Agent` ,
Address : `Cerrito 333` ,
City : `Buenos Aires` ,
Region : `East` ,
PostalCode : 1010 ,
Country : `Argentina` ,
Phone : `(1) 135-5555` ,
Fax : `(1) 135-4892`
}),
new CustomersDataItem(
{
ID : `CENTC` ,
Company : `Centro comercial Moctezuma` ,
ContactName : `Francisco Chang` ,
ContactTitle : `Marketing Manager` ,
Address : `Sierras de Granada 9993` ,
City : `México D.F.` ,
Region : `South` ,
PostalCode : 5022 ,
Country : `Mexico` ,
Phone : `(5) 555-3392` ,
Fax : `(5) 555-7293`
}),
new CustomersDataItem(
{
ID : `CHOPS` ,
Company : `Chop-suey Chinese` ,
ContactName : `Yang Wang` ,
ContactTitle : `Owner` ,
Address : `Hauptstr. 29` ,
City : `Bern` ,
Region : `East` ,
PostalCode : 3012 ,
Country : `Switzerland` ,
Phone : `0452-076545` ,
Fax : `(5) 555-3745`
}),
new CustomersDataItem(
{
ID : `COMMI` ,
Company : `Comércio Mineiro` ,
ContactName : `Pedro Afonso` ,
ContactTitle : `Sales Associate` ,
Address : `Av. dos Lusíadas, 23` ,
City : `Sao Paulo` ,
Region : `SP` ,
PostalCode : 34000 ,
Country : `Brazil` ,
Phone : `(11) 555-7647` ,
Fax : `(5) 555-3745`
}),
new CustomersDataItem(
{
ID : `CONSH` ,
Company : `Consolidated Holdings` ,
ContactName : `Elizabeth Brown` ,
ContactTitle : `Sales Representative` ,
Address : `Berkeley Gardens 12 Brewery` ,
City : `London` ,
Region : `South` ,
PostalCode : 27000 ,
Country : `UK` ,
Phone : `(171) 555-2282` ,
Fax : `(171) 555-9199`
}),
new CustomersDataItem(
{
ID : `DRACD` ,
Company : `Drachenblut Delikatessen` ,
ContactName : `Sven Ottlieb` ,
ContactTitle : `Order Administrator` ,
Address : `Walserweg 21` ,
City : `Aachen` ,
Region : `South` ,
PostalCode : 52066 ,
Country : `Germany` ,
Phone : `0241-039123` ,
Fax : `0241-059428`
}),
new CustomersDataItem(
{
ID : `DUMON` ,
Company : `Du monde entier` ,
ContactName : `Janine Labrune` ,
ContactTitle : `Owner` ,
Address : `67, rue des Cinquante Otages` ,
City : `Nantes` ,
Region : `East` ,
PostalCode : 44000 ,
Country : `France` ,
Phone : `40.67.88.88` ,
Fax : `40.67.89.89`
}),
new CustomersDataItem(
{
ID : `EASTC` ,
Company : `Eastern Connection` ,
ContactName : `Ann Devon` ,
ContactTitle : `Sales Agent` ,
Address : `35 King George` ,
City : `London` ,
Region : `East` ,
PostalCode : 41000 ,
Country : `UK` ,
Phone : `(171) 555-0297` ,
Fax : `(171) 555-3373`
}),
new CustomersDataItem(
{
ID : `ERNSH` ,
Company : `Ernst Handel` ,
ContactName : `Roland Mendel` ,
ContactTitle : `Sales Manager` ,
Address : `Kirchgasse 6` ,
City : `Graz` ,
Region : `South` ,
PostalCode : 8010 ,
Country : `Austria` ,
Phone : `7675-3425` ,
Fax : `7675-3426`
}),
new CustomersDataItem(
{
ID : `FAMIA` ,
Company : `Familia Arquibaldo` ,
ContactName : `Aria Cruz` ,
ContactTitle : `Marketing Assistant` ,
Address : `Rua Orós, 92` ,
City : `Sao Paulo` ,
Region : `SP` ,
PostalCode : 27000 ,
Country : `Brazil` ,
Phone : `(11) 555-9857` ,
Fax : `(5) 555-3745`
}),
new CustomersDataItem(
{
ID : `FISSA` ,
Company : `FISSA Fabrica Inter. Salchichas S.A.` ,
ContactName : `Diego Roel` ,
ContactTitle : `Accounting Manager` ,
Address : `C/ Moralzarzal, 86` ,
City : `Madrid` ,
Region : `East` ,
PostalCode : 28034 ,
Country : `Spain` ,
Phone : `(91) 555 94 44` ,
Fax : `(91) 555 55 93`
}),
new CustomersDataItem(
{
ID : `FOLIG` ,
Company : `Folies gourmandes` ,
ContactName : `Martine Rancé` ,
ContactTitle : `Assistant Sales Agent` ,
Address : `184, chaussée de Tournai` ,
City : `Lille` ,
Region : `South` ,
PostalCode : 59000 ,
Country : `France` ,
Phone : `20.16.10.16` ,
Fax : `20.16.10.17`
}),
new CustomersDataItem(
{
ID : `FOLKO` ,
Company : `Folk och fä HB` ,
ContactName : `Maria Larsson` ,
ContactTitle : `Owner` ,
Address : `Åkergatan 24` ,
City : `Bräcke` ,
Region : `East` ,
PostalCode : 36000 ,
Country : `Sweden` ,
Phone : `0695-34 67 21` ,
Fax : `0695 33-4455`
}),
new CustomersDataItem(
{
ID : `FRANK` ,
Company : `Frankenversand` ,
ContactName : `Peter Franken` ,
ContactTitle : `Marketing Manager` ,
Address : `Berliner Platz 43` ,
City : `München` ,
Region : `East` ,
PostalCode : 80805 ,
Country : `Germany` ,
Phone : `089-0877310` ,
Fax : `089-0877451`
}),
new CustomersDataItem(
{
ID : `FRANR` ,
Company : `France restauration` ,
ContactName : `Carine Schmitt` ,
ContactTitle : `Marketing Manager` ,
Address : `54, rue Royale` ,
City : `Nantes` ,
Region : `South` ,
PostalCode : 44000 ,
Country : `France` ,
Phone : `40.32.21.21` ,
Fax : `40.32.21.20`
}),
new CustomersDataItem(
{
ID : `FRANS` ,
Company : `Franchi S.p.A.` ,
ContactName : `Paolo Accorti` ,
ContactTitle : `Sales Representative` ,
Address : `Via Monte Bianco 34` ,
City : `Torino` ,
Region : `East` ,
PostalCode : 10100 ,
Country : `Italy` ,
Phone : `011-4988260` ,
Fax : `011-4988261`
}),
];
super (...newItems.slice(0 ));
}
}
}
ts コピー import 'igniteui-webcomponents-grids/grids/combined' ;
import { IgcGridComponent, IgcColumnComponent } from 'igniteui-webcomponents-grids/grids' ;
import { CustomersDataItem, CustomersData } from './CustomersData' ;
import { IgcPropertyEditorPropertyDescriptionButtonClickEventArgs } from 'igniteui-webcomponents-layouts' ;
import { IgcCellTemplateContext } from 'igniteui-webcomponents-grids/grids' ;
import { html, nothing } from 'lit-html' ;
import "igniteui-webcomponents-grids/grids/themes/light/bootstrap.css" ;
import 'igniteui-webcomponents/themes/light/bootstrap.css' ;
import { defineAllComponents } from 'igniteui-webcomponents' ;
defineAllComponents();
import "./index.css" ;
export class Sample {
private grid: IgcGridComponent
private column1: IgcColumnComponent
private column2: IgcColumnComponent
private _bind: () => void ;
constructor ( ) {
var grid = this .grid = document .getElementById('grid' ) as IgcGridComponent;
var column1 = this .column1 = document .getElementById('column1' ) as IgcColumnComponent;
var column2 = this .column2 = document .getElementById('column2' ) as IgcColumnComponent;
this ._bind = () => {
grid.data = this .customersData;
column1.bodyTemplate = this .webGridCompositeContactCellTemplate;
column1.inlineEditorTemplate = this .webGridCompositeContactEditCellTemplate;
column2.bodyTemplate = this .webGridCompositeAddressCellTemplate;
column2.inlineEditorTemplate = this .webGridCompositeAddressEditCellTemplate;
}
this ._bind();
}
private _customersData: CustomersData = null ;
public get customersData (): CustomersData {
if (this ._customersData == null )
{
this ._customersData = new CustomersData();
}
return this ._customersData;
}
public webGridCompositeContactCellTemplate = (ctx: IgcCellTemplateContext ) => {
var cell = ctx.cell as any ;
if (cell === undefined || cell.row === undefined || cell.row.data === undefined ) {
return html``
}
return html` <div class ="contact-container" >
<span > <strong > Name:</strong > ${cell.row.data.ContactName} </span >
<br />
<span > <strong > Title:</strong > ${cell.row.data.ContactTitle} </span >
<br />
<span > <strong > Company:</strong > ${cell.row.data.Company} </span >
<br />
</div > ` ;
}
public webGridCompositeContactEditCellTemplate = (ctx: IgcCellTemplateContext ) => {
var cell = ctx.cell as any ;
if (cell === undefined || cell.row === undefined || cell.row.data === undefined ) {
return html``
}
function keyUpHandler (event: any , ctx: IgcCellTemplateContext ) {
var cell = ctx.cell as any ;
if (cell !== undefined && cell.row !== undefined && cell.row.data !== undefined ) {
cell.row.data[event.target.id] = event.target.value;
}
}
return html`<div class ="contact-container--edit" style ="padding: 1rem" >
<igc-input id ="ContactName" label ='Name' type ="text" name ="name" value =" ${ctx.cell.row.data.ContactName} " @keyup =${(e: any ) => keyUpHandler(e, ctx)} > </igc-input >
<igc-input id ="ContactTitle" label ='Title' type ="text" name ="title" value =" ${ctx.cell.row.data.ContactTitle} " @keyup =${(e: any ) => keyUpHandler(e, ctx)} > </igc-input >
<igc-input id ="Company" label ='Company' type ="text" name ="company" value =" ${ctx.cell.row.data.Company} " @keyup =${(e: any ) => keyUpHandler(e, ctx)} > </igc-input >
</div > ` ;
}
public webGridCompositeAddressCellTemplate = (ctx: IgcCellTemplateContext ) => {
var cell = ctx.cell as any ;
if (cell === undefined || cell.row === undefined || cell.row.data === undefined ) {
return html``
}
return html`<div class ="address-container" >
<div class ="country-city" >
<span > <strong > Country:</strong > ${cell.row.data.Country} </span >
<br >
<span > <strong > City:</strong > ${cell.row.data.City} </span >
</div >
<div class ="phone-pscode" >
<span > <strong > Postal Code:</strong > ${cell.row.data.PostalCode} </span >
<br >
<span > <strong > Phone:</strong > ${cell.row.data.Phone} </span >
</div >
<br />
</div > ` ;
}
public webGridCompositeAddressEditCellTemplate = (ctx: IgcCellTemplateContext ) => {
var cell = ctx.cell as any ;
if (cell === undefined || cell.row === undefined || cell.row.data === undefined ) {
return html``
}
function keyUpHandler (event: any , ctx: IgcCellTemplateContext ) {
var cell = ctx.cell as any ;
if (cell !== undefined && cell.row !== undefined && cell.row.data !== undefined ) {
cell.row.data[event.target.id] = event.target.value;
}
}
return html`
<div class ="contact-container--edit" style ="padding: 1rem" >
<igc-input id ="Country" label ='Country' type ="text" name ="country" value =" ${ctx.cell.row.data.Country} " @keyup =${(e: any ) => keyUpHandler(e, ctx)} > </igc-input >
<igc-input id ="City" label ='City' type ="text" name ="city" value =" ${ctx.cell.row.data.City} " @keyup =${(e: any ) => keyUpHandler(e, ctx)} > </igc-input >
<igc-input id ="PostalCode" label ='PostalCode' type ="text" name ="postalcode" value =" ${ctx.cell.row.data.PostalCode} " @keyup =${(e: any ) => keyUpHandler(e, ctx)} > </igc-input >
<igc-input id ="Phone" label ='Phone' type ="text" name ="phone" value =" ${ctx.cell.row.data.Phone} " @keyup =${(e: any ) => keyUpHandler(e, ctx)} > </igc-input >
</div > ` ;
}
}
new Sample();
ts コピー <!DOCTYPE html >
<html >
<head >
<title > Sample | Ignite UI | Web Components | infragistics</title >
<meta charset ="UTF-8" />
<link rel ="shortcut icon" href ="https://static.infragistics.com/xplatform/images/browsers/wc.png" >
<link rel ="stylesheet" href ="https://fonts.googleapis.com/icon?family=Material+Icons" />
<link rel ="stylesheet" href ="https://fonts.googleapis.com/css?family=Kanit&display=swap" />
<link rel ="stylesheet" href ="https://fonts.googleapis.com/css?family=Titillium Web" />
<link rel ="stylesheet" href ="https://static.infragistics.com/xplatform/css/samples/shared.v8.css" />
<link rel ="stylesheet" href ="/src/index.css" type ="text/css" />
</head >
<body >
<div id ="root" >
<div class ="container sample ig-typography" >
<div class ="container fill" >
<igc-grid
auto-generate ="false"
primary-key ="ID"
name ="grid"
id ="grid" >
<igc-column
header ="ID"
field ="ID" >
</igc-column >
<igc-column
field ="ContactName"
header ="Contact"
editable ="true"
width ="250px"
resizable ="false"
name ="column1"
id ="column1" >
</igc-column >
<igc-column
header ="Address"
field ="Address"
editable ="true"
width ="250px"
resizable ="false"
name ="column2"
id ="column2" >
</igc-column >
<igc-column
header ="Country"
field ="Country" >
</igc-column >
<igc-column
header ="Region"
field ="Region" >
</igc-column >
<igc-column
header ="Phone"
field ="Phone" >
</igc-column >
<igc-column
header ="Fax"
field ="Fax" >
</igc-column >
</igc-grid >
</div >
</div >
</div >
<% if (false) { %><script src ="src/index.ts" > </script > <% } %>
</body >
</html >
html コピー
キーボード ナビゲーション
IgcGridComponent
のキーボード ナビゲーションは、さまざまなキーボード操作をユーザーに提供します。アクセシビリティが向上し、内部の要素 (セル、行、列ヘッダー、ツールバー、フッターなど) を直感的にナビゲートできます。
Web Components Grid スタイル設定の構成
注 :
グリッドは css グリッド レイアウト を使用しますが、これはプレフィックスなしでは IE ではサポートされていません 。その結果、適切に描画されません。
定義済みのテーマに加えて、利用可能な CSS プロパティ のいくつかを設定することで、グリッドをさらにカスタマイズできます。
<igc-grid class ="grid" > </igc-grid >
html
ヘッダーの背景とテキストの色を変更したい場合は、最初にグリッドのクラスを設定する必要があります:
.grid {
--header -background : #494949 ;
--header -text-color : #FFF ;
}
css
既知の問題と制限
制限
説明
列幅は percentage
および px
で設定されます。
列に %
と px
を組み合わせて使用することはできません。
number
型の列をフィルターする場合
フィルター入力に入力された値が number
と異なる場合、キャストが正しくないため NaN
が返されます。
グリッドの width
が列幅に依存しない
すべての列の width
でグリッド自体のスパンは決定しません。親コンテナーのディメンションまたは定義したグリッドの width
で決定されます。
親コンテナーでネストされた Grid
グリッドの width
を設定せずに定義済みのディメンションで親コンテナーに配置した場合、グリッドがコンテナーに合わせてスパンします。
グリッドの OnPush
ChangeDetectionStrategy
ChangeDetectionStrategy.OnPush
を処理し、カスタム表示されたときにグリッドに発生した変更について通知します。
列には設定可能な最小幅があります。--ig-size
CSS 変数に基づき、 "small": 56px "medium": 64px "large": 80px があります。
許容される最小幅未満に設定した場合、描画される要素に影響はありません。--ig-size
に対応する許容される最小幅で描画します。水平方向の仮想化は予期しない動作を招く場合があるためサポートしていません。
ビューに描画されていないセル高さは行の高さに影響しません。
仮想化のため、セルの高さを変更するビューにないカスタム テンプレートの列は行の高さに影響しません。関連する列がビューにスクロールされるときのみ行の高さに影響します。
API リファレンス
その他のリソース
コミュニティに参加して新しいアイデアをご提案ください。