React Grid 概要と構成
Ignite UI for React Data Table / Data Grid は、コーディングや構成をほとんど行わずにデータをすばやくバインドして表示できる表形式の React グリッド コンポーネントです。ツールボックスの React データ グリッドの機能には、フィルタリング、ソート、テンプレート、行の選択、行のグループ化、行の固定、および移動可能な列が含まれます。
React テーブルは、ライブのストリーミング データ用に最適化されており、多数の行または列で無制限のデータ セット サイズを処理できます。
React Data Grid の例
この Ignite UI for React Grid の例では、ユーザーが基本スタイルと Excel スタイルの両方のフィルタリング、ライブ データのソート、およびグリッド集計とセル テンプレートの使用を実行する方法を確認できます。デモには、1 ページあたり 10 項目を表示するように設定されたページングも含まれています。
import React from 'react' ;
import ReactDOM from 'react-dom/client' ;
import './index.css' ;
import { IgrGridModule } from "@infragistics/igniteui-react-grids" ;
import { IgrGrid, IgrPaginator, IgrColumn } from "@infragistics/igniteui-react-grids" ;
import NwindData from './NwindData.json' ;
import { IgrCellTemplateContext } from "@infragistics/igniteui-react-grids" ;
import "@infragistics/igniteui-react-grids/grids/combined" ;
import "@infragistics/igniteui-react-grids/grids/themes/light/bootstrap.css" ;
const mods : any [] = [
IgrGridModule
];
mods.forEach((m) => m.register());
export default class Sample extends React.Component <any, any> {
private grid: IgrGrid
private gridRef(r: IgrGrid) {
this .grid = r;
this .setState({});
}
private column1: IgrColumn
constructor (props: any ) {
super (props);
this .gridRef = this .gridRef.bind(this );
}
public render (): JSX .Element {
return (
<div className ="container sample ig-typography" >
<div className ="container fill" >
<IgrGrid
autoGenerate ={false}
id ="grid"
ref ={this.gridRef}
data ={this.nwindData}
primaryKey ="ProductID"
allowFiltering ={true}
filterMode ="excelStyleFilter" >
<IgrPaginator
perPage ={10} >
</IgrPaginator >
<IgrColumn
field ="ProductName"
header ="Product Name"
dataType ="string"
sortable ={true}
hasSummary ={true}
editable ={true}
resizable ={true} >
</IgrColumn >
<IgrColumn
field ="UnitPrice"
header ="Unit Price"
dataType ="number"
sortable ={true}
hasSummary ={true}
editable ={true}
resizable ={true} >
</IgrColumn >
<IgrColumn
field ="UnitsInStock"
header ="Units in Stock"
dataType ="number"
sortable ={true}
hasSummary ={true}
editable ={true}
resizable ={true} >
</IgrColumn >
<IgrColumn
field ="OrderDate"
header ="Order Date"
dataType ="date"
sortable ={true}
hasSummary ={true}
editable ={true}
resizable ={true} >
</IgrColumn >
<IgrColumn
field ="Discontinued"
header ="Discontinued"
dataType ="boolean"
sortable ={true}
hasSummary ={true}
editable ={true}
bodyTemplate ={this.webGridBooleanCellTemplate}
name ="column1" >
</IgrColumn >
<IgrColumn
field ="ReorderLevel"
header ="Reorder Level"
dataType ="number"
sortable ={true}
hasSummary ={true}
editable ={true}
filterable ={true} >
</IgrColumn >
</IgrGrid >
</div >
</div >
);
}
private _nwindData: any [] = NwindData;
public get nwindData(): any [] {
return this ._nwindData;
}
public webGridBooleanCellTemplate = (props: {dataContext: IgrCellTemplateContext}) => {
if (props.dataContext.cell.value) {
return (
<img src ="https://static.infragistics.com/xplatform/images/grid/active.png" title ="Continued" alt ="Continued" />
);
} else {
return (
<img src ="https://static.infragistics.com/xplatform/images/grid/expired.png" title ="Discontinued" alt ="Discontinued" />
);
}
}
}
const root = ReactDOM.createRoot (document.getElementById('root' ));
root.render (<Sample /> );
tsx コピー
#grid {
--ig-size: var (--ig-size-medium);
}
css コピー
このサンプルが気に入りましたか? 完全な Ignite UI for Reactツールキットにアクセスして、すばやく独自のアプリの作成を開始します。無料でダウンロードできます。
Ignite UI for React Data Grid で作業を開始
依存関係
React Data Grid を初期化するには、igniteui-react
と igniteui-react-grids
パッケージをインストールする必要があります。
npm install --save igniteui-react
npm install --save igniteui-react-grids
cmd
グリッドを使用するには、次のインポートも含める必要があります。
import "igniteui-react-grids/grids/combined.js" ;
tsx
対応するスタイルも参照する必要があります。テーマ の 1 つにライトモードのオプションまたはダークモードのオプションを選択し、プロジェクト構成に基づいてインポートできます:
import 'igniteui-react-grids/grids/themes/light/bootstrap.css'
tsx
グリッドの外観をカスタマイズする方法の詳細については、スタイル設定 セクションを参照してください。
コンポーネント モジュール
DataGrid
には以下のモジュールが必要です。
import { IgrGridModule } from "igniteui-react-grids" ;
IgrGridModule.register();
tsx
使用方法
グリッド パッケージをインポートしたので、基本的な構成と、ローカル データへのバインドから始めていきましょう。
<IgrGrid id ="grid1" data ={localData} autoGenerate ="true" > </IgrGrid >
tsx
id
プロパティは文字列値で、設定されない場合に自動生成生成されるグリッドの一意識別子です。data
はグリッドをローカル データにバインドします。
autoGenerate
プロパティは、データ ソース フィールドに基づいてグリッドの IgrColumn
コンポーネントを自動生成するようにグリッドに指示します。列の適切なデータ型の決定を試みます。それ以外の場合、開発者は列およびデータ ソース フィールドへのマッピングを明示的に定義する必要があります。
編集可能な React グリッド
グリッド編集の各操作にはバッチ操作が含まれます。つまり、API には、編集を単一のサーバー呼び出しにグループ化するオプションがあります。または、グリッドの操作を使用して、グリッドの編集を実行したり、発生した操作を更新したりできます。CRUD 操作を備えた編集グリッドとしての優れた開発者エクスペリエンスに加えて、Angular グリッドには Excel のようなキーボード ナビゲーションが含まれます。一般的なデフォルトのグリッド ナビゲーションに加えて、お客様のニーズを満たすためにナビゲーション オプションを上書きするオプションが含まれています。優れたナビゲーション スキームを備えた編集可能なグリッドは、最新の業務アプリケーションにとって重要であり、Ignite UI グリッドを使用すると簡単になります。
このトピックに続いて、セル テンプレート とセル編集テンプレート および編集について詳しく学習します。
グリッドの列構成
IgrColumn
は、グリッドの列コレクションを定義し、ソート やフィルタリング などの列ごとの機能を有効にするために使用されます。セル、ヘッダー、およびフッター テンプレートも利用できます。
列の定義
autoGenerate
プロパティを無効にし、マークアップで列コレクションを定義します。
<IgrGrid id ="grid1" autoGenerate ="false" allowFiltering ="true" data ={localData} >
<IgrColumn field ="Name" sortable ="true" > </igc-column >
<IgrColumn field ="AthleteNumber" sortable ="true" header ="Athlete number" filterable ="false" > </IgrColumn >
<IgrColumn id ="trackProgress" field ="TrackProgress" header ="Track progress" filterable ="false" > </IgrColumn >
</IgrGrid >
tsx
ヘッダー テンプレート
ヘッダー テンプレートを設定して、列ヘッダーを変更できます。以下のスニペットは、ヘッダー テキストを大文字に書式設定する方法を示しています。
function nameHeaderTemplate(ctx: IgrColumnTemplateContext) {
return (
<>
{formatUppercase(ctx.dataContext.column.field)}
</>
);
}
function formatUppercase(value: string ) {
return value.toUpperCase();
}
<IgrGrid id ="name" field ="Name" headerTemplate ={nameHeaderTemplate} > </IgrGrid >
tsx
注 :
グループ化 / 移動機能と一緒にヘッダー テンプレートを使用すると、列ヘッダー領域はドラッグ可能になりヘッダー テンプレートのカスタム要素部分にドラッグ不可としてマークするまでアクセスできません。以下の例をご覧ください。
function productNameHeaderTemplate(ctx: IgrColumnTemplateContext) {
return (
<>
<div class ="text" > ${ctx.dataContext.column.field}</div >
<IgrIcon onClick ={() => toggleSummary(ctx.dataContext.column)} name="functions" draggable="false" ></IgrIcon >
</>
);
}
<IgrColumn id ="productName" field ="ProductName" header ="Product Name" groupable ="true" hasSummary ="true" headerTemplate ={productNameHeaderTemplate} > </IgrColumn >
tsx
Draggable
属性を false に設定して追加しています。
セル テンプレート
セル テンプレートを設定すると、列内のすべてのセルが変更されます。テンプレートで提供されるコンテキスト オブジェクトは暗示的に提供されたセル値およびセル オブジェクトです。セルのテキストを書式設定できるテンプレートを定義するために使用できます。たとえば、タイトル ケースなどです。
function formatTitleCase(value: string ) {
return value.toUpperCase();
}
function nameCellTemplate(ctx: IgrCellTemplateContext) {
return (
<>
{formatTitleCase(ctx.dataContext.implicit)}
</>
);
}
<IgrColumn id ="name" field ="Name" bodyTemplate ={nameCellTemplate} > </IgrColumn >
tsx
上記のスニペットで暗示的に提供されたセル値への参照を取得します。データを表示し、セルの値にカスタム スタイル設定およびパイプ変換を適用する場合に使用します。ただし、Cell
インスタンスを以下のように使用するとより効果的です。
function nameCellTemplate(ctx: IgrCellTemplateContext) {
return (
<>
<span tabindex ="0" keydown ={() => deleteRow(ctx.dataContext.cell.id.rowIndex)}>
{formatTitleCase(ctx.dataContext.cell.value)}
</span >
</>
);
}
function subscriptionCellTemplate(ctx: IgrCellTemplateContext) {
if (ctx.dataContext.cell.value) {
return (
<>
<input type ="checkbox" checked />
</>
);
} else {
return (
<>
<input type ="checkbox" />
</>
);
}
}
function deleteRow(rowIndex: number ) {
grid.deleteRow(rowIndex);
}
function formatTitleCase(value: string ) {
return value.toUpperCase();
}
<IgrGrid id ="grid" autoGenerate ="false" data ={data} >
<IgrColumn id ="name" field ="Name" dataType ="string" bodyTemplate ={nameCellTemplate} > </IgrColumn >
<IgrColumn id ="subscription" field ="Subscription" dataType ="boolean" bodyTemplate ={subscriptionCellTemplate} > </IgrColumn >
</IgrGrid >
tsx
注 :
グリッドは、数値、文字列、日付、およびブール列タイプのデフォルトの処理を公開します。例えば、ブール列タイプの場合に列はデフォルトで true/false の代わりに check
または close
アイコンを表示します。
適切に実装されると、セル編集テンプレートは、セルの EditValue
がグリッド編集イベント サイクル を正しく渡します。
セル編集テンプレート
列は、セルが編集モードにある場合に使用されるテンプレートを使用します。その他の列テンプレートと同じように、提供されるコンテキスト オブジェクトはセル値およびセル オブジェクトです。編集モード テンプレートをユーザー アクセス可能にするには、列の editable
プロパティを true に設定します。
function priceCellTemplate(ctx: IgrCellTemplateContext) {
return (
<>
<label >
Enter the new price tag
</label >
<input name ="price" type ="number" value ={ctx.dataContext.cell.value}
change ={() => this .updateValue(ctx.dataContext.cell.value)}/>
</>
);
}
function updateValue(value: number ) {
}
<IgrColumn id ="price" field ="Price" dataType ="number" editable ="true" inlineEditorTemplate ={priceCellTemplate} > </IgrColumn >
tsx
テンプレートで使用可能なプロパティの詳細については、Cell
の API を参照してください。
列テンプレート API
各列テンプレートが IgrColumn
オブジェクトでコードによって変更可能です。以下のコード例で、ユーザー データの 2 つのテンプレートを宣言しました。TypeScript コードでテンプレートへの参照を取得し、条件に基づいてアプリケーションで列の適切なテンプレートを描画します。
<IgrGrid >
{}
</IgrGrid >
tsx
function normalViewTemplate(ctx: IgrCellTemplateContext) {
return (
<>
<div class ="user-details" > { ctx.dataContext.cell.value }</div >
<UserDetailsComponent > </UserDetailsComponent >
</>
);
}
function smallViewTemplate(ctx: IgrCellTemplateContext) {
return (
<>
<div class ="user-details-small" > { ctx.dataContext.cell.value }</div >
</>
);
}
const column = grid.getColumnByName("User" );
column.bodyTemplate = smallViewTemplate;
tsx
列プロパティもグリッドで列が初期化されるときに発生される ColumnInit
イベントのコードで設定できます。
function initColumns(grid: IgrGridBaseDirective, args: IgrColumnComponentEventArgs) {
const column : IgrColumn = args.detail;
if (column.field === 'ProductName' ) {
column.sortable = true ;
column.editable = true ;
}
}
tsx
上記のコードは ProductName 列のソートや編集機能を有効にし、対応する機能の UI (編集の入力など) をインスタンス化します。
カスタム表示形式
書式設定のためのオプションのパラメーターがあります:
Format
- 表示される日付 / 時間部分を決定します。デフォルト 'mediumDate'
です ('MMM d, y' )。
Timezone
- 日付のタイムゾーン オフセット。デフォルトでは、エンドユーザーのローカル システムのタイムゾーンを使用します。
DigitsInfo
- 10 進表現オブジェクト。デフォルトの設定は 1.0-3 です。
これらのパラメーターによって表示形式をカスタマイズできるようにするには、pipeArgs
入力公開します。pipeArgs
が設定されている場合、列はそのデータ型の対応するプロパティのみに遵守します。例:
const columnPipeArgs = {
format: "longDate" ,
timezone: "UTC" ,
digitsInfo: "1.2-2"
};
<IgrColumn field ="OrderDate" dataType ="date" pipeArgs ={columnPipeArgs} > </IgrColumn >
tsx
OrderDate
列は Format
および Timezone
プロパティのみに遵守しますが、UnitPrice
は DigitsInfo
のみに遵守します。
すべての利用可能な列データ型は、公式の列タイプ トピック にあります。
グリッド データの構造
IgrGrid
はフラット データ とネストされた 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
プロパティに割り当てます。
<IgrGrid ref ={gridRef} > </IgrGrid >
tsx
function fetchData(url: string ): void {
fetch(url)
.then(response => response.json())
.then(data => onDataLoaded(data));
}
function onDataLoaded(jsonData: any []) {
gridRef.current.data = jsonData;
}
tsx
注 : リモート データにバインドする場合、グリッドの autoGenerate
プロパティは使用しないことをお勧めします。データを検証して適切な列を生成するためにデータが利用可能である必要があります。リモート サービスの応答が完了するまでデータが利用できないため、グリッドはエラーを発生します。リモート サービスへバインド時に autoGenerate
を使用する機能は今後追加予定です。
複雑なデータ バインディング
IgrGrid
は、データ レコード内のプロパティのパスを介した複合オブジェクト (1 レベルより深いネストを含む) へのバインドをサポートします。
次のデータ モデルを見てください。
interface AminoAcid {
name : string ;
abbreviation: {
short : string ;
long: string ;
}
weight : {
molecular : number ;
residue: number ;
},
formula : {
molecular : string ;
residue: string ;
}
}
typescript
たとえば、グリッド内の特定のアミノ酸の重みを表示するには、次のスニペットで十分です。
<IgrColumn field ="weight.molecular" > </IgrColumn >
<IgrColumn field ="weight.residue" > </IgrColumn >
tsx
IgrGrid
で複雑なデータをバインドまたは複合データ (複数の列から) を可視化する別の方法は、列にカスタム ボディ テンプレートを使用することです。通常、以下のことができます。
ネストされたデータを含むセルの value
を使用します。
テンプレート内の cell
オブジェクトを使用し、そこから ctx.dataContext.cell.id.rowIndex
または ctx.dataContext.cell.id.rowID
にアクセスして、グリッドの API 経由で行を取得します。そこから任意の値を取得し、テンプレート内で補間します。
function getName(rowIndex: number ) {
return grid.getRowByIndex(rowIndex).data["Name" ];
}
function getWeight(rowIndex: number ) {
return grid.getRowByIndex(rowIndex).data["weight" ]["molecular" ];
}
function abbreviationLongCellTemplate(ctx: IgrCellTemplateContext) {
return (
<>
<div >
<div >
{ ctx.dataContext.cell.value }
{getName(ctx.dataContext.cell.id.rowIndex)}
{getWeight(ctx.dataContext.cell.id.rowIndex)}
</div >
</div >
</>
)
}
<IgrColumn id ="abbreviationLong" field ="abbreviation.long" bodyTemplate ={abbreviationLongCellTemplate} > </IgrColumn >
tsx
本文テンプレートを使用して複雑なデータを表示する方法の例を次に示します。以下は使用するデータです。
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
ネスト データをレンダリングする列のカスタム テンプレート。
function addressCellTemplate(ctx: IgrCellTemplateContext) {
return (
<>
<IgrExpansionPanel >
<div slot ="title" style ={{font-size: '1.1em '; font-weight: 'bold '; margin-top: '1rem '; margin-bottom: '0.25rem '}}>
{ctx.dataContext.cell.value[0 ].Name}
</div >
<div className ="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.dataContext.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.dataContext.cell.value[0].Age}" style ={{text-overflow: 'ellipsis '}} />
</div >
</div >
</IgrExpansionPanel >
</>
)
}
<IgrColumn field ="Employees" header ="Employees" width ="40%" bodyTemplate ={addressCellTemplate} > </IgrColumn >
tsx
以下は、この設定の結果です。
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 React from 'react' ;
import ReactDOM from 'react-dom/client' ;
import './index.css' ;
import { IgrGridModule } from "@infragistics/igniteui-react-grids" ;
import { IgrInputModule } from "@infragistics/igniteui-react" ;
import { IgrGrid, IgrColumn } from "@infragistics/igniteui-react-grids" ;
import { EmployeesNestedDataItem, EmployeesNestedDataItem_EmployeesItem, EmployeesNestedData } from './EmployeesNestedData' ;
import { IgrCellTemplateContext } from "@infragistics/igniteui-react-grids" ;
import { IgrExpansionPanel, IgrInput } from "@infragistics/igniteui-react" ;
import "@infragistics/igniteui-react-grids/grids/combined" ;
import "@infragistics/igniteui-react-grids/grids/themes/light/bootstrap.css" ;
const mods : any [] = [
IgrGridModule,
IgrInputModule
];
mods.forEach((m) => m.register());
export default class Sample extends React.Component <any, any> {
private grid: IgrGrid
private gridRef(r: IgrGrid) {
this .grid = r;
this .setState({});
}
private column1: IgrColumn
constructor (props: any ) {
super (props);
this .gridRef = this .gridRef.bind(this );
}
public render (): JSX .Element {
return (
<div className ="container sample ig-typography" >
<div className ="container fill" >
<IgrGrid
autoGenerate ={false}
data ={this.employeesNestedData}
ref ={this.gridRef}
id ="grid" >
<IgrColumn
header ="Name"
field ="Name"
width ="15%" >
</IgrColumn >
<IgrColumn
field ="Title"
header ="Title"
width ="15%" >
</IgrColumn >
<IgrColumn
field ="Salary"
header ="Salary"
width ="10%" >
</IgrColumn >
<IgrColumn
field ="Employees"
header ="Employees"
bodyTemplate ={this.webGridNestedDataCellTemplate}
width ="20%"
name ="column1" >
</IgrColumn >
<IgrColumn
field ="City"
header ="City"
width ="15%" >
</IgrColumn >
<IgrColumn
field ="Country"
header ="Country"
width ="15%" >
</IgrColumn >
<IgrColumn
field ="Age"
header ="Age"
width ="10%" >
</IgrColumn >
<IgrColumn
field ="HireDate"
header ="Hire Date"
dataType ="date" >
</IgrColumn >
</IgrGrid >
</div >
</div >
);
}
private _employeesNestedData: EmployeesNestedData = null ;
public get employeesNestedData(): EmployeesNestedData {
if (this ._employeesNestedData == null )
{
this ._employeesNestedData = new EmployeesNestedData();
}
return this ._employeesNestedData;
}
public webGridNestedDataCellTemplate = (props: {dataContext: IgrCellTemplateContext}) => {
if (props.dataContext.cell.value != null ) {
if (props.dataContext.cell.value.length === 0 ) return <> </> ;
const value = props.dataContext.cell.value[0 ];
var grid = this .grid;
return (
<>
<IgrExpansionPanel >
<div slot ="title" style ={{fontSize: "1.1em ", fontWeight: "bold ", marginTop: "1rem ", marginBottom: "0.25rem "}}>
{value.Name}
</div >
<div className ="description" >
<IgrInput type ="text" label ="Title" name ="title" value ={value.Title} change ={(s:any, e: any ) => {
props.dataContext.cell.value[0 ][s.label] = e.detail;
grid.markForCheck();
}} style={{textOverflow: "ellipsis" }} />
<IgrInput type ="number" label ="Age" name ="title" value ={value.Age} inputOcurred ={(s:any, e: any ) => {
props.dataContext.cell.value[0 ][s.label] = e.detail;
grid.markForCheck();
}} style={{textOverflow: "ellipsis" }} />
</div >
</IgrExpansionPanel >
</> );
}
return <> </> ;
};
}
const root = ReactDOM.createRoot (document.getElementById('root' ));
root.render (<Sample /> );
tsx コピー
フラット データの操作の概要
フラット データ バインディングのアプローチは既に説明したものと似ていますが、セル値 の代わりに、IgrGridRow
の data
プロパティを使用します。
React グリッドはデータ レコードをレンダリング 、操作 、保存する ためのコンポーネントのため、すべてのデータ レコード へアクセスすることで、それを処理する方法をカスタマイズすることができます。それには、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
カスタム テンプレート:
function getCountry(rowIndex: number ) {
return grid.getRowByIndex(rowIndex).data["Country" ];
}
function getCity(rowIndex: number ) {
return grid.getRowByIndex(rowIndex).data["City" ];
}
function getPostalCode(rowIndex: number ) {
return grid.getRowByIndex(rowIndex).data["PostalCode" ];
}
function addressCellTemplate(ctx: IgrCellTemplateContext) {
return (
<>
<div className ="address-container" >
<span > <strong > Country:</strong > {getCountry(ctx.dataContext.cell.id.rowIndex)}</span >
<br />
<span > <strong > City:</strong > {getCity(ctx.dataContext.cell.id.rowIndex)}</span >
<br />
<span > <strong > Postal Code:</strong > {getPostalCode(ctx.dataContext.cell.id.rowIndex)}</span >
</div >
</>
);
}
<IgrColumn field ="Address" header ="Address" width ="25%" editable ="true" bodyTemplate ={addressCellTemplate} > </IgrColumn >
tsx
上記で定義したテンプレートでは編集操作ができないため、エディター テンプレートが必要であることに注意してください。
function webGridCompositeAddressEditCellTemplate(ctx: IgrCellTemplateContext) {
var cell = ctx.dataContext.cell as any ;
if (cell === undefined || cell.row === undefined || cell.row.data === undefined ) {
return (<> </> )
}
function keyUpHandler(event: any , ctx: IgrCellTemplateContext) {
var cell = ctx.dataContext.cell as any ;
if (cell !== undefined && cell.row !== undefined && cell.row.data !== undefined ) {
cell.row.data[event.target.id] = event.target.value;
}
}
return (
<>
<div className ="address-container--edit" style ={{display: 'inline-grid '}}>
<div >
<span > <strong > Country:</strong > </span >
<input id ='Country' keyup ={(e: any ) => keyUpHandler(e, ctx)} value={cell.dataContext.row.data.Country}></input >
<br >
<span > <strong > City:</strong > </span >
<input id ='City' keyup ={(e: any ) => keyUpHandler(e, ctx)} value={cell.dataContext.row.data.City}></input >
</div >
<div >
<span > <strong > Postal Code:</strong > </span >
<input id ='PostalCode' keyup ={(e: any ) => keyUpHandler(e, ctx)} value={cell.dataContext.row.data.PostalCode}></input >
<br >
<span > <strong > Selected:</strong > </span >
<input id ='Phone' keyup ={(e: any ) => keyUpHandler(e, ctx)} value={cell.dataContext.row.data.Phone}></input >
</div >
<br >
</div >
</>
);
}
<IgrColumn field ="Address" dataType ="number" width ="25%" editable ="true" inlineEditorTemplate ={webGridCompositeAddressEditCellTemplate} > </IgrColumn >
tsx
フラット データの操作の例
前のセクションのコード スニペットを使用すると、次の IgrGrid
の例になります。
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 React from 'react' ;
import ReactDOM from 'react-dom/client' ;
import './index.css' ;
import { IgrGridModule } from "@infragistics/igniteui-react-grids" ;
import { IgrInputModule } from "@infragistics/igniteui-react" ;
import { IgrGrid, IgrColumn } from "@infragistics/igniteui-react-grids" ;
import { CustomersDataItem, CustomersData } from './CustomersData' ;
import { IgrCellTemplateContext } from "@infragistics/igniteui-react-grids" ;
import { IgrInput } from "@infragistics/igniteui-react" ;
import "@infragistics/igniteui-react-grids/grids/combined" ;
import "@infragistics/igniteui-react-grids/grids/themes/light/bootstrap.css" ;
const mods : any [] = [
IgrGridModule,
IgrInputModule
];
mods.forEach((m) => m.register());
export default class Sample extends React.Component <any, any> {
private grid: IgrGrid
private gridRef(r: IgrGrid) {
this .grid = r;
this .setState({});
}
private column1: IgrColumn
private column2: IgrColumn
constructor (props: any ) {
super (props);
this .gridRef = this .gridRef.bind(this );
}
public render (): JSX .Element {
return (
<div className ="container sample ig-typography" >
<div className ="container fill" >
<IgrGrid
autoGenerate ={false}
data ={this.customersData}
primaryKey ="ID"
ref ={this.gridRef} >
<IgrColumn
header ="ID"
field ="ID" >
</IgrColumn >
<IgrColumn
field ="ContactName"
header ="Contact"
editable ={true}
bodyTemplate ={this.webGridCompositeContactCellTemplate}
inlineEditorTemplate ={this.webGridCompositeContactEditCellTemplate}
width ="250px"
resizable ={false}
name ="column1" >
</IgrColumn >
<IgrColumn
header ="Address"
field ="Address"
editable ={true}
bodyTemplate ={this.webGridCompositeAddressCellTemplate}
inlineEditorTemplate ={this.webGridCompositeAddressEditCellTemplate}
width ="250px"
resizable ={false}
name ="column2" >
</IgrColumn >
<IgrColumn
header ="Country"
field ="Country" >
</IgrColumn >
<IgrColumn
header ="Region"
field ="Region" >
</IgrColumn >
<IgrColumn
header ="Phone"
field ="Phone" >
</IgrColumn >
<IgrColumn
header ="Fax"
field ="Fax" >
</IgrColumn >
</IgrGrid >
</div >
</div >
);
}
private _customersData: CustomersData = null ;
public get customersData(): CustomersData {
if (this ._customersData == null )
{
this ._customersData = new CustomersData();
}
return this ._customersData;
}
public webGridCompositeContactCellTemplate = (props: {dataContext: IgrCellTemplateContext}) => {
var cell = props.dataContext.cell as any ;
if (cell === undefined || cell.row === undefined || cell.row.data === undefined ) {
return <> </> ;
}
return (
<>
<div className ="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 = (props: {dataContext: IgrCellTemplateContext}) => {
var cell = props.dataContext.cell as any ;
var grid = this .grid;
if (cell === undefined || cell.row === undefined || cell.row.data === undefined ) {
return <> </>
}
return (
<>
<div className ="contact-container--edit" style ={{padding: "1rem "}}>
<IgrInput label ='Name' inputOcurred ={(input: any , e: any ) =>
{
cell.row.data.ContactName = e.detail;
grid.forceUpdate();
}
} value={cell.row.data.ContactName}></IgrInput >
<IgrInput label ='Title' inputOcurred ={(input: any , e: any ) =>
{
cell.row.data.ContactTitle = e.detail;
grid.forceUpdate();
}
} value={cell.row.data.ContactTitle}></IgrInput >
<IgrInput label ='Company' inputOcurred ={(input: any , e: any ) =>
{
cell.row.data.Company = e.detail;
grid.forceUpdate();
}
} value={cell.row.data.Company}></IgrInput >
</div >
</>
);
}
public webGridCompositeAddressCellTemplate = (props: {dataContext: IgrCellTemplateContext}) => {
var cell = props.dataContext.cell as any ;
if (cell === undefined || cell.row === undefined || cell.row.data === undefined ) {
return <> </> ;
}
return (
<>
<div className ="address-container" >
<div className ="country-city" >
<span > <strong > Country:</strong > {cell.row.data.Country}</span >
<br />
<span > <strong > City:</strong > {cell.row.data.City}</span >
</div >
<div className ="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 = (props: {dataContext: IgrCellTemplateContext}) => {
var cell = props.dataContext.cell as any ;
var grid = this .grid;
if (cell === undefined || cell.row === undefined || cell.row.data === undefined ) {
return <> </> ;
}
return (
<>
<div className ="contact-container--edit" style ={{padding: "1rem "}}>
<IgrInput label ='Country' inputOcurred ={(input: any , e: any ) =>
{
cell.row.data.Country = e.detail;
grid.forceUpdate();
}
} value={cell.row.data.Country}></IgrInput >
<IgrInput label ='City' inputOcurred ={(input: any , e: any ) =>
{
cell.row.data.City = e.detail;
grid.forceUpdate();
}
} value={cell.row.data.City}></IgrInput >
<IgrInput label ='Postal Code' inputOcurred ={(input: any , e: any ) =>
{
cell.row.data.PostalCode = e.detail;
grid.forceUpdate();
}
} value={cell.row.data.PostalCode}></IgrInput >
<IgrInput label ='Phone' inputOcurred ={(input: any , e: any ) =>
{
cell.row.data.Phone = e.detail;
grid.forceUpdate();
}
} value={cell.row.data.Phone}></IgrInput >
</div >
</>
);
}
}
const root = ReactDOM.createRoot (document.getElementById('root' ));
root.render (<Sample /> );
tsx コピー
キーボード ナビゲーション
IgrGrid
のキーボード ナビゲーションは、さまざまなキーボード操作をユーザーに提供します。アクセシビリティが向上し、内部の要素 (セル、行、列ヘッダー、ツールバー、フッターなど) を直感的にナビゲートできます。
React Grid スタイル設定の構成
注 :
グリッドは css グリッド レイアウト を使用しますが、これはプレフィックスなしでは IE ではサポートされていません 。その結果、適切に描画されません。
定義済みのテーマに加えて、利用可能な CSS プロパティ のいくつかを設定することで、グリッドをさらにカスタマイズできます。
<IgrGrid className ="grid" > </IgrGrid >
tsx
ヘッダーの背景とテキストの色を変更したい場合は、最初にグリッドのクラスを設定する必要があります:
.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 リファレンス
その他のリソース
コミュニティに参加して新しいアイデアをご提案ください。