Ignite UI for Web Components 데이터 테이블/데이터 그리드는 약간의 코딩이나 구성으로 데이터를 빠르게 바인딩하고 표시할 수 있는 테이블 형식의 Web Components 그리드 구성 요소입니다. 툴박스의 Web Components 데이터 그리드 기능에는 필터링, 정렬, 템플릿, 행 선택, 행 그룹화, 행 고정 및 이동 가능한 열 등이 있습니다.
Web Components 테이블은 라이브 스트리밍 데이터에 최적화되어 있으며, 여러 행 또는 열에서 데이터 세트 크기를 무제한으로 처리할 수 있습니다.
Web Components 데이터 그리드 예제
이 Ignite UI for Web Components 그리드 예제에서는 사용자가 기본 및 Excel 스타일 필터링, 라이브 데이터 정렬을 모두 수행하고 그리드 요약 및 셀 템플릿을 사용하는 방법을 확인할 수 있습니다. 데모에는 페이지당 10개의 항목을 표시하도록 설정된 페이징도 포함되어 있습니다.
<!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-gridauto-generate="false"id="grid"name="grid"id="grid"primary-key="ProductID"allow-filtering="true"filter-mode="excelStyleFilter"><igc-paginatorper-page="10"></igc-paginator><igc-columnfield="ProductName"header="Product Name"data-type="string"sortable="true"has-summary="true"editable="true"resizable="true"></igc-column><igc-columnfield="UnitPrice"header="Unit Price"data-type="number"sortable="true"has-summary="true"editable="true"resizable="true"></igc-column><igc-columnfield="UnitsInStock"header="Units in Stock"data-type="number"sortable="true"has-summary="true"editable="true"resizable="true"></igc-column><igc-columnfield="OrderDate"header="Order Date"data-type="date"sortable="true"has-summary="true"editable="true"resizable="true"></igc-column><igc-columnfield="Discontinued"header="Discontinued"data-type="boolean"sortable="true"has-summary="true"editable="true"name="column1"id="column1"></igc-column><igc-columnfield="ReorderLevel"header="Reorder Level"data-type="number"sortable="true"has-summary="true"editable="true"filterable="true"></igc-column></igc-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
constructor() {
let grid1 = document.getElementById("grid1") as IgcGridComponent;
grid1.data = data;
}
typescript
id 속성은 문자열 값이며 제공되지 않은 경우 자동 생성되는 그리드의 고유 식별자이며, data 그리드(이 경우 로컬 데이터)를 바인딩합니다.
이 autoGenerate 속성은 데이터 원본 필드를 기반으로 그리드 IgcColumnComponent의 구성 요소를 자동으로 생성하도록 그리드에 지시합니다. 또한 가능한 경우 열에 적합한 데이터 형식을 추론하려고 시도합니다. 그렇지 않으면 개발자는 열과 데이터 원본 필드에 대한 매핑을 명시적으로 정의해야 합니다.
편집 가능한 Web Components 그리드
그리드 편집을 위한 각 작업에는 일괄 작업이 포함되어 있습니다. 즉, API는 편집 내용을 단일 서버 호출로 그룹화하거나 그리드 상호 작용으로 발생하는 대로 그리드 편집/업데이트 작업을 수행할 수 있는 옵션을 제공합니다. CRUD 작업이 있는 편집 가능한 그리드로서 훌륭한 개발자 경험과 함께 그리드에는 Excel과 같은 키보드 탐색이 포함됩니다. 일반적인 기본 그리드 탐색이 포함되어 있으며, 고객의 요구 사항을 충족시키기 위해 모든 탐색 옵션을 재정의하는 옵션도 있습니다. 훌륭한 탐색 체계가 있는 편집 가능한 그리드는 모든 최신 사업 분야 애플리케이션에 필수적이며, Ignite UI 그리드를 사용하면 쉽게 만들 수 있습니다.
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`<spantabindex="0" @keydown="${() => this.deleteRow(ctx.cell.id.rowIndex)}">${this.formatTitleCase(ctx.cell.value)}</span>
`;
}
public subscriptionCellTemplate = (ctx: IgcCellTemplateContext) => {
if (ctx.cell.value) {
return html`<inputtype="checkbox"checked /> `;
} else {
return html`<inputtype="checkbox"/> `;
}
}
publicdeleteRow(rowIndex: number) {
this.grid.deleteRow(rowIndex);
}
publicformatTitleCase(value: string) {
return value.toUpperCase();
}
typescript
참고: 그리드는 숫자, 문자열, 날짜 및 부울 열 유형에 대한 기본 처리를 노출합니다. 예를 들어 열은 부울 열 유형에 대해 기본적으로 참/거짓 대신 check 또는 close 아이콘을 표시합니다.
올바르게 구현되면 셀 편집 템플릿은 셀의 EditValue 그리드 편집 이벤트 주기를 올바르게 통과하도록 합니다.
셀 편집 템플릿
또한 이 열은 셀이 편집 모드에 있을 때 사용되는 마지막 템플릿 하나를 허용합니다. 다른 열 템플릿과 마찬가지로 제공된 컨텍스트 개체는 다시 셀 값이자 셀 개체 자체입니다. 물론 최종 사용자가 편집 모드 템플릿에 액세스할 수 있도록 하려면 열의 editable 속성을 true로 설정해야 합니다.
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><inputname="price"type="number"value="${ctx.cell.value}" @change="${() => this.updateValue(ctx.cell.value)}" />
`;
}
publicupdateValue(value: number) {
}
typescript
템플릿에서 사용할 수 있는 제공된 속성에 익숙해지려면 API Cell를 확인해야 합니다.
열 템플릿 API
각 열 템플릿은 개체 자체를 통해 언제든지 프로그래밍 방식으로 변경할 수 있습니다 IgcColumnComponent. 예를 들어 아래 코드에서는 사용자 데이터에 대한 두 개의 템플릿을 선언했습니다. TypeScript 코드에서 템플릿 자체에 대한 참조를 가져온 다음 일부 조건에 따라 애플리케이션의 열에 적합한 템플릿을 렌더링합니다.
var user = this.user = document.getElementById('user') as IgcColumnComponent;
// Return the appropriate template based on some condition.// For example saved user settings, viewport size, etc.
user.bodyTemplate = this.smallView;
public normalViewTemplate = (ctx: IgcCellTemplateContext) => {
return html`<divclass="user-details">${ ctx.cell.value }</div><user-details-component></user-details-component>
`;
}
public smallViewTemplate = (ctx: IgcCellTemplateContext) => {
return html`<divclass="user-details-small">${ ctx.cell.value }</div>
`;
}
typescript
열 속성은 그리드에서 열이 초기화될 때 발생하는 ColumnInit 이벤트의 코드에서 설정할 수도 있습니다.
그리드를 더 진행하기 전에 대규모 애플리케이션의 일반적인 시나리오인 원격 데이터 서비스에 바인딩하도록 그리드를 변경하려고 합니다.
JSON 응답을 수신한 특정 URL에서 데이터를 가져오고 이를 그리드의 데이터 소스로 사용되는 그리드의 data 속성에 할당하여 이를 수행할 수 있습니다.
<igc-gridid="grid1"></igc-grid>html
public fetchData(url: string): void {
fetch(url)
.then(response => response.json())
.then(data =>this.onDataLoaded(data));
}
publiconDataLoaded(jsonData: any[]) {
var grid1 = document.getElementById("grid1") as IgcGridComponent;
grid1.data = jsonData;
}
typescript
참고: 지금은 원격 데이터에 바인딩할 때 그리드 autoGenerate 속성을 피하는 것이 가장 좋습니다. 데이터를 검사하고 적절한 열을 생성하기 위해 데이터를 사용할 수 있다고 가정합니다. 일반적으로 원격 서비스가 응답할 때까지는 그렇지 않으며 그리드에서 오류가 발생합니다. 원격 서비스에 바인딩할 때 autoGenerate 사용할 수 있도록 하는 것은 향후 버전의 로드맵에 있습니다.
복잡한 데이터 바인딩
IgcGridComponent는 데이터 레코드에 있는 속성의 "경로"를 통해 복잡한 개체(한 수준보다 깊은 중첩 포함)에 대한 바인딩을 지원합니다.
<!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-gridauto-generate="false"name="grid"id="grid"id="grid"><igc-columnheader="Name"field="Name"width="15%"></igc-column><igc-columnfield="Title"header="Title"width="15%"></igc-column><igc-columnfield="Salary"header="Salary"width="10%"></igc-column><igc-columnfield="Employees"header="Employees"width="20%"name="column1"id="column1"></igc-column><igc-columnfield="City"header="City"width="15%"></igc-column><igc-columnfield="Country"header="Country"width="15%"></igc-column><igc-columnfield="Age"header="Age"width="10%"></igc-column><igc-columnfield="HireDate"header="Hire Date"data-type="date"></igc-column></igc-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
플랫 데이터 작업 개요
플랫 데이터 바인딩 접근 방식은 위에서 이미 설명한 것과 유사하지만 셀 값 대신 IgcGridRow의 data 속성을 사용할 것입니다.
Web Components 그리드는 데이터 레코드를 렌더링, 조작 및 보존 하기 위한 구성 요소이므로 모든 데이터 레코드에 액세스할 수 있으면 처리 방식을 사용자 지정할 수 있습니다. 이 부동산은 data 이러한 기회를 제공합니다.
constructor() {
var address = this.address = document.getElementById('address') as IgcColumnComponent;
address.bodyTemplate = this.addressCellTemplate;
}
public addressCellTemplate = (ctx: IgcCellTemplateContext) => {
return html`<divclass="address-container"><!-- In the Address column combine the Country, City and PostCode values of the corresponding data record --><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>
`;
}
publicgetCountry(rowIndex: number) {
returnthis.grid.getRowByIndex(rowIndex).data["Country"];
}
publicgetCity(rowIndex: number) {
returnthis.grid.getRowByIndex(rowIndex).data["City"];
}
publicgetPostalCode(rowIndex: number) {
returnthis.grid.getRowByIndex(rowIndex).data["PostalCode"];
}
typescript
<!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-gridauto-generate="false"primary-key="ID"name="grid"id="grid"><igc-columnheader="ID"field="ID"></igc-column><igc-columnfield="ContactName"header="Contact"editable="true"width="250px"resizable="false"name="column1"id="column1"></igc-column><igc-columnheader="Address"field="Address"editable="true"width="250px"resizable="false"name="column2"id="column2"></igc-column><igc-columnheader="Country"field="Country"></igc-column><igc-columnheader="Region"field="Region"></igc-column><igc-columnheader="Phone"field="Phone"></igc-column><igc-columnheader="Fax"field="Fax"></igc-column></igc-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
키보드 탐색
IgcGridComponent의 키보드 탐색은 사용자에게 다양한 키보드 상호 작용을 제공합니다. 접근성을 향상시키고 내부의 모든 유형의 요소(셀, 행, 열 머리글, 도구 모음, 바닥글 등)를 통해 직관적인 탐색을 허용합니다.
Web Components 그리드 스타일링
참고: 그리드는 css 그리드 레이아웃을 사용하며 접두사가 없는 IE에서는 지원되지 않으므로 제대로 렌더링되지 않습니다.
사전 정의된 테마 외에도 사용 가능한 CSS 속성 중 일부를 설정하여 그리드를 추가로 사용자 정의할 수 있습니다. 헤더 배경과 텍스트 색상을 변경하려면 먼저 그리드에 대한 클래스를 설정해야 합니다.
<igc-gridclass="grid"></igc-grid>html
그런 다음 해당 클래스에 대해--header-background 및--header-text-color CSS 속성을 설정합니다.