Web Components Grid 列タイプの概要

    Web Components Grid は、デフォルトおよび編集テンプレートの外観に基づいて、number (数値)、string (文字列)、date (日付)、boolean (ブール値)、currency (通貨) および percent (パーセント) 列のデータ型のデフォルト処理を提供します。

    Web Components Grid 列タイプの例

    Web Components Grid デフォルト テンプレート

    データ型固有のテンプレートを有効にする場合、列の dataType 入力を設定する必要があります。設定しない場合、列は文字列の列として処理されます (これは列 dataType のデフォルト値であるためです)。

    次に、各 dataType のデフォルト テンプレートについて説明します。

    文字列

    この列 dataType はセル値の外観または書式を変更しません。

    Number (数値)

    dataTypenumber に設定されている場合、セル値はアプリケーションまたはグリッドの locale 設定に基づいて書式設定され、pipeArgs プロパティが指定されている場合にも同じように設定されます。数値書式はそれらに基づいて変更されます。たとえば、以下を変更します:

    • 小数点後の桁数。
    • , または . の少数桁の区切り文字
    <igc-column id="column" data-type="number">
    </igc-column>
    
    private _formatOptions: any | null = null;
    public get formatOptions(): any {
        if (this._formatOptions == null)
        {
            var columnPipeArgs: any = {};
            columnPipeArgs.digitsInfo = "1.4-4";
            this._formatOptions = columnPipeArgs;
        }
        return this._formatOptions;
    }
    
    constructor() {
        var column = document.getElementById('column') as IgcColumnComponent;
        column.pipeArgs = this.formatOptions;
    }
    

    DateTime、Date and Time (日付と時刻)

    日付部分の外観は、locale の形式または pipeArgs 入力に基づいて設定されます (例: 日、月、年)。Pipe 引数はカスタム日付書式またはタイムゾーンを指定するために使用できます。

    • format - 日付の書式設定のデフォルト値は 'mediumDate' です。その他の利用可能なオプション 'short''long''shortDate''fullDate''longTime''fullTime' などです。
    • timezone - ユーザーのローカル システム タイムゾーンがデフォルト値です。タイムゾーン オフセットまたは標準の UTC/GMT または米国本土のタイムゾーンの略語も渡すことができます。世界の任意の場所の対応する時間を表示するさまざまなタイムゾーンの例:
    <igc-column id="column" data-type="date">
    </igc-column>
    
    private _formatDateOptions: any | null = null;
    public get formatDateOptions(): any {
        if (this._formatDateOptions == null)
        {
            var columnPipeArgs: any = {};
            columnPipeArgs2.format = "long";
            columnPipeArgs2.timezone = "UTC+0";
            this._formatDateOptions = columnPipeArgs;
        }
        return this._formatDateOptions;
    }
    
    constructor() {
        var column = document.getElementById('column') as IgcColumnComponent;
        column.pipeArgs = this.formatDateOptions;
    }
    

    利用可能なタイムゾーン:

    タイムゾーン
    Alpha Time Zone ‘UTC+1’
    Australian Central Time ‘UTC+9:30/ +10:30’
    Arabia Standard Time ‘UTC+3’
    Central Standard Time ‘UTC-6’
    China Standard Time ‘UTC+8’
    Delta Time Zone ‘UTC+4’
    Greenwich Mean Time ‘UTC+0’
    Gulf Standard Time ‘UTC+4’
    Hawaii Standard Time ‘UTC-10’
    India Standard Time ‘UTC+4’

    IgcGridComponent は、Date オブジェクト数値 (ミリ秒) または ISO 日付/時刻文字列の日付値を受け取ります。このセクションは、カスタム表示書式を構成する方法を示します。

    サンプルでは、特定の列タイプで使用可能な書式を紹介するために、さまざまな書式設定オプションを指定しています。たとえば、以下は日付オブジェクトの time 部分の書式設定オプションのサンプルです。

    // Time format with equivalent example
    public timeFormats = [
        { format: 'shortTime', eq: 'h:mm a' },
        { format: 'mediumTime', eq: 'h:mm:ss a' },
        { format: 'longTime', eq: 'h:mm:ss a z' },
        { format: 'fullTime', eq: 'h:mm:ss a zzzz' },
    ];
    

    セルの編集

    列タイプに基づくセル編集に関しては、別のエディターが表示されます。

    • DateTime - DateTimeEditor が使用されます。このエディターは、DateTime オブジェクトの入力要素部分のマスクを提供します。
    • Date - IgcDatePickerComponent が使用されます。
    • Time - TimePicker が使用されます。

    フィルタリング

    クイック フィルタリング/Excel スタイル フィルタリングに関しては、上記と同じエディターが使用されます。これらは、各タイプが公開する次のフィルタリング オペランドです。

    • DateTime および Date - Equals、Does Not Equal、Before、After、Today、Yesterday、This Month、Last Month、Next Month、This Year、Last Year、Next Year、Empty、Not Empty、Null、Not Null;
    • Time - At、Not At、Before、After、At or Before、At or After、Empty、Not Empty、Null、Not Null;

    集計

    使用可能な集計オペランドは、CountEarliest (date/time)、および Latest (date/time) になります。

    ソート

    • Time: タイプの列は、オブジェクトの時間部分に基づいてソートされます。分/秒は無視されます。
    • Date: タイプの列は、日付部分に基づいてソートされ、時間部分は無視されます。
    • DateTime: タイプの列は、日付に基づいてソートされます。

    Boolean

    デフォルトのテンプレートは、ブール値の可視化にマテリアル アイコンを使用します。false 値には 'clear' アイコン、true 値には 'check' アイコンを使用します。編集テンプレートは IgcCheckboxComponent コンポーネントを使用しています。

    <igc-column data-type="boolean">
    </igc-column>
    

    画像

    デフォルトのテンプレートは、デフォルの画像テンプレートへの画像ソースとしてデータからの値を使用しています。デフォルトの画像テンプレートは、画像ファイルの名前を抽出し、アクセシビリティ要件を満たすために画像の alt 属性として設定します。表示されるセル サイズは描画される画像のサイズに合わせて調整されるため、大きな画像も描画され、グリッド行は画像列の画像と同じ大きさになることに注意してください。画像タイプの列では、フィルタリング、ソート、およびグループ化はデフォルトでオフになっています。それらを有効にしたい場合は、データ操作を実行するカスタム ストラテジを提供する必要があります。

    <igc-column field="Image" data-type="image">
    </igc-column>
    

    列に autoGenerate を使用すると、グリッドは最初のデータ レコードの値を分析します。値が文字列型で、画像拡張子 (gif、jpg、jpeg、tiff、png、webp、bmp) で終わる URL のパターンと一致する場合、列は自動的に dataType === GridColumnDataType.Image としてマークされ、デフォルトの画像テンプレートが描画されます。

    通貨

    デフォルトのテンプレート

    デフォルトのテンプレートには、接頭辞または接尾辞が付いた通貨記号を含む数値を表示します。

    <igc-column id="column" field="UnitsInStock" data-type="currency">
    </igc-column>
    
    private _formatOptions: any | null = null;
        public get formatOptions(): any {
            if (this._formatOptions == null)
            {
                var columnPipeArgs: any = {};
                columnPipeArgs.digitsInfo = "1.4-4";
                columnPipeArgs.display = "symbol-narrow";
                this._formatOptions = columnPipeArgs;
            }
            return this._formatOptions;
        }
    
    constructor() {
        var column = document.getElementById('column') as IgcColumnComponent;
        column.pipeArgs = this.formatOptions;
    }
    
    パラメーター 説明
    digitsInfo 通貨値の 10 進数表現を表します。
    display* 狭義または広義の記号で値を表示します。

    *display - デフォルトの en-US ロケールの場合、USD コードは省略記号 $ または記号 US$ で表すことができます。

    セルの値を編集すると、通貨記号がサフィックスまたはプレフィックスとして表示されます。詳細については、公式のセル編集トピックを参照してください。

    注: 上/下矢印キーを使用する場合、値は digitsInfo - minFractionDigits (小数点以下の最小桁数。デフォルトは 0 です。) に基づいてステップで増減します。

    Percent (パーセント)

    デフォルトのテンプレートは、基になる数値に相当するパーセントを表示します。表示されるセル値は、'100' の表示ファクタで乗算された結果です。たとえば、デフォルトのファクタは 100 で、セルに渡される値は 0.123 であるため、表示されるセル値は 12.3% になります。

    セル編集の場合、値はデータ ソース値と同じになります。表示ファクタは '1' です。セルを編集すると、パーセント値のプレビューがサフィックス要素として表示されます。たとえば、'0.0547' の編集中にプレビュー要素に '5.47%' が表示されます。

    <igc-column id="column" field="UnitsInStock" data-type="percent">
    </igc-column>
    
    private _formatPercentOptions: any | null = null;
        public get formatPercentOptions(): any {
            if (this._formatPercentOptions == null)
            {
                var columnPipeArgs: any = {};
                columnPipeArgs.digitsInfo = "2.2-3";
                this._formatPercentOptions = columnPipeArgs;
            }
            return this._formatPercentOptions;
        }
    
    constructor() {
        var column = document.getElementById('column') as IgcColumnComponent;
        column.pipeArgs = this.formatPercentOptions;
    }
    

    [!Note] 上/下矢印キーを使用する場合、値は digitsInfo - minFractionDigits (小数点以下の最小桁数。デフォルトは 0 です。) に基づいてステップで増減します。

    デフォルトの編集テンプレート

    Grid 編集トピックの編集テンプレート部分を参照してください。

    カスタム編集テンプレートとフォーマッタ

    カスタム テンプレートと列フォーマッタの定義は、列データ型セットより常に優先されます。

    カスタム テンプレート

    <igc-grid id="grid1" auto-generate="false">
        <igc-column id="UnitsInStock" field="UnitsInStock" data-type="currency" editable="true">
        </igc-column>
    </igc-grid>
    
    constructor() {
        var unitsInStock = document.getElementById('UnitsInStock') as IgcColumnComponent;
        unitsInStock.inlineEditorTemplate = this.editCellTemplate;
    }
    
    public editCellTemplate = (ctx: IgcCellTemplateContext) => {
        return html`<input></input>`;
    }
    

    列の書式設定

    <igc-grid id="grid1" auto-generate="false">
        <igc-column id="UnitsInStock" field="UnitsInStock" data-type="currency">
        </igc-column>
    </igc-grid>
    
    constructor() {
        var unitsInStock = this.unitsInStock = document.getElementById('UnitsInStock') as IgcColumnComponent;
        unitsInStock.formatter = this.formatCurrency;
    }
    
    public formatCurrency(value: number) {
        return `$ ${value.toFixed(0)}`;
    }
    

    API リファレンス

    その他のリソース

    カスタム テンプレートについては、セル編集トピックを参照してください。