I am trying to find a solution to row drag a row from grid 1 to a grouped row in grid 2.
For example:
Grid 1 has address information: Street, number, city
Grid 2 has type + address information: Type, street, number, city
Grid 2 is grouped by type so the address information is grouped/attached to a specific type.
I want to drag the address information from grid 1 under a grouped row (for example type 1) and it should be added under the grouped row type 1
I tried to find out if this is possible with the Enterprise version of ag grid. Sadly I can only find you can row drag to another grid and you can group rows. But there is no example of how to row drag to a grouped row. Since for my knowledge you only have applyTransaction Add/remove but not on a grouped row.
Can someone correct me if i’m wrong and maybe could provide a example of how to achieve this?
Sven is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
It sounds like you’re looking to combine row drag and drop functionality with grouping in AG Grid, specifically to drag rows from one grid to another while maintaining their grouping. This can indeed be achieved using AG Grid’s Enterprise version, but it requires some custom logic because the default examples often deal with basic row drag and drop between grids without grouping considerations.
a/c to me : you should try enabling row drag across grids:
In Grid 1, set the rowDrag property for the column where dragging will happen.
{
field: 'street',
rowDrag: true,
}
In Grid 2, you’ll already have rows grouped by type (Type 1, Type 2, etc.). Use the grouping feature of AG Grid:
{
groupDisplayType: 'groupRows',
rowGroup: true,
}
Since AG Grid doesn’t natively handle dropping rows into grouped rows, you’ll need to listen for the drop event and then manually apply the transaction to insert the dropped row into the correct group.
To achieve this, you’ll listen for a rowDragEnd event on Grid 1 and then programmatically determine where to insert the row into Grid 2 based on the grouping.
Here’s how you can do it (this shall work ):
// Grid 1 (Source Grid)
const gridOptions1 = {
columnDefs: [
{ field: 'street', rowDrag: true },
{ field: 'number' },
{ field: 'city' }
],
onRowDragEnd: function(event) {
const draggedData = event.node.data;
// Custom logic to figure out which group the row was dropped on
const groupType = 'Type 1'; // You need to determine this dynamically
const transaction = {
add: [{
type: groupType,
street: draggedData.street,
number: draggedData.number,
city: draggedData.city
}]
};
gridOptions2.api.applyTransaction(transaction);
}
};
// Grid 2 (Target Grid)
const gridOptions2 = {
columnDefs: [
{ field: 'type', rowGroup: true },
{ field: 'street' },
{ field: 'number' },
{ field: 'city' }
],
defaultColDef: {
flex: 1,
minWidth: 100,
resizable: true
},
groupDisplayType: 'groupRows',
rowData: initialDataForGrid2
};
Summary of Steps:
- Enable rowDrag in Grid 1.
- Enable grouping in Grid 2.
- Listen for the rowDragEnd event in Grid 1.
- Determine the target group in Grid 2 based on where the row was
dropped. - Use applyTransaction in Grid 2 to add the new row under
the correct group.