# Angular Grid Row Pinning

The [Kendo UI for Angular Grid](https://www.telerik.com/kendo-angular-ui-develop/components/grid) supports row pinning that keeps specific rows visible at the top or bottom of the Grid while the user scrolls through the data. Pinned rows remain in place regardless of sorting, filtering, or paging, making them ideal for monitoring critical data entries such as out-of-stock items, high-priority orders, or key performance indicators.

The following example demonstrates the row pinning functionality of the Grid.

[Demo Source](https://demos.telerik.com/kendo-angular-ui/demos/grid/row-pinning/overview/source.txt)

## Enabling Row Pinning

The Grid provides multiple approaches for enabling row pinning. All of them require the [`pinnable`](https://www.telerik.com/kendo-angular-ui-develop/components/grid/api/gridcomponent#pinnable) property. The property accepts a `boolean` or a [`GridRowPinLocation`](https://www.telerik.com/kendo-angular-ui-develop/components/grid/api/gridrowpinlocation) string. Setting `pinnable` to `true` enables pinning to both directions. To restrict the pinning direction, use one of the following string values:

* `top`—Allows pinning rows to the top of the Grid only.
* `bottom`—Allows pinning rows to the bottom of the Grid only.
* `both`—Allows pinning rows to both the top and bottom of the Grid.

Choose the approach that best fits your layout and data-binding strategy:

<Row>
  <Column count={[24,24,8]} style={{marginBottom: "1rem"}}>
    <Component className="tile" href="#using-the-pin-column">
      <ComponentTitle>Pin Column</ComponentTitle>
      <ComponentDescription style={{padding: "0 10px 10px 10px"}}>Display a dedicated pin icon on each row. The data binding directive manages the pinned collections automatically.</ComponentDescription>
    </Component>
  </Column>
  <Column count={[24,24,8]} style={{marginBottom: "1rem"}}>
    <Component className="tile" href="#using-a-context-menu">
      <ComponentTitle>Context Menu</ComponentTitle>
      <ComponentDescription style={{padding: "0 10px 10px 10px"}}>Provide pinning actions through a right-click menu. Keeps the Grid layout clean by removing the dedicated pin column.</ComponentDescription>
    </Component>
  </Column>
  <Column count={[24,24,8]} style={{marginBottom: "1rem"}}>
    <Component className="tile" href="#manual-pinned-rows-management">
      <ComponentTitle>Manual Management</ComponentTitle>
      <ComponentDescription style={{padding: "0 10px 10px 10px"}}>Handle the pinned row collections yourself when binding through the data property instead of the data binding directive.</ComponentDescription>
    </Component>
  </Column>
</Row>

### Using the Pin Column

The built-in pin column provides a dedicated UI for pinning and unpinning rows. Add the [`RowPinColumnComponent`](https://www.telerik.com/kendo-angular-ui-develop/components/grid/api/rowpincolumncomponent) inside the Grid to display a pin icon on each row. When using the [`kendoGridBinding`](https://www.telerik.com/kendo-angular-ui-develop/components/grid/api/databindingdirective) directive, the Grid manages the pinned row collections automatically—no extra event handling is required.

The following example demonstrates the default pin column configuration with automatic pinning to both the top and bottom of the Grid.

[Demo Source](https://demos.telerik.com/kendo-angular-ui/demos/grid/row-pinning/pin-column/source.txt)

### Using a Context Menu

As an alternative to the built-in pin column, you can use a context menu to offer row pinning actions. This approach provides a cleaner Grid layout by removing the dedicated pin column while still enabling full pinning functionality.

The following example demonstrates row pinning through a context menu without the pin column.

[Demo Source](https://demos.telerik.com/kendo-angular-ui/demos/grid/row-pinning/context-menu/source.txt)

To implement context-menu-based pinning:

1. Set the [`pinnable`](https://www.telerik.com/kendo-angular-ui-develop/components/grid/api/gridcomponent#pinnable) property to `true` to enable the row pinning feature on the Grid.

   ```html
   <kendo-grid [pinnable]="true">
   </kendo-grid>
   ```

2. Add a [`ContextMenuComponent`](https://www.telerik.com/kendo-angular-ui-develop/components/menus/api/contextmenucomponent) to the template with a template reference variable (for example, `#contextMenu`). Bind the [`items`](https://www.telerik.com/kendo-angular-ui-develop/components/menus/api/contextmenucomponent#items) input to a collection of menu items that define the available pinning actions.

   ```html Context Menu Template
   <kendo-contextmenu #contextMenu [items]="menuItems" (select)="onMenuSelect($event)">
   </kendo-contextmenu>
   ```

   ```ts Menu Items Definition
   public menuItems: Array<{ text: string; svgIcon: SVGIcon; action: string }> = [
       { text: 'Pin to Top', svgIcon: pinOutlineTopIcon, action: 'pinToTop' },
       { text: 'Pin to Bottom', svgIcon: pinOutlineBottomIcon, action: 'pinToBottom' },
       { text: 'Unpin', svgIcon: unpinIcon, action: 'unpin' }
   ];
   ```

3. Set up a context menu that appears on right-click by following the [Context Menu](https://www.telerik.com/kendo-angular-ui-develop/components/grid/accessories/context-menu#setup) article. Inside the [`cellClick`](https://www.telerik.com/kendo-angular-ui-develop/components/grid/api/gridcomponent#cellclick) handler, build the menu items dynamically based on the current pin state of the clicked row. Show only the relevant actions—for example, display **Unpin** and **Pin to Bottom** when the row is already pinned to the top.

   ```ts Dynamic Menu Items Based on Pin State
   private getMenuItems(dataItem: DataItem): PinMenuItem[] {
       const isPinnedTop = this.pinnedTopRows.includes(dataItem);
       const isPinnedBottom = this.pinnedBottomRows.includes(dataItem);

       if (isPinnedTop) {
           return [
               { text: 'Unpin', svgIcon: unpinIcon, action: 'unpin' },
               { text: 'Pin to Bottom', svgIcon: pinOutlineBottomIcon, action: 'pinToBottom' }
           ];
       }

       if (isPinnedBottom) {
           return [
               { text: 'Unpin', svgIcon: unpinIcon, action: 'unpin' },
               { text: 'Pin to Top', svgIcon: pinOutlineTopIcon, action: 'pinToTop' }
           ];
       }

       return [
           { text: 'Pin to Top', svgIcon: pinOutlineTopIcon, action: 'pinToTop' },
           { text: 'Pin to Bottom', svgIcon: pinOutlineBottomIcon, action: 'pinToBottom' }
       ];
   }
   ```

4. Handle the [`select`](https://www.telerik.com/kendo-angular-ui-develop/components/menus/api/contextmenucomponent#select) event of the ContextMenu and update the [`pinnedTopRows`](https://www.telerik.com/kendo-angular-ui-develop/components/grid/api/gridcomponent#pinnedtoprows) and [`pinnedBottomRows`](https://www.telerik.com/kendo-angular-ui-develop/components/grid/api/gridcomponent#pinnedbottomrows) collections based on the selected action. Remove the item from one collection before adding it to another to prevent duplicates.

   ```html Context Menu Template
   <kendo-contextmenu (select)="onMenuSelect($event)">
   </kendo-contextmenu>
   ```

   ```ts Context Menu Select Handler Logic
   public onMenuSelect({ item }: { item: PinMenuItem }): void {
       const dataItem = this.contextDataItem;

       // Move rows between pin collections without leaving duplicates.
       switch (item.action) {
           case 'pinToTop':
               this.pinnedBottomRows = this.pinnedBottomRows.filter(r => r !== dataItem);
               this.pinnedTopRows = [...this.pinnedTopRows, dataItem];
               break;
           case 'pinToBottom':
               this.pinnedTopRows = this.pinnedTopRows.filter(r => r !== dataItem);
               this.pinnedBottomRows = [...this.pinnedBottomRows, dataItem];
               break;
           case 'unpin':
               this.pinnedTopRows = this.pinnedTopRows.filter(r => r !== dataItem);
               this.pinnedBottomRows = this.pinnedBottomRows.filter(r => r !== dataItem);
               break;
       }
   }
   ```

## Pinning Rows to a Specific Location

To restrict pinning to a specific location, set the `pinnable` property to `top` or `bottom`. This configuration limits the pinning actions to the specified location and hides irrelevant options from the UI. For example, when `pinnable` is set to `top`, users can only pin rows to the top of the Grid, and any UI elements related to bottom pinning will be hidden.

The following example demonstrates pinning rows only to the top of the Grid.

[Demo Source](https://demos.telerik.com/kendo-angular-ui/demos/grid/row-pinning/pin-location/source.txt)

## Restricting the Pinnable Rows

The [`isRowPinnable`](https://www.telerik.com/kendo-angular-ui-develop/components/grid/api/gridcomponent#isrowpinnable) callback allows you to restrict which rows can be pinned. The callback receives a [`RowArgs`](https://www.telerik.com/kendo-angular-ui-develop/components/grid/api/rowargs) object containing the `dataItem` and `index`, and returns a boolean that determines whether the row displays the pin action.

The following example allows pinning only for items with a `Low Stock` or `Out of Stock` status.

[Demo Source](https://demos.telerik.com/kendo-angular-ui/demos/grid/row-pinning/is-row-pinnable/source.txt)

## Initially Pinned Rows

To pin rows on initial load, populate the [`pinnedTopRows`](https://www.telerik.com/kendo-angular-ui-develop/components/grid/api/gridcomponent#pinnedtoprows) and [`pinnedBottomRows`](https://www.telerik.com/kendo-angular-ui-develop/components/grid/api/gridcomponent#pinnedbottomrows) arrays with data items before the Grid renders. This is useful for scenarios where you need to surface critical data immediately, such as out-of-stock inventory items or overstock alerts.

The following example demonstrates a Grid that starts with out-of-stock items pinned to the top and overstock items pinned to the bottom.

[Demo Source](https://demos.telerik.com/kendo-angular-ui/demos/grid/row-pinning/initially-pinned/source.txt)

## Manual Pinned Rows Management

When binding the Grid through the [`data`](https://www.telerik.com/kendo-angular-ui-develop/components/grid/api/gridcomponent#data) property instead of [`kendoGridBinding`](https://www.telerik.com/kendo-angular-ui-develop/components/grid/api/databindingdirective), you need to manage the pinned row collections manually. Handle the [`rowPinChange`](https://www.telerik.com/kendo-angular-ui-develop/components/grid/api/gridcomponent#rowpinchange) event to update the [`pinnedTopRows`](https://www.telerik.com/kendo-angular-ui-develop/components/grid/api/gridcomponent#pinnedtoprows) and [`pinnedBottomRows`](https://www.telerik.com/kendo-angular-ui-develop/components/grid/api/gridcomponent#pinnedbottomrows) collections. The event emits a [`RowPinEvent`](https://www.telerik.com/kendo-angular-ui-develop/components/grid/api/rowpinevent) object containing the updated pinned row collections.

The following example demonstrates manual management of pinned rows when using the `data` property for binding.

[Demo Source](https://demos.telerik.com/kendo-angular-ui/demos/grid/row-pinning/manual-pin-column/source.txt)

## See Also

* [Grid Sticky Rows](https://www.telerik.com/kendo-angular-ui-develop/components/grid/rows/sticky)
* [Grid Row Reordering](https://www.telerik.com/kendo-angular-ui-develop/components/grid/rows/reordering)
* [Grid Row and Cell Highlighting](https://www.telerik.com/kendo-angular-ui-develop/components/grid/rows/highlighting)
* [Grid Row Spanning](https://www.telerik.com/kendo-angular-ui-develop/components/grid/rows/row-spanning)
* [Grid Data Binding](https://www.telerik.com/kendo-angular-ui-develop/components/grid/data-binding/basics)
* [Drag and Drop between Grids](https://www.telerik.com/kendo-angular-ui-develop/components/grid/rows/drag-and-drop)
* [API Reference of the GridComponent](https://www.telerik.com/kendo-angular-ui-develop/components/grid/api/gridcomponent)
