React Tree Grid 編集
React Tree Grid の Ignite UI for React セル編集機能を使用すると、レコードの作成、更新、削除などのデータ操作を簡単に実行できます。IgrTreeGrid
は、これらの操作をカスタマイズできる強力なパブリック API を提供します。データ操作のフェーズは次のとおりです。
設定
有効にする編集モードを指定するために、IgrTreeGrid
は editable
および rowEditable
ブール値プロパティを公開します。
以下のオプションは、プロパティ editable
で指定できます。
false - 対応する列の編集が無効になります 。これがデフォルト値です。
true - 対応する列の編集が有効になります。
列が編集できない場合でも、IgrTreeGrid
によって公開されるパブリック API を介して値を変更できます。
以下のオプションは、プロパティ rowEditable
で指定できます。
false - 対応するグリッドの行編集は無効になります。これがデフォルト値です。
true - 対応するグリッドで行編集が有効になります。
IgrTreeGrid
で rowEditable
プロパティを true に設定し、editable
プロパティがどの列にも明示的に定義されていない場合、編集は主キー 以外のすべての列で有効になります。
セルおよび一括編集 - このシナリオでは、各セルの変更は個別に保持され、元に戻す/やり直し操作はセル レベルで使用できます。
行および一括編集 - このシナリオでは、変更は行レベルで保持されるため、元に戻す/やり直し操作は変更された各セルではなく、各行のセル全体に対して動作します。
テンプレートの編集
データ型固有の編集テンプレート を使用する場合、列 dataType
プロパティを指定する必要があります。次に各型のデフォルト テンプレートについて説明します。
string
データ型の場合、デフォルトのテンプレートは IgrInput
を使用します。
number
データ型のデフォルト テンプレートは IgrInput
type="number" を使用します。数値に解析できない値にセルを更新した場合、変更は無視されてセルの値が 0 に設定されます。
date
データ型ではデフォルトのテンプレートは IgrDatePicker
を使用します。
dateTime
データ型ではデフォルトのテンプレートは DateTimeEditor
を使用します。このエディターは、DateTime オブジェクトの入力要素部分のマスクを提供します。
time
データ型ではデフォルトのテンプレートは TimePicker
を使用します。
boolean
データ型ではデフォルトのテンプレートは IgrCheckbox
を使用します。
currency
データ型の場合、デフォルトのテンプレートは、アプリケーションまたはグリッドのロケール設定に基づいたプレフィックス/サフィックス構成の InputGroup
を使用します。
percent
パーセントデータ型の場合、デフォルトのテンプレートは、編集された値のプレビューをパーセントで表示するサフィックス要素を持つ InputGroup
を使用します。
すべての利用可能な列データ型は、公式の列タイプトピック にあります。
イベントの引数とシーケンス
グリッドは、編集エクスペリエンスをより詳細に制御できる広範なイベントを公開します。これらのイベントは、行の編集 およびセルの編集 のライフサイクル - 編集の開始、コミット、またはキャンセル時に発生します。
イベントのキャンセル
RowEditEnter
- Row
も Cell
も編集モードに入りません。
CellEditEnter
- セル編集に入ることを防止します。rowEditable
が有効な場合、セルの編集は禁止されたままですが、行の編集がトリガーされます。
CellEdit
- Cell
/Row
の編集を許可し、[完了] ボタンまたは [Enter] を押しても値または行のトランザクションはコミットされません。[キャンセル] ボタンをクリックするまで、セル編集と行編集は閉じません。
RowEdit
- 行全体ではなくセルのコミットは可能です。行は編集モードのままになり、行トランザクションは開いていると見なされます。[完了] を押しても、行をコミットまたは閉じません。[キャンセル] ボタンは、変更をコミットせずに編集プロセスとトランザクションを閉じます。
以下のサンプルは、実行中の編集実行シーケンスを示しています。
export class EmployeesFlatDataItem {
public constructor (init: Partial<EmployeesFlatDataItem> ) {
Object .assign(this , init);
}
public Age: number ;
public HireDate: string ;
public ID: number ;
public Name: string ;
public Phone: string ;
public OnPTO: boolean ;
public ParentID: number ;
public Title: string ;
}
export class EmployeesFlatData extends Array <EmployeesFlatDataItem > {
public constructor (items: Array <EmployeesFlatDataItem> | number = -1 ) {
if (Array .isArray(items)) {
super (...items);
} else {
const newItems = [
new EmployeesFlatDataItem(
{
Age : 55 ,
HireDate : `2008-03-20` ,
ID : 1 ,
Name : `Johnathan Winchester` ,
Phone : `0251-031259` ,
OnPTO : false ,
ParentID : -1 ,
Title : `Development Manager`
}),
new EmployeesFlatDataItem(
{
Age : 42 ,
HireDate : `2014-01-22` ,
ID : 4 ,
Name : `Ana Sanders` ,
Phone : `(21) 555-0091` ,
OnPTO : true ,
ParentID : -1 ,
Title : `CEO`
}),
new EmployeesFlatDataItem(
{
Age : 49 ,
HireDate : `2014-01-22` ,
ID : 18 ,
Name : `Victoria Lincoln` ,
Phone : `(071) 23 67 22 20` ,
OnPTO : true ,
ParentID : -1 ,
Title : `Accounting Manager`
}),
new EmployeesFlatDataItem(
{
Age : 61 ,
HireDate : `2010-01-01` ,
ID : 10 ,
Name : `Yang Wang` ,
Phone : `(21) 555-0091` ,
OnPTO : false ,
ParentID : -1 ,
Title : `Localization Manager`
}),
new EmployeesFlatDataItem(
{
Age : 43 ,
HireDate : `2011-06-03` ,
ID : 3 ,
Name : `Michael Burke` ,
Phone : `0452-076545` ,
OnPTO : true ,
ParentID : 1 ,
Title : `Senior Software Developer`
}),
new EmployeesFlatDataItem(
{
Age : 29 ,
HireDate : `2009-06-19` ,
ID : 2 ,
Name : `Thomas Anderson` ,
Phone : `(14) 555-8122` ,
OnPTO : false ,
ParentID : 1 ,
Title : `Senior Software Developer`
}),
new EmployeesFlatDataItem(
{
Age : 31 ,
HireDate : `2014-08-18` ,
ID : 11 ,
Name : `Monica Reyes` ,
Phone : `7675-3425` ,
OnPTO : false ,
ParentID : 1 ,
Title : `Software Development Team Lead`
}),
new EmployeesFlatDataItem(
{
Age : 35 ,
HireDate : `2015-09-17` ,
ID : 6 ,
Name : `Roland Mendel` ,
Phone : `(505) 555-5939` ,
OnPTO : false ,
ParentID : 11 ,
Title : `Senior Software Developer`
}),
new EmployeesFlatDataItem(
{
Age : 44 ,
HireDate : `2009-10-11` ,
ID : 12 ,
Name : `Sven Cooper` ,
Phone : `0695-34 67 21` ,
OnPTO : true ,
ParentID : 11 ,
Title : `Senior Software Developer`
}),
new EmployeesFlatDataItem(
{
Age : 44 ,
HireDate : `2014-04-04` ,
ID : 14 ,
Name : `Laurence Johnson` ,
Phone : `981-443655` ,
OnPTO : false ,
ParentID : 4 ,
Title : `Director`
}),
new EmployeesFlatDataItem(
{
Age : 25 ,
HireDate : `2017-11-09` ,
ID : 5 ,
Name : `Elizabeth Richards` ,
Phone : `(2) 283-2951` ,
OnPTO : true ,
ParentID : 4 ,
Title : `Vice President`
}),
new EmployeesFlatDataItem(
{
Age : 39 ,
HireDate : `2010-03-22` ,
ID : 13 ,
Name : `Trevor Ashworth` ,
Phone : `981-443655` ,
OnPTO : true ,
ParentID : 5 ,
Title : `Director`
}),
new EmployeesFlatDataItem(
{
Age : 44 ,
HireDate : `2014-04-04` ,
ID : 17 ,
Name : `Antonio Moreno` ,
Phone : `(505) 555-5939` ,
OnPTO : false ,
ParentID : 18 ,
Title : `Senior Accountant`
}),
new EmployeesFlatDataItem(
{
Age : 50 ,
HireDate : `2007-11-18` ,
ID : 7 ,
Name : `Pedro Rodriguez` ,
Phone : `035-640230` ,
OnPTO : false ,
ParentID : 10 ,
Title : `Senior Localization Developer`
}),
new EmployeesFlatDataItem(
{
Age : 27 ,
HireDate : `2016-02-19` ,
ID : 8 ,
Name : `Casey Harper` ,
Phone : `0342-023176` ,
OnPTO : true ,
ParentID : 10 ,
Title : `Senior Localization`
}),
new EmployeesFlatDataItem(
{
Age : 25 ,
HireDate : `2017-11-09` ,
ID : 15 ,
Name : `Patricia Simpson` ,
Phone : `069-0245984` ,
OnPTO : false ,
ParentID : 7 ,
Title : `Localization Intern`
}),
new EmployeesFlatDataItem(
{
Age : 39 ,
HireDate : `2010-03-22` ,
ID : 9 ,
Name : `Francisco Chang` ,
Phone : `(91) 745 6200` ,
OnPTO : false ,
ParentID : 7 ,
Title : `Localization Intern`
}),
new EmployeesFlatDataItem(
{
Age : 25 ,
HireDate : `2018-03-18` ,
ID : 16 ,
Name : `Peter Lewis` ,
Phone : `069-0245984` ,
OnPTO : true ,
ParentID : 7 ,
Title : `Localization Intern`
}),
];
super (...newItems.slice(0 ));
}
}
}
ts コピー import React from 'react' ;
import ReactDOM from 'react-dom/client' ;
import './index.css' ;
import { IgrTreeGridModule } from "@infragistics/igniteui-react-grids" ;
import { IgrTreeGrid, IgrColumn } from "@infragistics/igniteui-react-grids" ;
import { EmployeesFlatDataItem, EmployeesFlatData } from './EmployeesFlatData' ;
import { IgrGridEditEventArgs, IgrGrid, IgrGridEditDoneEventArgs } 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 [] = [
IgrTreeGridModule
];
mods.forEach((m) => m.register());
export default class Sample extends React.Component <any, any> {
private grid: IgrTreeGrid
private gridRef(r: IgrTreeGrid) {
this .grid = r;
this .setState({});
}
constructor (props: any ) {
super (props);
this .gridRef = this .gridRef.bind(this );
this .webTreeGridRendered = this .webTreeGridRendered.bind(this );
this .webGridRowEditEnter = this .webGridRowEditEnter.bind(this );
this .webGridRowEdit = this .webGridRowEdit.bind(this );
this .webGridRowEditDone = this .webGridRowEditDone.bind(this );
this .webGridRowEditExit = this .webGridRowEditExit.bind(this );
this .webGridCellEditEnter = this .webGridCellEditEnter.bind(this );
this .webGridCellEdit = this .webGridCellEdit.bind(this );
this .webGridCellEditDone = this .webGridCellEditDone.bind(this );
this .webGridCellEditExit = this .webGridCellEditExit.bind(this );
}
public render (): JSX .Element {
return (
<div className ="container sample ig-typography" >
<div className ="container fill" >
<IgrTreeGrid
autoGenerate ={false}
data ={this.employeesFlatData}
ref ={this.gridRef}
id ="grid"
rowEditable ={true}
primaryKey ="ID"
foreignKey ="ParentID"
rendered ={this.webTreeGridRendered}
rowEditEnter ={this.webGridRowEditEnter}
rowEdit ={this.webGridRowEdit}
rowEditDone ={this.webGridRowEditDone}
rowEditExit ={this.webGridRowEditExit}
cellEditEnter ={this.webGridCellEditEnter}
cellEdit ={this.webGridCellEdit}
cellEditDone ={this.webGridCellEditDone}
cellEditExit ={this.webGridCellEditExit} >
<IgrColumn
field ="Name"
dataType ="string"
editable ={true} >
</IgrColumn >
<IgrColumn
field ="Title"
header ="Job Title"
dataType ="string"
editable ={true} >
</IgrColumn >
<IgrColumn
field ="Age"
dataType ="number"
editable ={true} >
</IgrColumn >
</IgrTreeGrid >
</div >
</div >
);
}
private _employeesFlatData: EmployeesFlatData = null ;
public get employeesFlatData(): EmployeesFlatData {
if (this ._employeesFlatData == null )
{
this ._employeesFlatData = new EmployeesFlatData();
}
return this ._employeesFlatData;
}
public webTreeGridRendered(args:any ): void {
const treeGrid = document.getElementById("grid" );
treeGrid.parentElement.className = "fill" ;
treeGrid.parentElement.style.display = "flex" ;
treeGrid.parentElement.style.height = "100vh" ;
const container = document.createElement("div" );
container.id = "container" ;
container.style.height = "100vh" ;
container.style.width = "100%" ;
container.style.overflow = "auto" ;
treeGrid.parentElement.appendChild(container);
const title = document.createElement("span" );
title.textContent = "Events execution sequence:" ;
container.appendChild(title);
}
public webGridRowEditEnter(sender: IgrTreeGrid, args: IgrGridEditEventArgs): void {
let container = document.getElementById("container" );
const message = document.createElement("p" );
message.textContent = `=> 'rowEditEnter' with 'RowID' :` + args.detail.rowID;
container.appendChild(message);
}
public webGridRowEdit(sender: IgrTreeGrid, args: IgrGridEditEventArgs): void {
let container = document.getElementById("container" );
const message = document.createElement("p" );
message.textContent = `=> 'rowEdit' `;
container.appendChild(message);
}
public webGridRowEditDone(sender: IgrTreeGrid, args: IgrGridEditDoneEventArgs): void {
let container = document.getElementById("container" );
const message = document.createElement("p" );
message.textContent = `=> 'rowEditDone' `;
container.appendChild(message);
}
public webGridRowEditExit(sender: IgrTreeGrid, args: IgrGridEditDoneEventArgs): void {
let container = document.getElementById("container" );
const message = document.createElement("p" );
message.textContent = `=> 'rowEditExit' < < End of cycle >>`;
container.appendChild(message);
}
public webGridCellEditEnter(sender: IgrTreeGrid, args: IgrGridEditEventArgs): void {
let container = document.getElementById("container");
const message = document.createElement("p");
message.textContent = `=> 'cellEditEnter' with 'value':` + args.detail.oldValue, args.detail.cancel;
container.appendChild(message);
}
public webGridCellEdit(sender: IgrTreeGrid, args: IgrGridEditEventArgs): void {
let container = document.getElementById("container");
const message = document.createElement("p");
message.textContent = `=> 'cellEdit' with 'newValue':` + args.detail.newValue, args.detail.cancel;
container.appendChild(message);
}
public webGridCellEditDone(sender: IgrTreeGrid, args: IgrGridEditDoneEventArgs): void {
let container = document.getElementById("container");
const message = document.createElement("p");
message.textContent = `=> 'cellEditDone'`;
container.appendChild(message);
}
public webGridCellEditExit(sender: IgrTreeGrid, args: IgrGridEditDoneEventArgs): void {
let container = document.getElementById("container");
const message = document.createElement("p");
message.textContent = `=> 'cellEditExit'`;
container.appendChild(message);
}
}
// rendering above component in the React DOM
const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(<Sample /> );
tsx コピー
このサンプルが気に入りましたか? 完全な Ignite UI for Reactツールキットにアクセスして、すばやく独自のアプリの作成を開始します。無料でダウンロードできます。
機能の統合
セル/行が編集モードの場合、ユーザーはさまざまな方法でグリッドを操作できます。以下のテーブルは、特定の操作が現在の編集にどのように影響するかを示しています。
Tree Grid
フィルタリング
ソート
ページング
移動
ピン固定
非表示
グループ化
サイズ変更
Escape
Enter
F2
Tab
セル クリック
新しい行の追加/削除/編集
編集モードを保持
✔
編集モードを終了
✔
✔
✔
✔
✔
✔
✔
✔
✔
✔
✔
✔
✔
コミット
✔
✔
✔
✔
✔
破棄
✔
✔
✔
✔
✔
✔
✔
✔
テーブルからわかるように、列のサイズ変更を除くすべての操作は編集を終了し、新しい値を破棄します。新しい値がコミットされる場合、対応する機能の 「-ing」 イベントで開発者が実行できます。
たとえば、ユーザーがセル/行が編集モードのときに列をソートしようとする場合に、新しい値をコミットする方法を示します:
function onSorting(grid: IgrTreeGrid, event: IgrSortingEventArgs) {
grid.endEdit(true );
}
<IgrTreeGrid data ={localData} primaryKey ="ProductID" sorting ={onSorting} >
</IgrTreeGrid >
tsx
API リファレンス
その他のリソース