React Hierarchical Grid の列非表示
Ignite UI for React には組み込み列非表示 UI があり、これを React Hierarchical Grid のツールバーから使用して列の表示状態を変更できます。開発者は、必要に応じてページ内の任意の場所に列非表示 UI を柔軟に定義できます。React Hierarchical Grid 列の非表示機能は、グリッドのサイズを小さくし、冗長なフィールドをタブで移動する必要をなくしたい場合に特に便利です。
React Hierarchical Grid 列非表示の例
import React from 'react';
import ReactDOM from 'react-dom/client';
import './index.css';
import { IgrGridToolbarModule, IgrHierarchicalGridModule } from "@infragistics/igniteui-react-grids";
import { IgrHierarchicalGrid, IgrGridToolbar, IgrGridToolbarActions, IgrGridToolbarHiding, IgrColumn, IgrRowIsland } from "@infragistics/igniteui-react-grids";
import SingersData from './SingersData.json';
import "@infragistics/igniteui-react-grids/grids/combined";
import "@infragistics/igniteui-react-grids/grids/themes/light/bootstrap.css";
const mods: any[] = [
IgrGridToolbarModule,
IgrHierarchicalGridModule
];
mods.forEach((m) => m.register());
export default class Sample extends React.Component<any, any> {
private hierarchicalGrid1: IgrHierarchicalGrid
private hierarchicalGrid1Ref(r: IgrHierarchicalGrid) {
this.hierarchicalGrid1 = r;
this.setState({});
}
constructor(props: any) {
super(props);
this.hierarchicalGrid1Ref = this.hierarchicalGrid1Ref.bind(this);
}
public render(): JSX.Element {
return (
<div className="container sample ig-typography">
<div className="container fill">
<IgrHierarchicalGrid
autoGenerate={false}
data={this.singersData}
primaryKey="ID"
allowFiltering={true}
ref={this.hierarchicalGrid1Ref}>
<IgrGridToolbar
>
<IgrGridToolbarActions
>
<IgrGridToolbarHiding
title="Column Hiding">
</IgrGridToolbarHiding>
</IgrGridToolbarActions>
</IgrGridToolbar>
<IgrColumn
field="Artist"
header="Artist"
dataType="string"
sortable={true}>
</IgrColumn>
<IgrColumn
field="Photo"
header="Photo"
dataType="image">
</IgrColumn>
<IgrColumn
field="Debut"
header="Debut"
dataType="number"
hidden={true}>
</IgrColumn>
<IgrColumn
field="GrammyNominations"
header="Grammy Nominations"
dataType="number"
sortable={true}
hidden={true}>
</IgrColumn>
<IgrColumn
field="GrammyAwards"
header="Grammy Awards"
dataType="number"
sortable={true}>
</IgrColumn>
<IgrRowIsland
childDataKey="Albums"
autoGenerate={false}>
<IgrColumn
field="Album"
header="Album"
dataType="string"
sortable={true}>
</IgrColumn>
<IgrColumn
field="LaunchDate"
header="Launch Date"
dataType="date"
sortable={true}>
</IgrColumn>
<IgrColumn
field="BillboardReview"
header="Billboard Review"
dataType="string"
sortable={true}>
</IgrColumn>
<IgrColumn
field="USBillboard200"
header="US Billboard 200"
dataType="string"
sortable={true}>
</IgrColumn>
<IgrRowIsland
childDataKey="Songs"
autoGenerate={false}>
<IgrColumn
field="Number"
header="No."
dataType="string">
</IgrColumn>
<IgrColumn
field="Title"
header="Title"
dataType="string">
</IgrColumn>
<IgrColumn
field="Released"
header="Released"
dataType="date">
</IgrColumn>
<IgrColumn
field="Genre"
header="Genre"
dataType="string">
</IgrColumn>
</IgrRowIsland>
</IgrRowIsland>
<IgrRowIsland
childDataKey="Tours"
autoGenerate={false}>
<IgrColumn
field="Tour"
header="Tour"
dataType="string">
</IgrColumn>
<IgrColumn
field="StartedOn"
header="Started on"
dataType="string">
</IgrColumn>
<IgrColumn
field="Location"
header="Location"
dataType="string">
</IgrColumn>
<IgrColumn
field="Headliner"
header="Headliner"
dataType="string">
</IgrColumn>
</IgrRowIsland>
</IgrHierarchicalGrid>
</div>
</div>
);
}
private _singersData: any[] = SingersData;
public get singersData(): any[] {
return this._singersData;
}
}
const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(<Sample/>);
tsx
このサンプルが気に入りましたか? 完全な Ignite UI for Reactツールキットにアクセスして、すばやく独自のアプリの作成を開始します。無料でダウンロードできます。
Hierarchical Grid のセットアップ
IgrHierarchicalGrid
を作成してからデータをバインドします。列でフィルタリングとソートも有効にします。
<IgrHierarchicalGrid autoGenerate="false" data={this.singersData} primaryKey="ID" allowFiltering="true"ref={this.hierarchicalGrid1Ref}>
<IgrColumn field="Artist" header="Artist" dataType="String" sortable="true"></IgrColumn>
<IgrColumn field="Photo" header="Photo" dataType="Image"></IgrColumn>
<IgrColumn field="Debut" header="Debut" dataType="Number" hidden="true"></IgrColumn>
<IgrColumn field="GrammyNominations" header="Grammy Nominations" dataType="Number" sortable="true" hidden="true"></IgrColumn>
<IgrColumn field="GrammyAwards" header="Grammy Awards" dataType="Number" sortable="true"></IgrColumn>
</IgrHierarchicalGrid>
tsx
ツールバーの列非表示 UI
定義済みの列非表示 UI は、IgrHierarchicalGrid
のツールバーの DropDown
内に配置されます。列非表示の UI をこのドロップダウンを使用して表示/非表示にできます。
これには、IgrHierarchicalGrid
内に IgrGridToolbarActions
と IgrGridToolbarHiding
の両方を設定することだけです。ツールバーにタイトルを追加するには、IgrGridToolbarTitle
を設定し、Hierarchical Grid のラッパーにカスタム スタイルを設定します。
<IgrHierarchicalGrid data={this.singersData}>
<IgrGridToolbar>
<IgrGridToolbarActions>
<IgrGridToolbarHiding></IgrGridToolbarHiding>
</IgrGridToolbarActions>
</IgrGridToolbar>
</IgrHierarchicalGrid>
tsx
IgrHierarchicalGrid
にはツールバーの列非表示 UI に便利なプロパティがあります。
title
プロパティを使用して、ツールバーのドロップダウン ボタンに表示されるタイトルを設定します。
<IgrHierarchicalGrid>
<IgrGridToolbar key="toolbar">
<IgrGridToolbarActions key="toolbarActions">
<IgrGridToolbarHiding key="toolbarHiding" title="Column Hiding"></IgrGridToolbarHiding>
</IgrGridToolbarActions>
</IgrGridToolbar>
</IgrHierarchicalGrid>
tsx
このトピックのはじめにあるコードの結果は React 列非表示の例のセクションで確認できます。
列の非表示の無効化
列の disableHiding
プロパティを true に設定すると、ユーザーが列非表示 UI によって列を非表示にできません。
<IgrHierarchicalGrid>
<IgrColumn field="Artist" dataType="string" sortable="true" disableHiding="true"></IgrColumn>
<IgrColumn field="GrammyAwards" dataType="string" sortable="true" disableHiding="true"></IgrColumn>
<IgrRowIsland>
<IgrColumn field="Album" dataType="string" sortable="true" disableHiding="true"></IgrColumn>
</IgrRowIsland>
</IgrHierarchicalGrid>
tsx
スタイル設定
グリッドは、利用可能な CSS 変数の一部を設定することでさらにカスタマイズできます。
これを実現するために、最初にグリッドに割り当てるクラスを使用します。
<IgrHierarchicalGrid className="hierarchical-grid"></IgrHierarchicalGrid>
tsx
次に、関連するコンポーネントに関連する CSS 変数を設定します。スタイルも igx-column-actions
にのみ適用するので、グリッドの残りの部分は影響を受けません。
#hierarchicalGrid {
--ig-column-actions-background-color: #292826;
--ig-column-actions-title-color: #ffcd0f;
--ig-checkbox-tick-color: #292826;
--ig-checkbox-label-color: #ffcd0f;
--ig-checkbox-empty-color: #ffcd0f;
--ig-checkbox-fill-color: #ffcd0f;
--ig-input-group-idle-text-color: white;
--ig-input-group-filled-text-color: #ffcd0f;
--ig-input-group-focused-text-color: #ffcd0f;
--ig-input-group-focused-border-color: #ffcd0f;
--ig-input-group-focused-secondary-color: #ffcd0f;
--ig-button-foreground: #292826;
--ig-button-background: #ffcd0f;
--ig-button-hover-background: #404040;
--ig-button-hover-foreground: #ffcd0f;
--ig-button-focus-background: #ffcd0f;
--ig-button-focus-foreground: black;
--ig-button-focus-visible-background: #ffcd0f;
--ig-button-focus-visible-foreground: black;
--ig-button-disabled-foreground: #ffcd0f;
}
css
デモ
import React from 'react';
import ReactDOM from 'react-dom/client';
import './index.css';
import { IgrGridToolbarModule, IgrHierarchicalGridModule } from "@infragistics/igniteui-react-grids";
import { IgrHierarchicalGrid, IgrGridToolbar, IgrGridToolbarActions, IgrGridToolbarHiding, IgrColumn, IgrRowIsland } from "@infragistics/igniteui-react-grids";
import SingersData from './SingersData.json';
import "@infragistics/igniteui-react-grids/grids/combined";
import "@infragistics/igniteui-react-grids/grids/themes/light/bootstrap.css";
const mods: any[] = [
IgrGridToolbarModule,
IgrHierarchicalGridModule
];
mods.forEach((m) => m.register());
export default class Sample extends React.Component<any, any> {
private hierarchicalGrid: IgrHierarchicalGrid
private hierarchicalGridRef(r: IgrHierarchicalGrid) {
this.hierarchicalGrid = r;
this.setState({});
}
constructor(props: any) {
super(props);
this.hierarchicalGridRef = this.hierarchicalGridRef.bind(this);
}
public render(): JSX.Element {
return (
<div className="container sample ig-typography">
<div className="container fill">
<IgrHierarchicalGrid
autoGenerate={false}
data={this.singersData}
id="hierarchicalGrid"
ref={this.hierarchicalGridRef}
primaryKey="ID"
allowFiltering={true}>
<IgrGridToolbar
>
<IgrGridToolbarActions
>
<IgrGridToolbarHiding
title="Column Hiding">
</IgrGridToolbarHiding>
</IgrGridToolbarActions>
</IgrGridToolbar>
<IgrColumn
field="Artist"
header="Artist"
dataType="string"
sortable={true}>
</IgrColumn>
<IgrColumn
field="Photo"
header="Photo"
dataType="image">
</IgrColumn>
<IgrColumn
field="Debut"
header="Debut"
dataType="number"
sortable={true}>
</IgrColumn>
<IgrColumn
field="GrammyNominations"
header="Grammy Nominations"
dataType="number"
sortable={true}>
</IgrColumn>
<IgrColumn
field="GrammyAwards"
header="Grammy Awards"
dataType="number"
sortable={true}>
</IgrColumn>
<IgrRowIsland
childDataKey="Albums"
autoGenerate={false}>
<IgrColumn
field="Album"
header="Album"
dataType="string"
sortable={true}>
</IgrColumn>
<IgrColumn
field="LaunchDate"
header="Launch Date"
dataType="date"
sortable={true}>
</IgrColumn>
<IgrColumn
field="BillboardReview"
header="Billboard Review"
dataType="string"
sortable={true}>
</IgrColumn>
<IgrColumn
field="USBillboard200"
header="US Billboard 200"
dataType="string"
sortable={true}>
</IgrColumn>
<IgrRowIsland
childDataKey="Songs"
autoGenerate={false}>
<IgrColumn
field="Number"
header="No."
dataType="string">
</IgrColumn>
<IgrColumn
field="Title"
header="Title"
dataType="string">
</IgrColumn>
<IgrColumn
field="Released"
header="Released"
dataType="date">
</IgrColumn>
<IgrColumn
field="Genre"
header="Genre"
dataType="string">
</IgrColumn>
</IgrRowIsland>
</IgrRowIsland>
<IgrRowIsland
childDataKey="Tours"
autoGenerate={false}>
<IgrColumn
field="Tour"
header="Tour"
dataType="string">
</IgrColumn>
<IgrColumn
field="StartedOn"
header="Started on"
dataType="string">
</IgrColumn>
<IgrColumn
field="Location"
header="Location"
dataType="string">
</IgrColumn>
<IgrColumn
field="Headliner"
header="Headliner"
dataType="string">
</IgrColumn>
</IgrRowIsland>
</IgrHierarchicalGrid>
</div>
</div>
);
}
private _singersData: any[] = SingersData;
public get singersData(): any[] {
return this._singersData;
}
}
const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(<Sample/>);
tsx
#hierarchicalGrid {
--ig-column-actions-background-color: #292826;
--ig-column-actions-title-color: #ffcd0f;
--ig-checkbox-tick-color: #292826;
--ig-checkbox-label-color: #ffcd0f;
--ig-checkbox-empty-color: #ffcd0f;
--ig-checkbox-fill-color: #ffcd0f;
--ig-input-group-idle-text-color: white;
--ig-input-group-filled-text-color: #ffcd0f;
--ig-input-group-focused-text-color: #ffcd0f;
--ig-input-group-focused-border-color: #ffcd0f;
--ig-input-group-focused-secondary-color: #ffcd0f;
--ig-button-foreground: #292826;
--ig-button-background: #ffcd0f;
--ig-button-hover-background: #404040;
--ig-button-hover-foreground: #ffcd0f;
--ig-button-focus-background: #ffcd0f;
--ig-button-focus-foreground: black;
--ig-button-focus-visible-background: #ffcd0f;
--ig-button-focus-visible-foreground: black;
--ig-button-disabled-foreground: #ffcd0f;
}
css
API リファレンス
このトピックでは、IgrHierarchicalGrid
のツールバーの定義済みの列非表示 UI の使用方法について学びました。以下は、列非表示 UI のその他の API です。
その他のコンポーネント (またはそのいずれか) で使用した API:
IgrColumn
プロパティ:
IgrGridToolbar
プロパティ:
IgrGridToolbar
メソッド:
IgrHierarchicalGrid
イベント:
その他のリソース
コミュニティに参加して新しいアイデアをご提案ください。