# Angular Grid Row Reordering

The row reordering feature of the [Angular Grid](https://www.telerik.com/kendo-angular-ui-develop/components/grid) allows you to rearrange rows by dragging them with the mouse. By default, the row reordering is disabled.

You can reorder the Grid rows by:

<Row>
  <Column count={[24,24,12]} style={{marginBottom: "1rem"}}>
    <Component className="tile" href="#using-a-specified-handle">
      <ComponentTitle>Using a Specified Handle</ComponentTitle>
      <ComponentDescription style={{padding: "0 10px 10px 10px"}}>Enable row reordering with a dedicated drag handle column for precise control over drag operations.</ComponentDescription>
    </Component>
  </Column>
  <Column count={[24,24,12]} style={{marginBottom: "1rem"}}>
    <Component className="tile" href="#dragging-the-row">
      <ComponentTitle>Dragging the Row</ComponentTitle>
      <ComponentDescription style={{padding: "0 10px 10px 10px"}}>Allow users to reorder rows by clicking and dragging anywhere on the row without a dedicated handle.</ComponentDescription>
    </Component>
  </Column>
</Row>

## Using a Specified Handle

To enable the row reordering feature of the Grid:

1. Set the [`rowReorderable`](https://www.telerik.com/kendo-angular-ui-develop/components/grid/api/gridcomponent#rowreorderable) property of the Grid to `true`. By default row reordering is disabled.
2. Define a [`RowReorderColumn`](https://www.telerik.com/kendo-angular-ui-develop/components/grid/api/rowreordercolumncomponent) by using the `<kendo-grid-rowreorder-column>` tag. It will hold the dedicated drag handle for row reordering.

> When the Grid data is bound using the [`DataBindingDirective`](https://www.telerik.com/kendo-angular-ui-develop/components/grid/api/databindingdirective), all data updates related to row reordering will be handled automatically.

The following example demonstrates how to drag and drop a row using a drag handle.

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

## Dragging the Row

To allow the dragging of a row without needing the dedicated handle, use the [`DragTargetContainer`](https://www.telerik.com/kendo-angular-ui-develop/components/utils/draganddrop/drag-container) and [`DropTargetContainer`](https://www.telerik.com/kendo-angular-ui-develop/components/utils/draganddrop/drop-container) built-in directives. This will allow the user to reorder a row by clicking anywhere on it:

1. Create a wrapper container of the Grid and apply the built-in [`DragTargetContainer`](https://www.telerik.com/kendo-angular-ui-develop/components/utils/draganddrop/drag-container) and [`DropTargetContainer`](https://www.telerik.com/kendo-angular-ui-develop/components/utils/draganddrop/drop-container) directives.
   ```html
   <div #wrapper
       kendoDragTargetContainer
       kendoDropTargetContainer
       ... >
       <kendo-grid></kendo-grid>
    </div>
   ```

2. To define the drag and drop targets, configure the directives' properties.
   ```html
   <div ...
       dragTargetFilter=".k-master-row"
       dropTargetFilter=".k-master-row"
       [dragData]="dragData"
       [hint]="{hintClass: 'rowHint'}"
       (onDrop)="onDrop($event)"
       dragHandle="tr">
   </div>
   ```

3. Use the [`dragData`](https://www.telerik.com/kendo-angular-ui-develop/components/utils/api/dragtargetcontainerdirective#dragdata) callback to fetch the row index.
   ```ts
   public dragData = ({ dragTarget }) => {
       return Number(dragTarget.getAttribute('data-kendo-grid-item-index'));
   };
   ```

4. Use the fetched index to reorder the rows and invoke the `notify()` method of the directives to reflect the changes.
   ```ts
   public onDrop(e: DropTargetEvent): void {
       const fromIndex = e.dragData;
       // Refresh both containers after the data order changes.
       this.dragTargetContainer.notify();
       this.dropTargetContainer.notify();
   }
   ```

The following example demonstrates how to drag and drop a row.

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

## Customizing the Drag Handle

Тhe row reordering feature relies on a default handle to perform the drag-and-drop operation. The default handle is represented by the built-in [`RowReorderColumnComponent`](https://www.telerik.com/kendo-angular-ui-develop/components/grid/api/rowreordercolumncomponent).

You can customize the default drag handle and render custom elements for dragging the rows by using the built-in [`RowDragHandleTemplateDirective`](https://www.telerik.com/kendo-angular-ui-develop/components/grid/api/rowdraghandletemplatedirective).

The following example demonstrates how to render a custom drag handle for the row reordering feature of the Grid.

[Demo Source](https://demos.telerik.com/kendo-angular-ui/demos/grid/row-reordering/custom-drag-handle/source.txt)

## Customizing the Drag Hint

To ensure the user-friendliness of the operation, the component displays a designated hint element with the current row data while dragging the rows within the Grid. You can modify the content of the drag hint by utilizing the built-in [`RowDragHintTemplateDirective`](https://www.telerik.com/kendo-angular-ui-develop/components/grid/api/rowdraghinttemplatedirective) and rendering the desired custom content.

The following example demonstrates how to display a custom drag hint for the row reordering feature of the Grid.

[Demo Source](https://demos.telerik.com/kendo-angular-ui/demos/grid/row-reordering/custom-drag-hint/source.txt)

## Known Limitations

* Row reordering does not work with sorting as both functionalities are mutually exclusive.

## Suggested Links

* [ColumnComponent](https://www.telerik.com/kendo-angular-ui-develop/components/grid/api/columncomponent)
* [API Reference of the GridComponent](https://www.telerik.com/kendo-angular-ui-develop/components/grid/api/gridcomponent)
* [API Index of the Grid](https://www.telerik.com/kendo-angular-ui-develop/components/grid/api)
* [Drag Grid rows to a custom container](https://www.telerik.com/kendo-angular-ui-develop/components/knowledge-base/row-reorder-custom-container)
