Close
Angular React Web Components Blazor
Premium

React Grid 列ピン固定

React Grid の Ignite UI for React 列のピン固定機能を使用すると、開発者は特定の列を希望の順序でロックできるため、ユーザーが IgrGrid を水平方向にスクロールしている場合でも、常に可視性を確保できます。 列ピン固定用の統合 UI があり、React Grid ツールバーからアクセスできます。さらに、開発者は、列のピン状態を変更するカスタム ユーザー インターフェイスを柔軟に構築できます。

React Grid 列ピン固定の例

以下の例は、1 つまたは複数の列を IgrGrid の左側または右側にピン固定する方法を示しています。

列ピン固定の API

列のピン固定は IgrColumn.pinnedPinned プロパティによって制御されます。デフォルトでピン固定列は IgrGrid の左側に固定して描画され、IgrGrid 本体のピン固定されていない列は水平スクロールされます。

<IgrGrid data={nwindData} autoGenerate={false}>
    <IgrColumn field="Name" pinned={true}></IgrColumn>
    <IgrColumn field="AthleteNumber"></IgrColumn>
    <IgrColumn field="TrackProgress"></IgrColumn>
</IgrGrid>

IgrGrid.pinColumnPinColumn または UnpinColumn メソッドを使用してフィールド名によって列をピン固定またはピン固定解除できます。

gridRef.current.pinColumn('AthleteNumber');
gridRef.current.unpinColumn('Name');

両方のメソッドは操作に成功したかどうかを示すブール値を返します。よくある失敗の原因に列がすでにその状態になっていることがあります。

列をピン固定すると、一番右に配置されたピン固定列の右にピン固定されます。ピン固定列の順序を変更するには、ColumnPin イベントでイベント引数の InsertAtIndex プロパティを適切な位置インデックスに変更します。

<IgrGrid data={nwindData} autoGenerate={false}>
    <IgrColumn field="Name" pinned={true}></IgrColumn>
    <IgrColumn field="AthleteNumber"></IgrColumn>
    <IgrColumn field="TrackProgress"></IgrColumn>
</IgrGrid>

ピン固定の位置

Pinning 設定オプションを使用して、列のピン固定の位置を変更できます。列の位置を [Start] または [End] のいずれかに設定できます。 [End] に設定すると、列がピン固定されていない列の後に、グリッドの最後にレンダリングされます。ピン固定されていない列は水平にスクロールできますが、ピン固定された列は右側に固定されます。

const pinningConfig: IgrPinningConfig = { columns: ColumnPinningPosition.End };
<IgrGrid data={nwindData} autoGenerate={true} pinning={pinningConfig}></IgrGrid>

デモ

両側の列のピン固定

各列のピン固定位置を個別に指定できるため、グリッドの両側に列をピン固定して利便性を高め、データ セットの最適化を容易にすることができます。詳細については、以下のデモを参照してください。列をピン固定するには、ヘッダーをクリックして列を選択し、ツールバーに追加されたピン固定ボタンを使用するか、列を別のピン固定された列にドラッグします。

デモ

You can define your custom UI and change the pin state of the columns via the related API.

Let’s say that instead of a toolbar you would like to define pin icons in the column headers that the end user can click to change the particular column’s pin state.

This can be done by creating a header template for the columns with a custom icon.

<IgrGrid autoGenerate={false} data= ref={grid}>
    <IgrColumn field="ID" hidden={true}></IgrColumn>

    <IgrColumn field="CompanyName" header="Company" width="300px"
    headerTemplate={toggleColumnPin}></IgrColumn>

    <IgrColumn field="ContactName" header="Name" width="200px" pinned={true}
    headerTemplate={toggleColumnPin}> </IgrColumn>

    <IgrColumn field="ContactTitle" header="Title" width="200px" pinned={true}
    headerTemplate={toggleColumnPin}></IgrColumn>
</IgrGrid>
const toggleColumnPin = (ctx: IgrColumnTemplateContext) => {
  const togglePin = () => {
    const col = ctx.column;
    col.pinned = !col.pinned;
  }

  const col = ctx.column;

  return(
    <div>
      <span style={{ float: 'left' }}>{col.header}</span>
      <span style={{ float: 'right' }} onClick={() => togglePin()}>📌</span>
    </div>
  );
}

On click of the custom icon the pin state of the related column can be changed using the column’s API methods.

カスタム列ピン固定 UI

デモ

  • Setting column widths in percentage (%) explicitly makes the IgrGrid body and header content to be misaligned when there are pinned columns. For column pinning to function correctly the column widths should be in pixels (px) or auto-assigned by the IgrGrid.

ピン固定の制限

  • 列幅をパーセンテージ (%) で設定した場合にピン固定列があると IgrGrid 本体およびヘッダー コンテンツが正しく配置されません。列のピン固定を正しく設定するには、列幅をピクセル (px) に設定するか、IgrGrid によって自動的に割り当てる必要があります。
<IgrGrid id="grid"></IgrGrid>

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;
}

スタイル設定

API リファレンス

IgrGrid
IgrColumn

カスタム テーマの定義

次に、grid-theme を拡張し、必要に応じてピン固定をカスタマイズするために必要なパラメーターを受け入れる新しいテーマを作成します。

Our community is active and always welcoming to new ideas.