Row Dragging to an External DropZone

Row Dragging to an External DropZone is concerned with moving rows from the grid to different components within the same application. When using row drag with an external DropZone, the data is moved or copied around using the grid events; this is in contrast to standard Drag & Drop which uses browser events.

The Row Drag to an External DropZone uses the grid's internal Managed Row Dragging system combined with row selection to create a seamless data drag and drop experience.

function addRowDropZone(params: RowDropZoneParams) => void; function removeRowDropZone(params: RowDropZoneParams) => void; // interface for params interface RowDropZoneParams { // A callback method that returns the DropZone HTMLElement getContainer: () => HTMLElement; // callback function that will be executed when the rowDrag enters the target onDragEnter?: (params: RowDragEnterEvent) => void; // callback function that will be executed when the rowDrag leaves the target onDragLeave?: (params: RowDragLeaveEvent) => void; // callback function that will be executed when the rowDrag is dragged inside the target // note: this gets called multiple times onDragging?: (params: RowDragMoveEvent) => void; // callback function that will be executed when the rowDrag drops rows within the target onDragStop?: (params: RowDragEndEvent) => void; }
If you read the Managed Dragging section of the Row Dragging documentation you probably noticed that when you sort, filter and rowGroup the Grid, the managed Row Dragging stops working. The only exception to this rule is when you register external drop zones using addRowDropZone. In this case, you will be able to drag from one container to another, but will not be able to drag the rows within the grid.

Adding and Removing Row Drop Targets

To allow dragging from the grid onto an outside element, or a different grid, call the addRowDropZone from the grid API. This will result in making the passed element or Grid a valid target when moving rows around. If you later wish to remove that drop zone use the removeRowDropZone method from the grid API.

// example usage: new agGrid.Grid(gridElement, gridOptions); var container = document.querySelector('.row-drop-zone'), dropZoneParams = { getContainer: function() { return container; }, onDragStop: function(params) { // do some custom action } }; gridApi.addRowDropZone(dropZoneParams); // when the DropZone above is no longer needed gridApi.removeRowDropZone(dropZoneParams);

In the example below, note the following:

  • You can move rows inside the grid.
  • You can move rows to the container on the right hand side.
  • Toggle the checkbox to enable or disable suppressMoveWhenRowDragging.

Dragging Between Grids

It is possible to use a generic DropZone to Drag and Drop rows from one grid to another. However, this approach will treat the target grid as a generic HTMLElement and adding the rows should be handled by the onDragStop callback. If you wish the grid to manage the Drag and Drop across grids and also handle where the record should be dropped, take a look at Row Dragging - Between Grids.

In the example below, note the following:

  • Rows can be dragged from one grid to the other grid. When the row is received, it is not removed from the first grid. This is the choice of the example. The example could equally have removed from the other grid.
  • If the row is already present in the grid, it will not be added twice. This happens because the grid will not allow duplicated IDs.
  • Rows can be removed from both grids by dragging the row to the 'Trash' drop zone.
  • New rows can be created by clicking on the red, green and blue buttons.