트리 그리드의 Ignite UI for Web Components 셀 편집 Web Components Web Components 트리 그리드 구성 요소 내의 개별 셀 내용에 대한 뛰어난 데이터 조작 기능을 제공하며 React CRUD 작업을 위한 강력한 API와 함께 제공됩니다. 스프레드시트, 데이터 테이블 및 데이터 그리드와 같은 앱의 기본 기능으로, 사용자가 특정 셀 내에서 데이터를 추가, 편집 또는 업데이트할 수 있습니다. 기본적으로 Ignite UI for Web Components의 그리드는 셀 편집에 사용됩니다. 그리고 기본 셀 편집 템플릿으로 인해 열 데이터 유형 Top of Form에 따라 다른 편집기가 있습니다.
또한 데이터 업데이트 작업에 대한 사용자 정의 템플릿을 정의하고 변경 사항 커밋 및 삭제에 대한 기본 동작을 재정의할 수 있습니다.
Web Components Tree Grid Cell Editing and Edit Templates Example
EXAMPLE
Like this sample? Get access to our complete Ignite UI for Web Components toolkit and start building your own apps in minutes. Download it for free.
셀 편집
Editing through UI
다음 방법 중 하나로 편집 가능한 셀에 초점이 맞춰지면 특정 셀에 대한 편집 모드로 들어갈 수 있습니다.
두 번 클릭하면;
한 번 클릭 시 - 이전에 선택한 셀이 편집 모드이고 현재 선택한 셀이 편집 가능한 경우에만 한 번 클릭하면 편집 모드로 들어갑니다. 이전에 선택한 셀이 편집 모드가 아닌 경우 한 번 클릭하면 편집 모드로 들어가지 않고 셀이 선택됩니다.
페이징, 크기 조정, 고정 또는 이동과 같은 작업을 수행하면 편집 모드가 종료되고 변경 사항이 제출됩니다.
The cell remains in edit mode when you scroll vertically or horizontally or click outside the IgcTreeGridComponent. This is valid for both cell editing and row editing.
셀을 업데이트하는 또 다른 방법은 다음과 같은 방법을 사용하는 Update 것입니다. Cell
publicupdateCell() {
const cell = this.treeGrid.getCellByColumn(rowIndex, 'Age');
// You can also get cell by rowID if primary key is defined// const cell = this.treeGrid.getCellByKey(rowID, 'Age');
cell.update(9999);
}
typescript
import'igniteui-webcomponents-grids/grids/combined';
import { ComponentRenderer, WebTreeGridDescriptionModule, WebSelectDescriptionModule } from'igniteui-webcomponents-core';
import { IgcTreeGridComponent, IgcColumnComponent } from'igniteui-webcomponents-grids/grids';
import { RoleplayTreeGridDataItem, RoleplayTreeGridData } from'./RoleplayTreeGridData';
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";
exportclassSample{
private treeGrid1: IgcTreeGridComponent
private column1: IgcColumnComponent
private column2: IgcColumnComponent
private column3: IgcColumnComponent
private _bind: () =>void;
constructor() {
var treeGrid1 = this.treeGrid1 = document.getElementById('treeGrid1') as IgcTreeGridComponent;
var column1 = this.column1 = document.getElementById('column1') as IgcColumnComponent;
var column2 = this.column2 = document.getElementById('column2') as IgcColumnComponent;
var column3 = this.column3 = document.getElementById('column3') as IgcColumnComponent;
this._bind = () => {
treeGrid1.data = this.roleplayTreeGridData;
column1.inlineEditorTemplate = this.webTreeGridCellEditCellTemplate;
column2.inlineEditorTemplate = this.webTreeGridCellEditCellTemplate;
column3.inlineEditorTemplate = this.webTreeGridCellEditCellTemplate;
}
this._bind();
}
private _roleplayTreeGridData: RoleplayTreeGridData = null;
publicgetroleplayTreeGridData(): RoleplayTreeGridData {
if (this._roleplayTreeGridData == null)
{
this._roleplayTreeGridData = new RoleplayTreeGridData();
}
returnthis._roleplayTreeGridData;
}
private _componentRenderer: ComponentRenderer = null;
publicgetrenderer(): ComponentRenderer {
if (this._componentRenderer == null) {
this._componentRenderer = new ComponentRenderer();
var context = this._componentRenderer.context;
WebTreeGridDescriptionModule.register(context);
WebSelectDescriptionModule.register(context);
}
returnthis._componentRenderer;
}
public webTreeGridCellEditCellTemplate = (ctx: IgcCellTemplateContext) => {
let cellValues: any = [];
let uniqueValues: any = [];
let roleplayData = this.roleplayTreeGridData
for (const i of (roleplayData asany)){
const field: string = ctx.cell.column.field;
if(uniqueValues.indexOf(i[field]) === -1 )
{
if (ctx.cell.value == i[field]) {
cellValues.push(html`<igc-select-itemselectedvalue=${i[field]}>${(i[field])}</igc-select-item>`);
} else cellValues.push(html`<igc-select-itemvalue=${i[field]}>${(i[field])}</igc-select-item>`);
uniqueValues.push(i[field]);
}
}
return html`<igc-selectstyle="width:100%; height:100%; --ig-size: var(--ig-size-large);" @igcChange=${(e: any) => ctx.cell.editValue = e.detail.value}>${cellValues}</igc-select>
`;
}
}
new Sample();
ts
<!DOCTYPE html><html><head><title>Sample | Ignite UI | Web Components | infragistics</title><metacharset="UTF-8" /><linkrel="shortcut icon"href="https://static.infragistics.com/xplatform/images/browsers/wc.png" ><linkrel="stylesheet"href="https://fonts.googleapis.com/icon?family=Material+Icons" /><linkrel="stylesheet"href="https://fonts.googleapis.com/css?family=Kanit&display=swap" /><linkrel="stylesheet"href="https://fonts.googleapis.com/css?family=Titillium Web" /><linkrel="stylesheet"href="https://static.infragistics.com/xplatform/css/samples/shared.v8.css" /><linkrel="stylesheet"href="/src/index.css"type="text/css" /></head><body><divid="root"><divclass="container sample ig-typography"><divclass="container fill"><igc-tree-gridauto-generate="false"name="treeGrid1"id="treeGrid1"id="treeGrid1"primary-key="ID"foreign-key="ParentID"><igc-columnfield="Name"header="Character Name"data-type="string"></igc-column><igc-columnfield="Race"header="Race"data-type="string"editable="true"name="column1"id="column1"></igc-column><igc-columnfield="Class"header="Class"data-type="string"editable="true"name="column2"id="column2"></igc-column><igc-columnfield="Age"header="Age"data-type="string"editable="true"></igc-column><igc-columnfield="Alignment"header="Alignment"data-type="string"editable="true"name="column3"id="column3"></igc-column></igc-tree-grid></div></div></div><!-- This script is needed only for parcel and it will be excluded for webpack -->
<% if (false) { %><scriptsrc="src/index.ts"></script><% } %>
</body></html>html
/* shared styles are loaded from: *//* https://static.infragistics.com/xplatform/css/samples */css
CRUD operations
Please keep in mind that when you perform some CRUD operation all of the applied pipes like filtering, sorting and grouping will be re-applied and your view will be automatically updated.
The IgcTreeGridComponent provides a straightforward API for basic CRUD operations.
publicaddNewChildRow() {
// Adding a new record// Assuming we have a `getNewRecord` method returning the new row data// And specifying the parentRowID.const record = this.getNewRecord();
this.treeGrid.addRow(record, 1);
}
typescript
Updating data in the Tree Grid
트리 그리드의 데이터 업데이트는 updateRow 및 updateCell 메소드를 통해 이루어지지만 그리드의 PrimaryKey가 정의된 경우에만 가능합니다. 또한 해당 업데이트 방법을 통해 셀 및/또는 행 값을 직접 업데이트할 수도 있습니다.
// Updating the whole rowthis.treeGrid.updateRow(newData, this.selectedCell.cellID.rowID);
// Just a particular cell through the Tree Grid APIthis.treeGrid.updateCell(newData, this.selectedCell.cellID.rowID, this.selectedCell.column.field);
// Directly using the cell `update` methodthis.selectedCell.update(newData);
// Directly using the row `update` methodconst row = this.treeGrid.getRowByKey(rowID);
row.update(newData);
typescript
이 예에서는 CellEdit 이벤트에 바인딩하여 입력된 데이터를 기반으로 셀의 유효성을 검사합니다. 셀의 새 값이 사전 정의된 기준을 충족하지 않는 경우 이벤트를 취소하여 데이터 소스에 도달하지 못하게 합니다.
가장 먼저 해야 할 일은 그리드의 이벤트에 바인딩하는 것입니다.
constructor() {
var treeGrid = document.getElementById('treeGrid') as IgcTreeGridComponent;
this.webTreeGridCellEdit = this.webTreeGridCellEdit.bind(this);
treeGrid.addEventListener("cellEdit", this.webTreeGridCellEdit);
}
typescript
CellEdit 셀의 값이 커밋되려고 할 때마다 내보냅니다. CellEdit 정의에서 조치를 취하기 전에 특정 열을 확인해야 합니다.
public webTreeGridCellEdit(event: CustomEvent<IgcGridEditEventArgs>): void {
const column = event.detail.column;
if (column.field === 'Age') {
if (event.detail.newValue < 18) {
event.detail.cancel = true;
alert('Employees must be at least 18 years old!');
}
} elseif (column.field === 'HireDate') {
if (event.detail.newValue > newDate().getTime()) {
event.detail.cancel = true;
alert('The employee hire date must be in the past!');
}
}
}
typescript
import'igniteui-webcomponents-grids/grids/combined';
import { ComponentRenderer, WebTreeGridDescriptionModule } from'igniteui-webcomponents-core';
import { IgcTreeGridComponent } from'igniteui-webcomponents-grids/grids';
import { EmployeesNestedTreeDataItem, EmployeesNestedTreeData } from'./EmployeesNestedTreeData';
import { IgcGridComponent, IgcGridEditEventArgs } from'igniteui-webcomponents-grids/grids';
import"igniteui-webcomponents-grids/grids/themes/light/bootstrap.css";
import"./index.css";
exportclassSample{
private treeGrid: IgcTreeGridComponent
private _bind: () =>void;
constructor() {
var treeGrid = this.treeGrid = document.getElementById('treeGrid') as IgcTreeGridComponent;
this.webTreeGridCellEdit = this.webTreeGridCellEdit.bind(this);
this._bind = () => {
treeGrid.data = this.employeesNestedTreeData;
treeGrid.addEventListener("cellEdit", this.webTreeGridCellEdit);
}
this._bind();
}
private _employeesNestedTreeData: EmployeesNestedTreeData = null;
publicgetemployeesNestedTreeData(): EmployeesNestedTreeData {
if (this._employeesNestedTreeData == null)
{
this._employeesNestedTreeData = new EmployeesNestedTreeData();
}
returnthis._employeesNestedTreeData;
}
private _componentRenderer: ComponentRenderer = null;
publicgetrenderer(): ComponentRenderer {
if (this._componentRenderer == null) {
this._componentRenderer = new ComponentRenderer();
var context = this._componentRenderer.context;
WebTreeGridDescriptionModule.register(context);
}
returnthis._componentRenderer;
}
public webTreeGridCellEdit(args: CustomEvent<IgcGridEditEventArgs>): void {
const column = args.detail.column;
if (column.field === 'Age') {
if (args.detail.newValue < 18) {
args.detail.cancel = true;
alert('Employees must be at least 18 years old!');
}
} elseif (column.field === 'HireDate') {
if (args.detail.newValue > newDate().getTime()) {
args.detail.cancel = true;
alert('The employee hire date must be in the past!');
}
}
}
}
new Sample();
ts
<!DOCTYPE html><html><head><title>Sample | Ignite UI | Web Components | infragistics</title><metacharset="UTF-8" /><linkrel="shortcut icon"href="https://static.infragistics.com/xplatform/images/browsers/wc.png" ><linkrel="stylesheet"href="https://fonts.googleapis.com/icon?family=Material+Icons" /><linkrel="stylesheet"href="https://fonts.googleapis.com/css?family=Kanit&display=swap" /><linkrel="stylesheet"href="https://fonts.googleapis.com/css?family=Titillium Web" /><linkrel="stylesheet"href="https://static.infragistics.com/xplatform/css/samples/shared.v8.css" /><linkrel="stylesheet"href="/src/index.css"type="text/css" /></head><body><divid="root"><divclass="container sample ig-typography"><divclass="container fill"><igc-tree-gridauto-generate="false"name="treeGrid"id="treeGrid"id="treeGrid"primary-key="ID"foreign-key="ParentID"><igc-columnfield="Name"data-type="string"></igc-column><igc-columnfield="Title"data-type="string"></igc-column><igc-columnfield="Age"data-type="number"editable="true"></igc-column><igc-columnfield="HireDate"data-type="date"editable="true"></igc-column></igc-tree-grid></div></div></div><!-- This script is needed only for parcel and it will be excluded for webpack -->
<% if (false) { %><scriptsrc="src/index.ts"></script><% } %>
</body></html>html
/* shared styles are loaded from: *//* https://static.infragistics.com/xplatform/css/samples */css
Styling
사전 정의된 테마 외에도 사용 가능한 CSS 속성 중 일부를 설정하여 그리드를 추가로 사용자 정의할 수 있습니다. 일부 색상을 변경하려면 먼저 그리드에 대한 클래스를 설정해야 합니다.
<!DOCTYPE html><html><head><title>Sample | Ignite UI | Web Components | infragistics</title><metacharset="UTF-8" /><linkrel="shortcut icon"href="https://static.infragistics.com/xplatform/images/browsers/wc.png" ><linkrel="stylesheet"href="https://fonts.googleapis.com/icon?family=Material+Icons" /><linkrel="stylesheet"href="https://fonts.googleapis.com/css?family=Kanit&display=swap" /><linkrel="stylesheet"href="https://fonts.googleapis.com/css?family=Titillium Web" /><linkrel="stylesheet"href="https://static.infragistics.com/xplatform/css/samples/shared.v8.css" /><linkrel="stylesheet"href="/src/index.css"type="text/css" /></head><body><divid="root"><divclass="container sample ig-typography"><divclass="container fill"><igc-tree-gridauto-generate="false"name="treeGrid"id="treeGrid"id="treeGrid"primary-key="ID"allow-filtering="true"foreign-key="ParentID"><igc-paginatorper-page="10"></igc-paginator><igc-columnfield="Name"data-type="string"editable="true"></igc-column><igc-columnfield="Title"data-type="string"editable="true"></igc-column><igc-columnfield="Age"data-type="number"editable="true"></igc-column><igc-columnfield="HireDate"data-type="date"editable="true"></igc-column><igc-columnfield="OnPTO"data-type="boolean"editable="true"width="130px"></igc-column></igc-tree-grid></div></div></div><!-- This script is needed only for parcel and it will be excluded for webpack -->
<% if (false) { %><scriptsrc="src/index.ts"></script><% } %>
</body></html>html