Web Components 그리드 열 고정

    The Ignite UI for Web Components Column Pinning feature in Web Components Grid enables developers to lock specific columns in a desired order, ensuring visibility all the time even when users scroll horizontally through the IgcGridComponent. There’s an integrated UI for Column Pinning, accessible via the Web Components Grid toolbar. Additionally, developers have the flexibility to build a custom user interface which changes the pin state of the columns.

    Web Components Grid Column Pinning Example

    This example demonstrates how you can pin a column or multiple columns to the left or right side of the IgcGridComponent.

    Column Pinning API

    Column pinning is controlled through the pinned property of the IgcColumnComponent. Pinned columns are rendered on the left side of the IgcGridComponent by default and stay fixed through horizontal scrolling of the unpinned columns in the IgcGridComponent body.

    <igc-grid id="grid1" width="700px" auto-generate="false">
        <igc-column field="Name" pinned="true"></igc-column>
        <igc-column field="AthleteNumber"></igc-column>
        <igc-column field="TrackProgress"></igc-column>
        <igc-paginator per-page="10">
        </igc-paginator>
    </igc-grid>
    
    constructor() {
        var grid = this.grid = document.getElementById('grid') as IgcGridComponent;
        grid.data = this.data;
    }
    

    You may also use the IgcGridComponent's pinColumn or unpinColumn methods of the IgcGridComponent to pin or unpin columns by their field name:

    this.grid.pinColumn('AthleteNumber');
    this.grid.unpinColumn('Name');
    

    두 메서드 모두 해당 작업의 성공 여부를 나타내는 부울 값을 반환합니다. 일반적으로 실패하는 이유는 열이 이미 원하는 상태에 있기 때문입니다.

    A column is pinned to the right of the rightmost pinned column. Changing the order of the pinned columns can be done by subscribing to the ColumnPin event and changing the InsertAtIndex property of the event arguments to the desired position index.

    <igc-grid id="dataGrid" auto-generate="true"></igc-grid>
    
    constructor() {
        var dataGrid = document.getElementById('dataGrid') as IgcGridComponent;
        dataGrid.data = this.data;
        dataGrid.addEventListener("columnPin", this.columnPinning);
    }
    
    public columnPinning(event) {
        if (event.detail.column.field === 'Name') {
            event.detail.insertAtIndex = 0;
        }
    }
    

    Pinning Position

    You can change the column pinning position via the pinning configuration option. It allows you to set the columns position to either Start or End. When set to End the columns are rendered at the end of the grid, after the unpinned columns. Unpinned columns can be scrolled horizontally, while the pinned columns remain fixed on the right.

    <igc-grid id="dataGrid" auto-generate="true"></igc-grid>
    
    var grid = document.getElementById('dataGrid') as IgcGridComponent;
    grid.pinning = { columns: ColumnPinningPosition.End };
    

    Demo

    Custom Column Pinning UI

    관련 API를 통해 사용자 정의 UI를 정의하고 열의 핀 상태를 변경할 수 있습니다.

    도구 모음 대신 최종 사용자가 클릭하여 특정 열의 핀 상태를 변경할 수 있는 열 헤더에 핀 아이콘을 정의한다고 가정해 보겠습니다.

    이는 사용자 정의 아이콘이 있는 열의 헤더 템플릿을 생성하여 수행할 수 있습니다.

    <igc-grid id="grid1" width="100%" height="500px" auto-generate="false">
        <igc-column id="Name" field="Name" data-type="String" width="250px"></igc-column>
        <igc-column id="Title" field="Title" data-type="String" width="300px"></igc-column>
        <igc-column id="ID" field="ID" data-type="Number" width="200px"></igc-column>
        <igc-column id="HireDate" field="HireDate" header="Hire Date" data-type="Date" width="200px"></igc-column>
        <igc-column id="Age" field="Age" data-type="Number" width="200px"></igc-column>
        <igc-column id="Address" field="Address" data-type="String" width="200px"></igc-column>
        <igc-column id="City" field="City" data-type="String" width="200px"></igc-column>
        <igc-column id="Country" field="Country" data-type="String" width="200px"></igc-column>
        <igc-column id="Fax" field="Fax" data-type="String" width="200px"></igc-column>
        <igc-column id="PostalCode" field="PostalCode" header="Postal Code" data-type="String" width="200px"></igc-column>
        <igc-column id="Phone" field="Phone" data-type="String" width="200px"></igc-column>
    </igc-grid>
    
    constructor() {
        var grid1 = document.getElementById('grid1') as IgcGridComponent;
        var Name = document.getElementById('Name') as IgcColumnComponent;
        var Title = document.getElementById('Title') as IgcColumnComponent;
        var ID = document.getElementById('ID') as IgcColumnComponent;
        var HireDate = document.getElementById('HireDate') as IgcColumnComponent;
        var Age = document.getElementById('Age') as IgcColumnComponent;
        var Address = document.getElementById('Address') as IgcColumnComponent;
        var City = document.getElementById('City') as IgcColumnComponent;
        var Country = document.getElementById('Country') as IgcColumnComponent;
        var Fax = document.getElementById('Fax') as IgcColumnComponent;
        var PostalCode = document.getElementById('PostalCode') as IgcColumnComponent;
        var Phone = document.getElementById('Phone') as IgcColumnComponent;
    
        grid.data = this.data;
        Name.headerTemplate = this.pinHeaderTemplate;
        Title.headerTemplate = this.pinHeaderTemplate;
        ID.headerTemplate = this.pinHeaderTemplate;
        HireDate.headerTemplate = this.pinHeaderTemplate;
        Age.headerTemplate = this.pinHeaderTemplate;
        Address.headerTemplate = this.pinHeaderTemplate;
        City.headerTemplate = this.pinHeaderTemplate;
        Country.headerTemplate = this.pinHeaderTemplate;
        Fax.headerTemplate = this.pinHeaderTemplate;
        PostalCode.headerTemplate = this.pinHeaderTemplate;
        Phone.headerTemplate = this.pinHeaderTemplate;
    }
    
    public pinHeaderTemplate = (ctx: IgcCellTemplateContext) => {
        return html`
            <div class="title-inner">
                <span style="float:left">${ctx.cell.column.header}</span>
                <igc-icon class="pin-icon" fontSet="fas" name="fa-thumbtack" @click="${() => toggleColumn(ctx.cell.column)}"></igx-icon>
            </div>
        `;
    }
    

    사용자 정의 아이콘을 클릭하면 해당 열의 API 메소드를 사용하여 관련 열의 고정 상태를 변경할 수 있습니다.

    public toggleColumn(col: IgcColumnComponent) {
        col.pinned ? col.unpin() : col.pin();
    }
    

    Demo

    Pinning Limitations

    • Setting column widths in percentage (%) explicitly makes the IgcGridComponent 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 IgcGridComponent.

    Styling

    In addition to the predefined themes, the grid could be further customized by setting some of the available CSS properties. In case you would like to change some of the colors, you need to set an ID for the grid first:

    <igc-grid id="grid"></igc-grid>
    

    그런 다음 관련 CSS 속성을 이 클래스로 설정합니다.

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

    Demo

    API References

    Additional Resources

    우리 커뮤니티는 활동적이며 항상 새로운 아이디어를 환영합니다.