---
title: "Row Dragging Customisation"
framework: javascript
version: "36.1.0"
---

# Row Dragging Customisation

There are some options that can be used to customise the Row Drag experience, so it has a better integration with your application.

## Entire Row Dragging

When using row dragging it is also possible to reorder rows by clicking and dragging anywhere on the row without the need for a drag handle by enabling the `rowDragEntireRow` grid option.

#### Entire Row Dragging

```ts
import {
  ClientSideRowModelModule,
  GridApi,
  GridOptions,
  ModuleRegistry,
  NumberFilterModule,
  RowDragModule,
  RowSelectionModule,
  TextFilterModule,
  createGrid,
  enableDevValidations,
} from "ag-grid-community";
import { IOlympicData } from "./interfaces";

// Enable extended validations only for development
if (process.env.NODE_ENV !== "production") {
  enableDevValidations();
}

ModuleRegistry.registerModules([
  TextFilterModule,
  NumberFilterModule,
  RowDragModule,
  RowSelectionModule,
  ClientSideRowModelModule,
]);

let gridApi: GridApi<IOlympicData>;

const gridOptions: GridOptions<IOlympicData> = {
  columnDefs: [
    { field: "athlete" },
    { field: "country" },
    { field: "year", width: 100 },
    { field: "date" },
    { field: "sport" },
    { field: "gold" },
    { field: "silver" },
    { field: "bronze" },
  ],

  defaultColDef: {
    width: 170,
    filter: true,
  },
  rowDragManaged: true,
  rowDragEntireRow: true,
  rowDragMultiRow: true,
  rowSelection: { mode: "multiRow" },
};

const gridDiv = document.querySelector<HTMLElement>("#myGrid")!;
gridApi = createGrid(gridDiv, gridOptions);

fetch("https://www.ag-grid.com/example-assets/olympic-winners.json")
  .then((response) => response.json())
  .then((data: IOlympicData[]) => gridApi!.setGridOption("rowData", data));
```

[Live example: Entire Row Dragging](https://www.ag-grid.com/examples/row-dragging-customisation/entire-row-dragging/typescript/)

The example above demonstrates entire row dragging with [Multi-Row Dragging](https://www.ag-grid.com/javascript-data-grid/row-dragging-managed/#multi-row-dragging). Note the following:

- Reordering rows by clicking and dragging anywhere on a row is possible as `rowDragEntireRow` is enabled.
- Multiple rows can be selected and dragged as `rowDragMultiRow` is also enabled with `rowSelection.mode = 'multiRow'`.
- Row Drag Managed is being used, but it is not a requirement for Entire Row Dragging.

To enable entire row dragging, set the `rowDragEntireRow` property to `true` in the `gridOptions` as shown below:

```js
const gridOptions = {
    columnDefs: [
        { field: 'country' },
        { field: 'year' },
        { field: 'sport' },
        { field: 'total' }
    ],
    // allows rows to be dragged without the need for drag handles
    rowDragEntireRow: true,

    // other grid options ...
}
```

> **Warning**
>
> [Cell Selection](https://www.ag-grid.com/javascript-data-grid/cell-selection/) is not supported when `rowDragEntireRow` is enabled.

## Custom Row Drag Text

When a row drag starts, a "floating" DOM element is created to indicate which row is being dragged. By default, this DOM element will contain the same value as the cell that started the row drag. It's possible to override that text by using the `gridOptions.rowDragText` callback.

#### Row Drag With Custom Text

```ts
import {
  ClientSideRowModelModule,
  ColDef,
  GridApi,
  GridOptions,
  IRowDragItem,
  ModuleRegistry,
  NumberFilterModule,
  RowDragModule,
  TextFilterModule,
  createGrid,
  enableDevValidations,
} from "ag-grid-community";
import { IOlympicData } from "./interfaces";

// Enable extended validations only for development
if (process.env.NODE_ENV !== "production") {
  enableDevValidations();
}

ModuleRegistry.registerModules([
  TextFilterModule,
  NumberFilterModule,
  RowDragModule,
  ClientSideRowModelModule,
]);

const rowDragText = function (params: IRowDragItem) {
  // keep double equals here because data can be a string or number
  if (params.rowNode!.data.year == "2012") {
    return params.defaultTextValue + " (London Olympics)";
  }
  return params.defaultTextValue;
};

const columnDefs: ColDef[] = [
  { field: "athlete", rowDrag: true },
  { field: "country" },
  { field: "year", width: 100 },
  { field: "date" },
  { field: "sport" },
  { field: "gold" },
  { field: "silver" },
  { field: "bronze" },
];

let gridApi: GridApi<IOlympicData>;

const gridOptions: GridOptions<IOlympicData> = {
  defaultColDef: {
    width: 170,
    filter: true,
  },
  rowDragManaged: true,
  columnDefs: columnDefs,
  rowDragText: rowDragText,
};

const gridDiv = document.querySelector<HTMLElement>("#myGrid")!;
gridApi = createGrid(gridDiv, gridOptions);

fetch("https://www.ag-grid.com/example-assets/olympic-winners.json")
  .then((response) => response.json())
  .then((data: IOlympicData[]) => gridApi!.setGridOption("rowData", data));
```

[Live example: Row Drag With Custom Text](https://www.ag-grid.com/examples/row-dragging-customisation/custom-drag-text/typescript/)

The example above shows dragging with custom text. The following can be noted:

- When you drag a row of the year 2012, the `rowDragText` callback will add **(London Olympics)** to the floating drag element.

To enable custom row drag text, set the `rowDragText` callback in the `gridOptions` as shown below:

```js
const gridOptions = {
    columnDefs: [
        {
            field: 'athlete',
            rowDrag: true
        }, {
            field: 'country'
        }
    ],
    rowDragText: (params, dragItemCount) => {
        return (
            dragItemCount > 1
                ? (dragItemCount + ' items')
                : params.defaultTextValue + ' is'
        ) + ' being dragged...';
    },

    // other grid options ...
}
```

| Property | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `rowDragText` | `RowDragTextFunc` |  |  | A callback that should return a string to be displayed by the `rowDragComp` while dragging a row. If this callback is not set, the current cell value will be used. If the `rowDragText` callback is set in the ColDef it will take precedence over this, except when `rowDragEntireRow=true`. Module: [`RowDragModule`](https://www.ag-grid.com/javascript-data-grid/modules/). [Initial](https://www.ag-grid.com/javascript-data-grid/grid-interface/#initial-grid-options). |

## Custom Row Drag Text with Multiple Draggers

If the grid has more than one column set with `rowDrag=true`, the `rowDragText` callback can be set in the `colDef`.

#### Row Drag With Custom Text and Multiple Draggers

```ts
import {
  ClientSideRowModelModule,
  ColDef,
  GridApi,
  GridOptions,
  IRowDragItem,
  ModuleRegistry,
  NumberFilterModule,
  RowDragModule,
  RowSelectionModule,
  TextFilterModule,
  createGrid,
  enableDevValidations,
} from "ag-grid-community";
import { IOlympicData } from "./interfaces";

// Enable extended validations only for development
if (process.env.NODE_ENV !== "production") {
  enableDevValidations();
}

ModuleRegistry.registerModules([
  TextFilterModule,
  NumberFilterModule,
  RowDragModule,
  RowSelectionModule,
  ClientSideRowModelModule,
]);

const athleteRowDragTextCallback = function (
  params: IRowDragItem,
  dragItemCount: number,
) {
  // keep double equals here because data can be a string or number
  return `${dragItemCount} athlete(s) selected`;
};

const rowDragTextCallback = function (params: IRowDragItem) {
  // keep double equals here because data can be a string or number
  if (params.rowNode!.data.year == "2012") {
    return params.defaultTextValue + " (London Olympics)";
  }
  return params.defaultTextValue;
};

const columnDefs: ColDef[] = [
  {
    field: "athlete",
    rowDrag: true,
    rowDragText: athleteRowDragTextCallback,
  },
  { field: "country", rowDrag: true },
  { field: "year", width: 100 },
  { field: "date" },
  { field: "sport" },
  { field: "gold" },
  { field: "silver" },
  { field: "bronze" },
];

let gridApi: GridApi<IOlympicData>;

const gridOptions: GridOptions<IOlympicData> = {
  defaultColDef: {
    width: 170,
    filter: true,
  },
  rowDragManaged: true,
  columnDefs,
  rowDragText: rowDragTextCallback,
  rowDragMultiRow: true,
  rowSelection: { mode: "multiRow" },
};

const gridDiv = document.querySelector<HTMLElement>("#myGrid")!;
gridApi = createGrid(gridDiv, gridOptions);

fetch("https://www.ag-grid.com/example-assets/olympic-winners.json")
  .then((response) => response.json())
  .then((data: IOlympicData[]) => gridApi!.setGridOption("rowData", data));
```

[Live example: Row Drag With Custom Text and Multiple Draggers](https://www.ag-grid.com/examples/row-dragging-customisation/custom-drag-multiple-draggers/typescript/)

The example above shows dragging with custom text and multiple column draggers. The following can be noted:

- When you drag a row with a year of 2012 by the country row dragger, the `rowDragText` callback will add **(London Olympics)** to the floating drag element.
- When you drag the row by the athlete row dragger, the `rowDragText` callback in the `gridOptions` will be overridden by the one in the `colDef` and will display the number of **athletes selected**.

To enable custom row drag text per column dragger, set the `rowDragText` callback in the `colDef` as shown below:

```js
const gridOptions = {
    columnDefs: [
        {
            field: 'athlete',
            rowDrag: true,
            rowDragText: (params, dragItemCount) => {
                const suffix = dragItemCount == 1 ? 'athlete' : 'athletes';
                return `Dragging ${dragItemCount} ${suffix}`;
            }
        }, {
            field: 'country',
            rowDrag: true,
        }
    ],
    rowDragText: (params, dragItemCount) => {
        return (
            dragItemCount > 1
                ? (dragItemCount + ' items')
                : params.defaultTextValue + ' is'
        ) + ' being dragged...';
    },

    // other grid options ...
}
```

## Row Dragger inside Custom Cell Renderers

Due to the complexity of some applications, it could be handy to render the Row Drag Component inside of a Custom Cell Renderer. This can be achieved by using the `registerRowDragger` method in the [ICellRendererParams](https://www.ag-grid.com/javascript-data-grid/component-cell-renderer/).

#### Row Drag With Custom Cell Renderer

```ts
import {
  CellStyleModule,
  ClientSideRowModelModule,
  ColDef,
  GridApi,
  GridOptions,
  ModuleRegistry,
  NumberFilterModule,
  RowDragModule,
  TextFilterModule,
  createGrid,
  enableDevValidations,
} from "ag-grid-community";
import { CustomCellRenderer } from "./customCellRenderer";
import { IOlympicData } from "./interfaces";

// Enable extended validations only for development
if (process.env.NODE_ENV !== "production") {
  enableDevValidations();
}

ModuleRegistry.registerModules([
  TextFilterModule,
  NumberFilterModule,
  RowDragModule,
  CellStyleModule,
  ClientSideRowModelModule,
]);

const columnDefs: ColDef[] = [
  {
    field: "athlete",
    cellClass: "custom-athlete-cell",
    cellRenderer: CustomCellRenderer,
  },
  { field: "country" },
  { field: "year", width: 100 },
  { field: "date" },
  { field: "sport" },
  { field: "gold" },
  { field: "silver" },
  { field: "bronze" },
];

let gridApi: GridApi<IOlympicData>;

const gridOptions: GridOptions<IOlympicData> = {
  defaultColDef: {
    width: 170,
    filter: true,
  },
  rowDragManaged: true,
  columnDefs: columnDefs,
};

const gridDiv = document.querySelector<HTMLElement>("#myGrid")!;
gridApi = createGrid(gridDiv, gridOptions);

fetch("https://www.ag-grid.com/example-assets/olympic-winners.json")
  .then((response) => response.json())
  .then((data: IOlympicData[]) => gridApi!.setGridOption("rowData", data));
```

[Live example: Row Drag With Custom Cell Renderer](https://www.ag-grid.com/examples/row-dragging-customisation/dragger-inside-custom-cell-renderer/typescript/)

The example above shows a custom cell renderer using the `registerRowDragger` callback to render the Row Dragger inside itself.

- When you hover the cells, an arrow will appear, and this arrow can be used to **drag** the rows.

To register a custom row dragger inside a custom cell renderer, use the `registerRowDragger` method from the `ICellRendererParams` as shown below:

```js
// your custom cell renderer init code
const rowDragger = document.createElement('div')
this.eGui.appendChild(rowDragger);

// register it as a row dragger
params.registerRowDragger(rowDragger);
```

> **Warning**
>
> When using `registerRowDragger` you should **not** set the property `rowDrag=true` in the Column Definition. Doing that will cause the cell to have two row draggers.

## Full Width Row Dragging

It is possible to drag [Full Width Rows](https://www.ag-grid.com/javascript-data-grid/full-width-rows/) by registering a [Custom Row Dragger](#row-dragger-inside-custom-cell-renderers).

#### Row Drag with Full Width Rows

```ts
import {
  ClientSideRowModelModule,
  GridApi,
  GridOptions,
  ICellRendererParams,
  IsFullWidthRowParams,
  ModuleRegistry,
  RowDragModule,
  RowHeightParams,
  TextFilterModule,
  createGrid,
  enableDevValidations,
} from "ag-grid-community";
import { getData } from "./data";
import { FullWidthCellRenderer } from "./fullWidthCellRenderer";

// Enable extended validations only for development
if (process.env.NODE_ENV !== "production") {
  enableDevValidations();
}

ModuleRegistry.registerModules([
  TextFilterModule,
  RowDragModule,
  ClientSideRowModelModule,
]);

let gridApi: GridApi;

const gridOptions: GridOptions = {
  columnDefs: [
    { field: "name", cellRenderer: countryCellRenderer },
    { field: "continent" },
    { field: "language" },
  ],
  defaultColDef: {
    flex: 1,
    filter: true,
  },
  rowData: getData(),
  rowDragManaged: true,
  getRowHeight: (params: RowHeightParams) => {
    // return 100px height for full width rows
    if (isFullWidth(params.data)) {
      return 100;
    }
  },
  isFullWidthRow: (params: IsFullWidthRowParams) => {
    return isFullWidth(params.rowNode.data);
  },
  // see AG Grid docs cellRenderer for details on how to build cellRenderers
  fullWidthCellRenderer: FullWidthCellRenderer,
};

function countryCellRenderer(params: ICellRendererParams) {
  if (!params.fullWidth) {
    return params.value;
  }
  const flag =
    '<img border="0" width="15" height="10" src="https://www.ag-grid.com/example-assets/flags/' +
    params.data.code +
    '.png">';
  return (
    '<span style="cursor: default;">' + flag + " " + params.value + "</span>"
  );
}

function isFullWidth(data: any) {
  // return true when country is Peru, France or Italy
  return ["Peru", "France", "Italy"].indexOf(data.name) >= 0;
}

const gridDiv = document.querySelector<HTMLElement>("#myGrid")!;
gridApi = createGrid(gridDiv, gridOptions);
```

[Live example: Row Drag with Full Width Rows](https://www.ag-grid.com/examples/row-dragging-customisation/dragger-inside-full-width-row/typescript/)

In the example above, only the full width rows are draggable.

## Row Dragger with Custom Start Drag Pixels

By default, the drag event only starts after the **Row Drag Element** has been dragged by `4px`, but sometimes it might be useful to start the drag with a different drag threshold. For example, start dragging as soon as the `mousedown` event happens (dragged by `0px`). For that reason, the `registerRowDragger` takes a second parameter to specify the number of pixels that will start the drag event.

#### Row Drag With Custom Start Drag Pixels

```ts
import {
  CellStyleModule,
  ClientSideRowModelModule,
  ColDef,
  GridApi,
  GridOptions,
  ModuleRegistry,
  NumberFilterModule,
  RowDragCancelEvent,
  RowDragEndEvent,
  RowDragEnterEvent,
  RowDragModule,
  TextFilterModule,
  createGrid,
  enableDevValidations,
} from "ag-grid-community";
import { CustomCellRenderer } from "./customCellRenderer";
import { IOlympicData } from "./interfaces";

// Enable extended validations only for development
if (process.env.NODE_ENV !== "production") {
  enableDevValidations();
}

ModuleRegistry.registerModules([
  TextFilterModule,
  NumberFilterModule,
  RowDragModule,
  CellStyleModule,
  ClientSideRowModelModule,
]);

const columnDefs: ColDef[] = [
  {
    field: "athlete",
    cellClass: "custom-athlete-cell",
    cellRenderer: CustomCellRenderer,
  },
  { field: "country" },
  { field: "year", width: 100 },
  { field: "date" },
  { field: "sport" },
  { field: "gold" },
  { field: "silver" },
  { field: "bronze" },
];

let gridApi: GridApi<IOlympicData>;

const gridOptions: GridOptions<IOlympicData> = {
  defaultColDef: {
    width: 170,
    filter: true,
  },
  rowDragManaged: true,
  columnDefs: columnDefs,
  onRowDragEnter: onRowDragEnter,
  onRowDragEnd: onRowDragEnd,
  onRowDragCancel: onRowDragCancel,
};

function onRowDragEnter(e: RowDragEnterEvent) {
  console.log("onRowDragEnter: node", e.node.id);
}

function onRowDragEnd(e: RowDragEndEvent) {
  console.log("onRowDragEnd: node", e.node.id);
}

function onRowDragCancel(e: RowDragCancelEvent) {
  console.log("onRowDragCancel: node", e.node.id);
}

const gridDiv = document.querySelector<HTMLElement>("#myGrid")!;
gridApi = createGrid(gridDiv, gridOptions);

fetch("https://www.ag-grid.com/example-assets/olympic-winners.json")
  .then((response) => response.json())
  .then((data: IOlympicData[]) => gridApi!.setGridOption("rowData", data));
```

[Live example: Row Drag With Custom Start Drag Pixels](https://www.ag-grid.com/examples/row-dragging-customisation/dragger-inside-custom-start-drag-pixels/typescript/)

In the example above, the drag event starts as soon as `mousedown` is fired.

## Custom Drag and Drop Image

The drag and drop image can be customised via the grid properties `dragAndDropImageComponent` and `dragAndDropImageComponentParams`.

Implement this interface to provide a custom drag and drop image component when dragging parts of the grid.

```ts
interface IDragAndDropImageComponent {
    // Optional - props for rendering.
    init?(params: IDragAndDropImageParams): void;

    // Mandatory - Return the DOM element of the component, this is what the grid will display while dragging
    getGui(): HTMLElement;

    // Optional - Gets called once by grid after rendering is finished - if your renderer needs to do any cleanup,
    // do it here
    destroy?(): void;

    // Mandatory - Gets called every time the grid needs to update the label of the Drag Image.
    setLabel(label: string): void;

    // Mandatory - Gets called every time the grid needs to update the icon of the Drag Image.
    setIcon(icon: string | null, shake: boolean): void;
}
```

### IDragAndDropImageParams

| Property | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `dragSource` | `DragSource` |  |  | DragSource |
| `api` | [`GridApi`](https://www.ag-grid.com/javascript-data-grid/grid-api/) |  |  | The grid api. |
| `context` | [`TContext`](https://www.ag-grid.com/javascript-data-grid/typescript-generics/#context-tcontext) |  |  | Application context as set on `gridOptions.context`. |

### Custom Params

On top of the parameters provided by the grid, you can also provide your own parameters. This is useful if you want to allow configuring the component. For example, you might have parts of the grid that you want to highlight with a different colour.

```js
colDef = {
    dragAndDropImageComponent: MyDragAndDropImageComponent,
    dragAndDropImageComponentParams : {
        accentColour: 'SlateGray'
    }
}
```

#### Custom Drag and Drop Image

```ts
import {
  ClientSideRowModelModule,
  GridApi,
  GridOptions,
  ModuleRegistry,
  NumberFilterModule,
  RowDragModule,
  TextFilterModule,
  createGrid,
  enableDevValidations,
} from "ag-grid-community";
import { CustomDragAndDropImage } from "./customDragAndDropImage";
import { IOlympicData } from "./interfaces";

// Enable extended validations only for development
if (process.env.NODE_ENV !== "production") {
  enableDevValidations();
}

ModuleRegistry.registerModules([
  TextFilterModule,
  NumberFilterModule,
  RowDragModule,
  ClientSideRowModelModule,
]);

let gridApi: GridApi<IOlympicData>;

const gridOptions: GridOptions<IOlympicData> = {
  columnDefs: [
    { field: "athlete", rowDrag: true },
    { field: "country" },
    { field: "year", width: 100 },
    { field: "date" },
    { field: "sport" },
    { field: "gold" },
    { field: "silver" },
    { field: "bronze" },
  ],

  defaultColDef: {
    width: 170,
    filter: true,
  },
  rowDragManaged: true,
  dragAndDropImageComponent: CustomDragAndDropImage,
  dragAndDropImageComponentParams: {
    accentColour: "SlateGray",
  },
};

const gridDiv = document.querySelector<HTMLElement>("#myGrid")!;
gridApi = createGrid(gridDiv, gridOptions);

fetch("https://www.ag-grid.com/example-assets/olympic-winners.json")
  .then((response) => response.json())
  .then((data: IOlympicData[]) => gridApi!.setGridOption("rowData", data));
```

[Live example: Custom Drag and Drop Image](https://www.ag-grid.com/examples/row-dragging-customisation/custom-drag-drop-image/typescript/)
