React Hierarchical Grid 列ピン固定
React Hierarchical Grid の Ignite UI for React 列のピン固定機能を使用すると、開発者は特定の列を希望の順序でロックできるため、ユーザーが IgrGrid
を水平方向にスクロールしている場合でも、常に可視性を確保できます。
列ピン固定用の統合 UI があり、React Hierarchical Grid ツールバーからアクセスできます。さらに、開発者は、列のピン状態を変更するカスタム ユーザー インターフェイスを柔軟に構築できます。
React Hierarchical Grid 列ピン固定の例
以下の例は、1 つまたは複数の列を IgrHierarchicalGrid
の左側または右側にピン固定する方法を示しています。
import React from 'react';
import ReactDOM from 'react-dom/client';
import './index.css';
import { IgrHierarchicalGridModule } from "@infragistics/igniteui-react-grids";
import { IgrHierarchicalGrid, IgrGridToolbar, IgrGridToolbarActions, IgrGridToolbarPinning, IgrColumn, IgrRowIsland } from "@infragistics/igniteui-react-grids";
import HierarchicalCustomersData from './HierarchicalCustomersData.json';
import "@infragistics/igniteui-react-grids/grids/themes/light/bootstrap.css";
const mods: any[] = [
IgrHierarchicalGridModule
];
mods.forEach((m) => m.register());
export default class Sample extends React.Component<any, any> {
private grid: IgrHierarchicalGrid
private gridRef(r: IgrHierarchicalGrid) {
this.grid = r;
this.setState({});
}
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">
<IgrHierarchicalGrid
ref={this.gridRef}
id="grid"
data={this.hierarchicalCustomersData}
columnSelection="single"
primaryKey="CustomerID">
<IgrGridToolbar
>
<IgrGridToolbarActions
>
<IgrGridToolbarPinning
>
</IgrGridToolbarPinning>
</IgrGridToolbarActions>
</IgrGridToolbar>
<IgrColumn
field="CustomerID"
hidden={true}>
</IgrColumn>
<IgrColumn
field="Company"
header="Company Name"
pinned={true}>
</IgrColumn>
<IgrColumn
field="ContactName"
header="Contact Name">
</IgrColumn>
<IgrColumn
field="ContactTitle"
header="Contact Title">
</IgrColumn>
<IgrColumn
field="Address"
header="Address">
</IgrColumn>
<IgrColumn
field="City"
header="City">
</IgrColumn>
<IgrColumn
field="PostalCode"
header="Postal Code">
</IgrColumn>
<IgrColumn
field="Country"
header="Country">
</IgrColumn>
<IgrColumn
field="Phone">
</IgrColumn>
<IgrColumn
field="Fax">
</IgrColumn>
<IgrRowIsland
childDataKey="Orders"
autoGenerate={false}>
<IgrColumn
field="OrderDate"
header="Order Date"
dataType="date"
resizable={true}>
</IgrColumn>
<IgrColumn
field="RequiredDate"
header="Required Date"
dataType="date"
resizable={true}>
</IgrColumn>
<IgrColumn
field="ShippedDate"
header="Shipped Date"
dataType="date"
resizable={true}>
</IgrColumn>
<IgrColumn
field="ShipName"
header="Ship Name"
dataType="string"
resizable={true}
pinned={true}>
</IgrColumn>
<IgrColumn
field="ShippedVia"
header="Shipped Via"
dataType="string"
resizable={true}>
</IgrColumn>
<IgrColumn
field="Freight"
header="Freight"
dataType="string"
resizable={true}>
</IgrColumn>
<IgrRowIsland
childDataKey="OrderDetails"
autoGenerate={false}>
<IgrColumn
field="UnitPrice"
header="Unit Price"
dataType="string"
resizable={true}>
</IgrColumn>
<IgrColumn
field="Quantity"
header="Quantity"
dataType="string"
resizable={true}>
</IgrColumn>
<IgrColumn
field="Discount"
header="Discount"
dataType="string"
resizable={true}>
</IgrColumn>
<IgrColumn
field="Weight"
header="Weight"
dataType="string"
resizable={true}>
</IgrColumn>
<IgrColumn
field="Length"
header="Length"
dataType="string"
resizable={true}>
</IgrColumn>
<IgrColumn
field="TotalPrice"
header="Total Price"
dataType="string"
resizable={true}>
</IgrColumn>
</IgrRowIsland>
</IgrRowIsland>
</IgrHierarchicalGrid>
</div>
</div>
);
}
private _hierarchicalCustomersData: any[] = HierarchicalCustomersData;
public get hierarchicalCustomersData(): any[] {
return this._hierarchicalCustomersData;
}
}
// rendering above component in the React DOM
const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(<Sample/>);
tsx/* shared styles are loaded from: */
/* https://static.infragistics.com/xplatform/css/samples */
css
このサンプルが気に入りましたか? 完全な Ignite UI for Reactツールキットにアクセスして、すばやく独自のアプリの作成を開始します。無料でダウンロードできます。
列ピン固定の API
列のピン固定は IgrColumn
の pinned
プロパティによって制御されます。デフォルトでピン固定列は IgrHierarchicalGrid
の左側に固定して描画され、IgrHierarchicalGrid
本体のピン固定されていない列は水平スクロールされます。
IgrHierarchicalGrid
の pinColumn
または unpinColumn
メソッドを使用してフィールド名によって列をピン固定またはピン固定解除できます。
this.hierarchicalGrid.pinColumn('Artist');
this.hierarchicalGrid.unpinColumn('Debut');
typescript
両方のメソッドは操作に成功したかどうかを示すブール値を返します。よくある失敗の原因に列がすでにその状態になっていることがあります。
列をピン固定すると、一番右に配置されたピン固定列の右にピン固定されます。ピン固定列の順序を変更するには、ColumnPin
イベントでイベント引数の InsertAtIndex
プロパティを適切な位置インデックスに変更します。
const columnPinning = (event: IgrPinColumnCancellableEventArgs) = {
if (event.detail.column.field === 'Name') {
event.detail.insertAtIndex = 0;
}
}
typescript
ピン固定の位置
pinning
設定オプションを使用して、列のピン固定の位置を変更できます。列の位置を [Start] または [End] のいずれかに設定できます。
[End] に設定すると、列がピン固定されていない列の後に、グリッドの最後にレンダリングされます。ピン固定されていない列は水平にスクロールできますが、ピン固定された列は右側に固定されます。
const pinningConfig: IgrPinningConfig = { columns: ColumnPinningPosition.End };
typescript
デモ
import React from 'react';
import ReactDOM from 'react-dom/client';
import './index.css';
import { IgrHierarchicalGridModule } from "@infragistics/igniteui-react-grids";
import { IgrHierarchicalGrid, IgrPinningConfig, ColumnPinningPosition, IgrGridToolbar, IgrGridToolbarActions, IgrGridToolbarPinning, IgrColumn, IgrRowIsland } from "@infragistics/igniteui-react-grids";
import HierarchicalCustomersData from './HierarchicalCustomersData.json';
import "@infragistics/igniteui-react-grids/grids/themes/light/bootstrap.css";
const mods: any[] = [
IgrHierarchicalGridModule
];
mods.forEach((m) => m.register());
export default class Sample extends React.Component<any, any> {
private grid: IgrHierarchicalGrid
private gridRef(r: IgrHierarchicalGrid) {
this.grid = r;
this.setState({});
}
private _pinningConfig1: IgrPinningConfig | null = null;
public get pinningConfig1(): IgrPinningConfig {
if (this._pinningConfig1 == null)
{
var pinningConfig1: IgrPinningConfig = {} as IgrPinningConfig;
pinningConfig1.columns = ColumnPinningPosition.End;
this._pinningConfig1 = pinningConfig1;
}
return this._pinningConfig1;
}
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">
<IgrHierarchicalGrid
ref={this.gridRef}
id="grid"
data={this.hierarchicalCustomersData}
columnSelection="single"
primaryKey="CustomerID"
pinning={this.pinningConfig1}>
<IgrGridToolbar
>
<IgrGridToolbarActions
>
<IgrGridToolbarPinning
>
</IgrGridToolbarPinning>
</IgrGridToolbarActions>
</IgrGridToolbar>
<IgrColumn
field="CustomerID"
hidden={true}>
</IgrColumn>
<IgrColumn
field="Company"
header="Company Name"
pinned={true}>
</IgrColumn>
<IgrColumn
field="ContactName"
header="Contact Name">
</IgrColumn>
<IgrColumn
field="ContactTitle"
header="Contact Title">
</IgrColumn>
<IgrColumn
field="Address"
header="Address">
</IgrColumn>
<IgrColumn
field="City"
header="City">
</IgrColumn>
<IgrColumn
field="PostalCode"
header="Postal Code">
</IgrColumn>
<IgrColumn
field="Country"
header="Country">
</IgrColumn>
<IgrColumn
field="Phone">
</IgrColumn>
<IgrColumn
field="Fax">
</IgrColumn>
<IgrRowIsland
childDataKey="Orders"
autoGenerate={false}>
<IgrColumn
field="OrderDate"
header="Order Date"
dataType="date"
resizable={true}>
</IgrColumn>
<IgrColumn
field="RequiredDate"
header="Required Date"
dataType="date"
resizable={true}>
</IgrColumn>
<IgrColumn
field="ShippedDate"
header="Shipped Date"
dataType="date"
resizable={true}>
</IgrColumn>
<IgrColumn
field="ShipName"
header="Ship Name"
dataType="string"
resizable={true}
pinned={true}>
</IgrColumn>
<IgrColumn
field="ShippedVia"
header="Shipped Via"
dataType="string"
resizable={true}>
</IgrColumn>
<IgrColumn
field="Freight"
header="Freight"
dataType="string"
resizable={true}>
</IgrColumn>
<IgrRowIsland
childDataKey="OrderDetails"
autoGenerate={false}>
<IgrColumn
field="UnitPrice"
header="Unit Price"
dataType="string"
resizable={true}>
</IgrColumn>
<IgrColumn
field="Quantity"
header="Quantity"
dataType="string"
resizable={true}>
</IgrColumn>
<IgrColumn
field="Discount"
header="Discount"
dataType="string"
resizable={true}>
</IgrColumn>
<IgrColumn
field="Weight"
header="Weight"
dataType="string"
resizable={true}>
</IgrColumn>
<IgrColumn
field="Length"
header="Length"
dataType="string"
resizable={true}>
</IgrColumn>
<IgrColumn
field="TotalPrice"
header="Total Price"
dataType="string"
resizable={true}>
</IgrColumn>
</IgrRowIsland>
</IgrRowIsland>
</IgrHierarchicalGrid>
</div>
</div>
);
}
private _hierarchicalCustomersData: any[] = HierarchicalCustomersData;
public get hierarchicalCustomersData(): any[] {
return this._hierarchicalCustomersData;
}
}
// rendering above component in the React DOM
const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(<Sample/>);
tsx/* shared styles are loaded from: */
/* https://static.infragistics.com/xplatform/css/samples */
css
カスタム列ピン固定 UI
カスタム UI を定義し、関連する API を介して列のピン状態を変更できます。
ツールバーの代わりに、エンドユーザーが特定の列のピンの状態を変更するためにクリックできる列ヘッダーにピンアイコンを定義するとします。
これは、カスタムアイコンを使用して列のヘッダーテンプレートを作成することで実行できます。
デモ
import React from 'react';
import ReactDOM from 'react-dom/client';
import './index.css';
import { IgrHierarchicalGridModule } from "@infragistics/igniteui-react-grids";
import { IgrHierarchicalGrid, IgrGridToolbar, IgrGridToolbarActions, IgrGridToolbarPinning, IgrColumn, IgrRowIsland } from "@infragistics/igniteui-react-grids";
import HierarchicalCustomersData from './HierarchicalCustomersData.json';
import { IgrColumnTemplateContext } from "@infragistics/igniteui-react-grids";
import "@infragistics/igniteui-react-grids/grids/themes/light/bootstrap.css";
const mods: any[] = [
IgrHierarchicalGridModule
];
mods.forEach((m) => m.register());
export default class Sample extends React.Component<any, any> {
private grid: IgrHierarchicalGrid
private gridRef(r: IgrHierarchicalGrid) {
this.grid = r;
this.setState({});
}
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">
<IgrHierarchicalGrid
ref={this.gridRef}
id="grid"
data={this.hierarchicalCustomersData}
columnSelection="single"
primaryKey="CustomerID">
<IgrGridToolbar
>
<IgrGridToolbarActions
>
<IgrGridToolbarPinning
>
</IgrGridToolbarPinning>
</IgrGridToolbarActions>
</IgrGridToolbar>
<IgrColumn
field="CustomerID"
hidden={true}>
</IgrColumn>
<IgrColumn
field="Company"
header="Company Name"
pinned={true}
headerTemplate={this.hierarchicalGridPinHeaderTemplate}>
</IgrColumn>
<IgrColumn
field="ContactName"
header="Contact Name"
headerTemplate={this.hierarchicalGridPinHeaderTemplate}>
</IgrColumn>
<IgrColumn
field="ContactTitle"
header="Contact Title"
headerTemplate={this.hierarchicalGridPinHeaderTemplate}>
</IgrColumn>
<IgrColumn
field="Address"
header="Address"
headerTemplate={this.hierarchicalGridPinHeaderTemplate}>
</IgrColumn>
<IgrColumn
field="City"
header="City"
headerTemplate={this.hierarchicalGridPinHeaderTemplate}>
</IgrColumn>
<IgrColumn
field="PostalCode"
header="Postal Code"
headerTemplate={this.hierarchicalGridPinHeaderTemplate}>
</IgrColumn>
<IgrColumn
field="Country"
header="Country"
headerTemplate={this.hierarchicalGridPinHeaderTemplate}>
</IgrColumn>
<IgrColumn
field="Phone"
headerTemplate={this.hierarchicalGridPinHeaderTemplate}>
</IgrColumn>
<IgrColumn
field="Fax"
headerTemplate={this.hierarchicalGridPinHeaderTemplate}>
</IgrColumn>
<IgrRowIsland
childDataKey="Orders"
autoGenerate={false}>
<IgrColumn
field="OrderDate"
header="Order Date"
dataType="date"
resizable={true}
headerTemplate={this.hierarchicalGridPinHeaderTemplate}>
</IgrColumn>
<IgrColumn
field="RequiredDate"
header="Required Date"
dataType="date"
resizable={true}
headerTemplate={this.hierarchicalGridPinHeaderTemplate}>
</IgrColumn>
<IgrColumn
field="ShippedDate"
header="Shipped Date"
dataType="date"
resizable={true}
headerTemplate={this.hierarchicalGridPinHeaderTemplate}>
</IgrColumn>
<IgrColumn
field="ShipName"
header="Ship Name"
dataType="string"
resizable={true}
pinned={true}
headerTemplate={this.hierarchicalGridPinHeaderTemplate}>
</IgrColumn>
<IgrColumn
field="ShippedVia"
header="Shipped Via"
dataType="string"
resizable={true}
headerTemplate={this.hierarchicalGridPinHeaderTemplate}>
</IgrColumn>
<IgrColumn
field="Freight"
header="Freight"
dataType="string"
resizable={true}
headerTemplate={this.hierarchicalGridPinHeaderTemplate}>
</IgrColumn>
<IgrRowIsland
childDataKey="OrderDetails"
autoGenerate={false}>
<IgrColumn
field="UnitPrice"
header="Unit Price"
dataType="string"
resizable={true}
headerTemplate={this.hierarchicalGridPinHeaderTemplate}>
</IgrColumn>
<IgrColumn
field="Quantity"
header="Quantity"
dataType="string"
resizable={true}
headerTemplate={this.hierarchicalGridPinHeaderTemplate}>
</IgrColumn>
<IgrColumn
field="Discount"
header="Discount"
dataType="string"
resizable={true}
headerTemplate={this.hierarchicalGridPinHeaderTemplate}>
</IgrColumn>
<IgrColumn
field="Weight"
header="Weight"
dataType="string"
resizable={true}
headerTemplate={this.hierarchicalGridPinHeaderTemplate}>
</IgrColumn>
<IgrColumn
field="Length"
header="Length"
dataType="string"
resizable={true}
headerTemplate={this.hierarchicalGridPinHeaderTemplate}>
</IgrColumn>
<IgrColumn
field="TotalPrice"
header="Total Price"
dataType="string"
resizable={true}
headerTemplate={this.hierarchicalGridPinHeaderTemplate}>
</IgrColumn>
</IgrRowIsland>
</IgrRowIsland>
</IgrHierarchicalGrid>
</div>
</div>
);
}
private _hierarchicalCustomersData: any[] = HierarchicalCustomersData;
public get hierarchicalCustomersData(): any[] {
return this._hierarchicalCustomersData;
}
public hierarchicalGridPinHeaderTemplate = (props: {dataContext: IgrColumnTemplateContext}) => {
const column = (props.dataContext as any).column;
return (
<div>
<span style={{float: 'left'}}>{column.field}</span>
<span style={{float: 'right'}} onPointerDown={(e: any) => this.toggleColumnPin(column)}>📌</span>
</div>
);
}
public toggleColumnPin(field: IgrColumn) {
if(field) {
field.pinned = !field.pinned;
}
}
}
// rendering above component in the React DOM
const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(<Sample/>);
tsx/* shared styles are loaded from: */
/* https://static.infragistics.com/xplatform/css/samples */
css
ピン固定の制限
- 列幅をパーセンテージ (%) で設定した場合にピン固定列があると
IgrHierarchicalGrid
本体およびヘッダー コンテンツが正しく配置されません。列のピン固定を正しく設定するには、列幅をピクセル (px) に設定するか、IgrHierarchicalGrid
によって自動的に割り当てる必要があります。
スタイル設定
定義済みのテーマに加えて、利用可能な CSS プロパティのいくつかを設定することで、グリッドをさらにカスタマイズできます。
一部の色を変更したい場合は、最初にグリッドの ID
を設定する必要があります。
<IgrHierarchicalGrid id="grid"></IgrHierarchicalGrid>
tsx
Then set the related CSS properties to this class:
#grid {
--ig-grid-pinned-border-width: 5px;
--ig-grid-pinned-border-color: #FFCD0F;
--ig-grid-pinned-border-style: double;
--ig-grid-cell-active-border-color: #FFCD0F;
}
css
デモ
import React from 'react';
import ReactDOM from 'react-dom/client';
import './index.css';
import { IgrHierarchicalGridModule } from "@infragistics/igniteui-react-grids";
import { IgrHierarchicalGrid, IgrGridToolbar, IgrGridToolbarActions, IgrGridToolbarPinning, IgrColumn, IgrRowIsland } from "@infragistics/igniteui-react-grids";
import HierarchicalCustomersData from './HierarchicalCustomersData.json';
import "@infragistics/igniteui-react-grids/grids/themes/light/bootstrap.css";
const mods: any[] = [
IgrHierarchicalGridModule
];
mods.forEach((m) => m.register());
export default class Sample extends React.Component<any, any> {
private grid: IgrHierarchicalGrid
private gridRef(r: IgrHierarchicalGrid) {
this.grid = r;
this.setState({});
}
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">
<IgrHierarchicalGrid
ref={this.gridRef}
id="grid"
data={this.hierarchicalCustomersData}
columnSelection="single"
primaryKey="CustomerID">
<IgrGridToolbar
>
<IgrGridToolbarActions
>
<IgrGridToolbarPinning
>
</IgrGridToolbarPinning>
</IgrGridToolbarActions>
</IgrGridToolbar>
<IgrColumn
field="CustomerID"
hidden={true}>
</IgrColumn>
<IgrColumn
field="Company"
header="Company Name"
pinned={true}>
</IgrColumn>
<IgrColumn
field="ContactName"
header="Contact Name">
</IgrColumn>
<IgrColumn
field="ContactTitle"
header="Contact Title">
</IgrColumn>
<IgrColumn
field="Address"
header="Address">
</IgrColumn>
<IgrColumn
field="City"
header="City">
</IgrColumn>
<IgrColumn
field="PostalCode"
header="Postal Code">
</IgrColumn>
<IgrColumn
field="Country"
header="Country">
</IgrColumn>
<IgrColumn
field="Phone">
</IgrColumn>
<IgrColumn
field="Fax">
</IgrColumn>
<IgrRowIsland
childDataKey="Orders"
autoGenerate={false}>
<IgrColumn
field="OrderDate"
header="Order Date"
dataType="date"
resizable={true}>
</IgrColumn>
<IgrColumn
field="RequiredDate"
header="Required Date"
dataType="date"
resizable={true}>
</IgrColumn>
<IgrColumn
field="ShippedDate"
header="Shipped Date"
dataType="date"
resizable={true}>
</IgrColumn>
<IgrColumn
field="ShipName"
header="Ship Name"
dataType="string"
resizable={true}
pinned={true}>
</IgrColumn>
<IgrColumn
field="ShippedVia"
header="Shipped Via"
dataType="string"
resizable={true}>
</IgrColumn>
<IgrColumn
field="Freight"
header="Freight"
dataType="string"
resizable={true}>
</IgrColumn>
<IgrRowIsland
childDataKey="OrderDetails"
autoGenerate={false}>
<IgrColumn
field="UnitPrice"
header="Unit Price"
dataType="string"
resizable={true}>
</IgrColumn>
<IgrColumn
field="Quantity"
header="Quantity"
dataType="string"
resizable={true}>
</IgrColumn>
<IgrColumn
field="Discount"
header="Discount"
dataType="string"
resizable={true}>
</IgrColumn>
<IgrColumn
field="Weight"
header="Weight"
dataType="string"
resizable={true}>
</IgrColumn>
<IgrColumn
field="Length"
header="Length"
dataType="string"
resizable={true}>
</IgrColumn>
<IgrColumn
field="TotalPrice"
header="Total Price"
dataType="string"
resizable={true}>
</IgrColumn>
</IgrRowIsland>
</IgrRowIsland>
</IgrHierarchicalGrid>
</div>
</div>
);
}
private _hierarchicalCustomersData: any[] = HierarchicalCustomersData;
public get hierarchicalCustomersData(): any[] {
return this._hierarchicalCustomersData;
}
}
// rendering above component in the React DOM
const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(<Sample/>);
tsx/* shared styles are loaded from: */
/* https://static.infragistics.com/xplatform/css/samples */
#grid {
--ig-grid-pinned-border-width: 5px;
--ig-grid-pinned-border-color: #FFCD0F;
--ig-grid-pinned-border-style: double;
--ig-grid-cell-active-border-color: #FFCD0F;
}
css
API リファレンス
その他のリソース
コミュニティに参加して新しいアイデアをご提案ください。