[!Note] Please note that this control has been deprecated and replaced with the Grid component, and as such, we recommend migrating to that control. This will not be receiving any new features, bug fixes will be deprioritized. For help or questions on migrating your codebase to the Data Grid, please contact support.

    Web Components Grid Column Pinning Overview

    The Ignite UI for Web Components Data Grid supports the ability to pin columns, allowing the end users to lock a column in a particular column order.

    A column or multiple columns can be pinned to the left-hand or right-hand side of the Data Grid. In addition, you can change the pin state of the columns by utilizing the pinColumn function.

    Web Components Grid Column Pinning Example

    The Column Pinning API in the Data Grid can be enabled by setting either a column's Pinned property, or when setting it by utilizing the pinColumn function of the grid.

    The Pinned property has three options:

    • Left - enabling Left will position pinned columns to the left-hand side of the grid.
    • Right - enabling Right will position pinned columns to the right side of the grid.
    • None - enabling None will unpin a column and reposition its default placement within the grid.

    Unpinned columns that are adjacent to pinned columns will still maintain horizontal scrolling.

    The pinColumn function contains two required parameters. The first parameter is the column to be pinned, and the second is with the PinnedPositions enumeration setting.

    Code Snippet

    The following code demonstrates how to implement column pinning in the Web Components Data Grid with column pinning by using the Pinned property and pinColumn function:

    <igc-data-grid
    id="grid"
    height="calc(100% - 40px)"
    width="100%"
    auto-generate-columns="false"
    default-column-min-width="120px"
    scrollbar-style="thin"
    >
        <igc-text-column pinned="left" field="ID" header-text="Employee ID" width="100"  horizontal-alignment="center"></igc-text-column>
        <igc-text-column pinned="left" field="FirstName" header-text="First Name" width="170"></igc-text-column>
        <igc-text-column pinned="left" field="LastName" header-text="Last Name" width="170"></igc-text-column>
    
        <igc-date-time-column pinned="none" field="Birthday" header-text="Date of Birth" width="150" horizontal-alignment="center"></igc-date-time-column>
        <igc-numeric-column pinned="none" field="Age" width="100" horizontal-alignment="center"></igc-numeric-column>
        <igc-image-column pinned="none" field="CountryFlag" header-text="Country" width="140" content-opacity="1" horizontal-alignment="center"></igc-image-column>
    
        <igc-text-column pinned="right" field="Street" header-text="Address" width="240"></igc-text-column>
        <igc-text-column pinned="right" field="City"  width="150" ></igc-text-column>
        <igc-text-column pinned="right" field="Country"  width="150" ></igc-text-column>
    </igc-data-grid>
    
    import { PinnedPositions } from 'igniteui-webcomponents-grids';
    
    onButtonPinLeft() {
    
        let idColumn = this.grid.actualColumns.item(0);
        let firstNameColumn = this.grid.actualColumns.item(1);
        let lastNameColumn = this.grid.actualColumns.item(2);
    
        //pinned property
        idColumn.pinned = PinnedPositions.Left;
        firstNameColumn.pinned = PinnedPositions.Left;
        lastNameColumn.pinned = PinnedPositions.Left;
    
        // pinColumn Function
        this.grid.pinColumn(idColumn, PinnedPositions.Left);
        this.grid.pinColumn(firstNameColumn, PinnedPositions.Left);
        this.grid.pinColumn(lastNameColumn, PinnedPositions.Left);
    }
    
    onButtonPinRight() {
    
        let streetColumn = this.grid.actualColumns.item(6);
        let cityColumn = this.grid.actualColumns.item(7);
        let countryColumn = this.grid.actualColumns.item(8);
    
        //pinned property
        streetColumn.pinned = PinnedPositions.Right;
        cityColumn.pinned = PinnedPositions.Right;
        countryColumn.pinned = PinnedPositions.Right;
    
        //pinColumn function
        this.grid.pinColumn(streetColumn, PinnedPositions.Right);
        this.grid.pinColumn(cityColumn, PinnedPositions.Right);
        this.grid.pinColumn(countryColumn, PinnedPositions.Right);
    }
    
    onButtonUnPin() {
    
        let idColumn = this.grid.actualColumns.item(0);
        let firstNameColumn = this.grid.actualColumns.item(1);
        let lastNameColumn = this.grid.actualColumns.item(2);
    
        //pinned property
        idColumn.pinned = PinnedPositions.Left;
        firstNameColumn.pinned = PinnedPositions.Left;
        lastNameColumn.pinned = PinnedPositions.Left;
    
        //pinColumn function
        this.grid.pinColumn(idColumn, PinnedPositions.None);
        this.grid.pinColumn(firstNameColumn, PinnedPositions.None);
        this.grid.pinColumn(lastNameColumn, PinnedPositions.None);
    
        let streetColumn = this.grid.actualColumns.item(6);
        let cityColumn = this.grid.actualColumns.item(7);
        let countryColumn = this.grid.actualColumns.item(8);
    
        //pinned property
        streetColumn.pinned = PinnedPositions.None;
        cityColumn.pinned = PinnedPositions.None;
        countryColumn.pinned = PinnedPositions.None;
    
        //pinColumn function
        this.grid.pinColumn(streetColumn, PinnedPositions.None);
        this.grid.pinColumn(cityColumn, PinnedPositions.None);
        this.grid.pinColumn(countryColumn, PinnedPositions.None);
    }
    

    Toolbar's Column Pinning UI

    The Column Pinning UI is accessible within the IgcDataGridToolbarComponent component separate from the grid. For this purpose all we have to do is set the toolbar's columnPinning property to true. The toolbar will then display a IgcButtonComponent, when clicked, will display the column pinning UI. This button also displays the total of pinned-left columns. If the toolbar is not created, enabling the columnPinning property will have no effect and hide the button.

    The IgcDataGridToolbarComponent provides additional properties such as adding a title to the toolbar by using the toolbarTitle property, placing text in the IgcButtonComponent by setting the columnPinningText property, and adding a title header to the column hiding UI by setting columnPinningTitle.

    Demo

    Code Snippet

    <igc-dataGrid-toolbar
        toolbar-title="Grid Title"
        column-pinning="true"
        column-pinning-text="Pinning"
        column-pinning-title="Columns Pinned Left">
    </igc-dataGrid-toolbar>
    <igc-data-grid
        id="grid"
        height="calc(100% - 40px)"
        width="100%"
        auto-generate-columns="false"
        default-column-min-width="120px"
        scrollbar-style = "thin">
    </igc-data-grid>
    
    import { IgcDataGrid } from 'igniteui-webcomponents-grids';
    import { IgcDataGridToolbar } from 'igniteui-webcomponents-grids';
    
    private grid: IgcDataGridComponent;
    private toolbar: IgcToolbarComponent;
    
    connectedCallback() {
        this.toolbar.targetGrid = this.grid;
        let productNameColumn = document.getElementById("productname") as IgcTextColumnComponent;
        productNameColumn.pinned = true;
        this.toolbar.columnPinning = true;
        this.toolbar.toolbarTitle = "Grid Title";
        this.toolbar.columnPinningText = "Pinning Text";
        this.toolbar.columnPinningTitle = "Pinning Title Text";
    }
    

    API References