0
votes

I've two ag-grids on my UI. Ag-grid 1 has 4 rows. Ag-grid 2 has 5 rows. Both ag-grids have same columns. I want to copy all the rows from Ag-grid 2 to Ag-grid 1 on some button click. How can I do that?

Expected result: On button click.

  1. Ag-grid 1 should have 9 rows (4 original rows and 5 rows which are copied from Ag-grid 2).
  2. Ag-grid 2 should have 0 rows
1

1 Answers

2
votes

with this sort of function:

move(){
  var rows = this.agGrid2.api.getModel().rowsToDisplay.map(e=>e.data)
  this.agGrid1.api.updateRowData({add: rows})
  this.agGrid2.api.setRowData([])
}

here's a plunker

This answers exactly as you asked, however, it sounds like you or someone else who is interested in a moving type function from one grid to another, might find it useful to use getSelectedRows() instead of getModel()