Angular Tree Grid Column Pinning

    열 또는 여러 열을 Angular UI Grid의 왼쪽 또는 오른쪽에 고정할 수 있습니다. Ignite UI for Angular의 열 고정을 사용하면 최종 사용자가 특정 열 순서로 열을 잠글 수 있으므로 Tree Grid를 수평으로 스크롤하는 동안 해당 열을 볼 수 있습니다. Material UI Grid에는 내장된 열 고정 UI가 있어 Tree Grid의 도구 모음을 통해 열의 고정 상태를 변경할 수 있습니다. 또한 사용자 지정 UI를 정의하고 Column Pinning API를 통해 열의 고정 상태를 변경할 수 있습니다.

    Angular Tree Grid Column Pinning Example

    Column Pinning API

    Column pinning is controlled through the pinned input of the igx-column. Pinned columns are rendered on the left side of the Tree Grid by default and stay fixed through horizontal scrolling of the unpinned columns in the Tree Grid body.

    <igx-tree-grid #treeGrid [data]="data" primaryKey="ID" foreignKey="ParentID" [autoGenerate]="false">
        <igx-column [field]="Name" [pinned]="true"></igx-column>
        <igx-column [field]="Title"></igx-column>
        <igx-column [field]="ID"></igx-column>
    </igx-tree-grid>
    

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

    this.treeGrid.pinColumn('Title');
    this.treeGrid.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.

    <igx-tree-grid #treeGrid [data]="data" primaryKey="ID" foreignKey="ParentID" [autoGenerate]="true" (columnPin)="columnPinning($event)"></igx-tree-grid>
    
    public columnPinning(event) {
        if (event.column.field === 'Name') {
            event.insertAtIndex = 0;
        }
    }
    

    Pinning Position

    구성 옵션을 통해pinning 열의 고정 위치를 변경할 수 있습니다. 열의 위치를 시작 또는 끝으로 설정할 수 있습니다. End로 설정하면 열은 고정되지 않은 열들 다음, 그리드 끝에 렌더링됩니다. 고정되지 않은 열은 가로로 스크롤할 수 있고, 고정된 열은 오른쪽에 고정되어 있습니다.

    <igx-tree-grid #grid1 [data]="data" [autoGenerate]="true" [pinning]="pinningConfig"></igx-tree-grid>
    
    public pinningConfig: IPinningConfig = { columns: ColumnPinningPosition.End };
    

    Demo

    또한 각 열 고정 위치를 별도로 지정할 수 있으므로 데이터 세트의 편의성과 최적화를 위해 그리드의 양쪽에 열을 고정할 수 있습니다. 자세한 내용은 아래 데모를 참조하십시오. 열을 고정하려면 머리글을 클릭하여 열을 선택하고 도구 모음에 추가된 고정 버튼을 사용하거나 열을 고정된 다른 열로 드래그하십시오.

    Custom Column Pinning UI

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

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

    <ng-template igxHeader let-column #pinTemplate>
        <div class="title-inner">
            <span style="float:left">{{column.header || column.field}}</span>
            <igx-icon class="pin-icon" [class.pinned]="column.pinned" [class.unpinned]="!column.pinned" fontSet="fas" name="fa-thumbtack"
                (click)="toggleColumn(column)"></igx-icon>
        </div>
    </ng-template>
    <div class="grid__wrapper">
        <igx-tree-grid #treeGrid [data]="data" primaryKey="ID" foreignKey="ParentID" [autoGenerate]="false" height="620px"
            width="100%">
            <igx-column [field]="'Name'" dataType="string" [headerTemplate]="pinTemplate" width="250px"></igx-column>
            <igx-column [field]="'Title'" dataType="string" [headerTemplate]="pinTemplate" width="300px"></igx-column>
            <igx-column [field]="'ID'" dataType="number" [headerTemplate]="pinTemplate" width="200px"></igx-column>
            <igx-column [field]="'HireDate'" header="Hire Date" dataType="date" [headerTemplate]="pinTemplate" width="200px"></igx-column>
            <igx-column [field]="'Age'" dataType="number" [headerTemplate]="pinTemplate" width="200px"></igx-column>
            <igx-column [field]="'Address'" dataType="string" [headerTemplate]="pinTemplate" width="200px"></igx-column>
            <igx-column [field]="'City'" dataType="string" [headerTemplate]="pinTemplate" width="200px"></igx-column>
            <igx-column [field]="'Country'" dataType="string" [headerTemplate]="pinTemplate" width="200px"></igx-column>
            <igx-column [field]="'Fax'" dataType="string" [headerTemplate]="pinTemplate" width="200px"></igx-column>
            <igx-column [field]="'PostalCode'" header="Postal Code" dataType="string" [headerTemplate]="pinTemplate" width="200px"></igx-column>
            <igx-column [field]="'Phone'" dataType="string" [headerTemplate]="pinTemplate" width="200px"></igx-column>
        </igx-tree-grid>
    </div>
    

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

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

    Demo

    Pinning Limitations

    • 열 너비를 백분율(%)로 설정하면 고정된 열이 있을 때 트리 그리드 본문과 머리글 내용이 잘못 정렬됩니다. 열 고정이 올바르게 작동하려면 열 너비가 픽셀(px) 단위이거나 트리 그리드에 의해 자동 할당되어야 합니다.

    API References

    Additional Resources

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