Web Components Hierarchical Grid の Ignite UI for Web Components 列移動機能を使用すると、列をすばやく簡単に並べ替えることができます。これは、列移動 API を使用するか、マウスまたはタッチ ジェスチャを使用してヘッダーを別の位置にドラッグ アンド ドロップすることによって実行できます。Web Components Hierarchical Grid では、ピン固定された列とピン固定されていない列、および複数列ヘッダーに対しても列の移動を有効にすることができます。
import'igniteui-webcomponents-grids/grids/combined';
import { IgcHierarchicalGridComponent, IgcPaginatorComponent, IgcColumnComponent } from'igniteui-webcomponents-grids/grids';
import HierarchicalCustomers from'./HierarchicalCustomers.json';
import { IgcColumnTemplateContext } from'igniteui-webcomponents-grids/grids';
import { html, nothing } from'lit-html';
import"igniteui-webcomponents-grids/grids/themes/light/bootstrap.css";
import"./index.css";
exportclassSample{
private hierarchicalGrid1: IgcHierarchicalGridComponent
private paginator: IgcPaginatorComponent
private column1: IgcColumnComponent
private column2: IgcColumnComponent
private column3: IgcColumnComponent
private column4: IgcColumnComponent
private column5: IgcColumnComponent
private column6: IgcColumnComponent
private column7: IgcColumnComponent
private column8: IgcColumnComponent
private column9: IgcColumnComponent
private column10: IgcColumnComponent
private _bind: () =>void;
constructor() {
var hierarchicalGrid1 = this.hierarchicalGrid1 = document.getElementById('hierarchicalGrid1') as IgcHierarchicalGridComponent;
var paginator = this.paginator = document.getElementById('paginator') as IgcPaginatorComponent;
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;
var column4 = this.column4 = document.getElementById('column4') as IgcColumnComponent;
var column5 = this.column5 = document.getElementById('column5') as IgcColumnComponent;
var column6 = this.column6 = document.getElementById('column6') as IgcColumnComponent;
var column7 = this.column7 = document.getElementById('column7') as IgcColumnComponent;
var column8 = this.column8 = document.getElementById('column8') as IgcColumnComponent;
var column9 = this.column9 = document.getElementById('column9') as IgcColumnComponent;
var column10 = this.column10 = document.getElementById('column10') as IgcColumnComponent;
this._bind = () => {
hierarchicalGrid1.data = this.hierarchicalCustomers;
column1.headerTemplate = this.hierarchicalGridPinHeaderTemplate;
column2.headerTemplate = this.hierarchicalGridPinHeaderTemplate;
column3.headerTemplate = this.hierarchicalGridPinHeaderTemplate;
column4.headerTemplate = this.hierarchicalGridPinHeaderTemplate;
column5.headerTemplate = this.hierarchicalGridPinHeaderTemplate;
column6.headerTemplate = this.hierarchicalGridPinHeaderTemplate;
column7.headerTemplate = this.hierarchicalGridPinHeaderTemplate;
column8.headerTemplate = this.hierarchicalGridPinHeaderTemplate;
column9.headerTemplate = this.hierarchicalGridPinHeaderTemplate;
column10.headerTemplate = this.hierarchicalGridPinHeaderTemplate;
}
this._bind();
}
private _hierarchicalCustomers: any[] = HierarchicalCustomers;
publicgethierarchicalCustomers(): any[] {
returnthis._hierarchicalCustomers;
}
public hierarchicalGridPinHeaderTemplate = (ctx: IgcColumnTemplateContext) => {
const column = (ctx asany).column;
return html`<div><spanstyle="float:left">${column.field}</span><spanstyle="float:right" @pointerdown=${(e: any) => this.toggleColumnPin(column)}>📌</span></div>`;
};
publictoggleColumnPin(field: IgcColumnComponent) {
if(field) {
field.pinned = !field.pinned;
}
}
}
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-hierarchical-gridauto-generate="false"moving="true"name="hierarchicalGrid1"id="hierarchicalGrid1"><igc-paginatorname="paginator"id="paginator"per-page="15"></igc-paginator><igc-columnfield="CustomerID"data-type="string"name="column1"id="column1"></igc-column><igc-columnfield="Company"data-type="string"width="150px"name="column2"id="column2"></igc-column><igc-columnfield="ContactName"data-type="string"width="150px"name="column3"id="column3"></igc-column><igc-columnfield="ContactTitle"data-type="string"width="150px"name="column4"id="column4"></igc-column><igc-columnfield="Address"data-type="string"name="column5"id="column5"></igc-column><igc-columnfield="City"data-type="string"name="column6"id="column6"></igc-column><igc-columnfield="PostalCode"data-type="string"name="column7"id="column7"></igc-column><igc-columnfield="Country"data-type="string"name="column8"id="column8"></igc-column><igc-columnfield="Phone"data-type="string"name="column9"id="column9"></igc-column><igc-columnfield="Fax"data-type="string"name="column10"id="column10"></igc-column><igc-row-islandchild-data-key="Orders"auto-generate="false"moving="true"><igc-columnfield="OrderID"data-type="number"></igc-column><igc-columnfield="EmployeeID"data-type="number"></igc-column><igc-columnfield="OrderDate"data-type="date"></igc-column><igc-columnfield="RequiredDate"data-type="date"></igc-column><igc-columnfield="ShippedDate"data-type="date"></igc-column><igc-columnfield="ShipVia"data-type="number"></igc-column><igc-columnfield="Freight"data-type="number"></igc-column><igc-columnfield="ShipName"data-type="string"></igc-column><igc-columnfield="ShipAddress"data-type="string"></igc-column><igc-columnfield="ShipCity"data-type="string"></igc-column><igc-columnfield="ShipPostalCode"data-type="string"></igc-column><igc-columnfield="ShipCountry"data-type="string"></igc-column><igc-row-islandchild-data-key="OrderDetails"auto-generate="false"moving="true"><igc-columnfield="ProductID"data-type="number"></igc-column><igc-columnfield="UnitPrice"data-type="number"></igc-column><igc-columnfield="Quantity"data-type="number"></igc-column><igc-columnfield="Discount"data-type="number"></igc-column></igc-row-island></igc-row-island></igc-hierarchical-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
このサンプルが気に入りましたか? 完全な Ignite UI for Web Componentsツールキットにアクセスして、すばやく独自のアプリの作成を開始します。無料でダウンロードできます。
// Move the ID column after the Name columnconst idColumn = grid.getColumnByName("ID");
const nameColumn = grid.getColumnByName("Name");
grid.moveColumn(idColumn, nameColumn, DropPosition.AfterDropTarget);
typescript
IgcHierarchicalGridComponent の ColumnMovingEnd イベントを処理し、列が新しい位置にドロップされたときにカスタム ロジックを実装できます。たとえば、以下のスニペットでは、Change On Year(%) 列の後に Category のドロップをキャンセルできます。
<igc-hierarchical-gridid="dataGrid"auto-generate="false"moving="true"><igc-columnfield="Category"></igc-column><igc-columnfield="Change On Year(%)"data-type="Number" ></igc-column></igc-hierarchical-grid>html
constructor() {
var dataGrid = this.dataGrid = document.getElementById('dataGrid') as IgcHierarchicalGridComponent;
dataGrid.data = this.data;
dataGrid.addEventListener("columnMovingEnd", this.onColumnMovingEnd);
}
typescript
publiconColumnMovingEnd(event) {
if (event.detail.source.field === "Category" && event.detail.target.field === "Change On Year(%)") {
event.detail.cancel = true;
}
}
typescript
import'igniteui-webcomponents-grids/grids/combined';
import { IgcHierarchicalGridComponent, IgcPaginatorComponent, IgcColumnComponent } from'igniteui-webcomponents-grids/grids';
import HierarchicalCustomers from'./HierarchicalCustomers.json';
import { IgcColumnTemplateContext } from'igniteui-webcomponents-grids/grids';
import { html, nothing } from'lit-html';
import"igniteui-webcomponents-grids/grids/themes/light/bootstrap.css";
import"./index.css";
exportclassSample{
private grid: IgcHierarchicalGridComponent
private paginator: IgcPaginatorComponent
private column1: IgcColumnComponent
private column2: IgcColumnComponent
private column3: IgcColumnComponent
private column4: IgcColumnComponent
private column5: IgcColumnComponent
private column6: IgcColumnComponent
private column7: IgcColumnComponent
private column8: IgcColumnComponent
private column9: IgcColumnComponent
private column10: IgcColumnComponent
private _bind: () =>void;
constructor() {
var grid = this.grid = document.getElementById('grid') as IgcHierarchicalGridComponent;
var paginator = this.paginator = document.getElementById('paginator') as IgcPaginatorComponent;
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;
var column4 = this.column4 = document.getElementById('column4') as IgcColumnComponent;
var column5 = this.column5 = document.getElementById('column5') as IgcColumnComponent;
var column6 = this.column6 = document.getElementById('column6') as IgcColumnComponent;
var column7 = this.column7 = document.getElementById('column7') as IgcColumnComponent;
var column8 = this.column8 = document.getElementById('column8') as IgcColumnComponent;
var column9 = this.column9 = document.getElementById('column9') as IgcColumnComponent;
var column10 = this.column10 = document.getElementById('column10') as IgcColumnComponent;
this._bind = () => {
grid.data = this.hierarchicalCustomers;
column1.headerTemplate = this.hierarchicalGridPinHeaderTemplate;
column2.headerTemplate = this.hierarchicalGridPinHeaderTemplate;
column3.headerTemplate = this.hierarchicalGridPinHeaderTemplate;
column4.headerTemplate = this.hierarchicalGridPinHeaderTemplate;
column5.headerTemplate = this.hierarchicalGridPinHeaderTemplate;
column6.headerTemplate = this.hierarchicalGridPinHeaderTemplate;
column7.headerTemplate = this.hierarchicalGridPinHeaderTemplate;
column8.headerTemplate = this.hierarchicalGridPinHeaderTemplate;
column9.headerTemplate = this.hierarchicalGridPinHeaderTemplate;
column10.headerTemplate = this.hierarchicalGridPinHeaderTemplate;
}
this._bind();
}
private _hierarchicalCustomers: any[] = HierarchicalCustomers;
publicgethierarchicalCustomers(): any[] {
returnthis._hierarchicalCustomers;
}
public hierarchicalGridPinHeaderTemplate = (ctx: IgcColumnTemplateContext) => {
const column = (ctx asany).column;
return html`<div><spanstyle="float:left">${column.field}</span><spanstyle="float:right" @pointerdown=${(e: any) => this.toggleColumnPin(column)}>📌</span></div>`;
};
publictoggleColumnPin(field: IgcColumnComponent) {
if(field) {
field.pinned = !field.pinned;
}
}
}
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-hierarchical-gridauto-generate="false"moving="true"name="grid"id="grid"id="grid"><igc-paginatorname="paginator"id="paginator"per-page="15"></igc-paginator><igc-columnfield="CustomerID"data-type="string"name="column1"id="column1"></igc-column><igc-columnfield="Company"data-type="string"width="150px"name="column2"id="column2"></igc-column><igc-columnfield="ContactName"data-type="string"width="150px"name="column3"id="column3"></igc-column><igc-columnfield="ContactTitle"data-type="string"width="150px"name="column4"id="column4"></igc-column><igc-columnfield="Address"data-type="string"name="column5"id="column5"></igc-column><igc-columnfield="City"data-type="string"name="column6"id="column6"></igc-column><igc-columnfield="PostalCode"data-type="string"name="column7"id="column7"></igc-column><igc-columnfield="Country"data-type="string"name="column8"id="column8"></igc-column><igc-columnfield="Phone"data-type="string"name="column9"id="column9"></igc-column><igc-columnfield="Fax"data-type="string"name="column10"id="column10"></igc-column><igc-row-islandchild-data-key="Orders"auto-generate="false"moving="true"><igc-columnfield="OrderID"data-type="number"></igc-column><igc-columnfield="EmployeeID"data-type="number"></igc-column><igc-columnfield="OrderDate"data-type="date"></igc-column><igc-columnfield="RequiredDate"data-type="date"></igc-column><igc-columnfield="ShippedDate"data-type="date"></igc-column><igc-columnfield="ShipVia"data-type="number"></igc-column><igc-columnfield="Freight"data-type="number"></igc-column><igc-columnfield="ShipName"data-type="string"></igc-column><igc-columnfield="ShipAddress"data-type="string"></igc-column><igc-columnfield="ShipCity"data-type="string"></igc-column><igc-columnfield="ShipPostalCode"data-type="string"></igc-column><igc-columnfield="ShipCountry"data-type="string"></igc-column><igc-row-islandchild-data-key="OrderDetails"auto-generate="false"moving="true"><igc-columnfield="ProductID"data-type="number"></igc-column><igc-columnfield="UnitPrice"data-type="number"></igc-column><igc-columnfield="Quantity"data-type="number"></igc-column><igc-columnfield="Discount"data-type="number"></igc-column></igc-row-island></igc-row-island></igc-hierarchical-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