Ag-Grid :: Add 2 child rows in replacement of one child row on parellel side

278 Views Asked by At

https://i.stack.imgur.com/dYMwi.png

The requirement is that I want to add the rows based on the selected options from the search as you are able to see from the image (I have selected 2 items from the search) as soon I click on replace button the selected items should get added.One should get displayed in the same line of the selected row and the other on the next line refer to the same checkbox

1

There are 1 best solutions below

0
Ahmet Firat Keler On

You gave us no code so I take an example to explain.

To do this, you should update rowNode data like below

function setDataOnOtherColumns() {
  const selectedRows = gridOptions.api.getSelectedRows(); // we find selected row here, just one column for this example

  var rowNode = gridOptions.api.getRowNode(selectedRows[0].id); // we find row node by id value
  var newData = {
    id: selectedRows[0].id,
    make: '',
    model: '',
    price: 0,
    make1: selectedRows[0].make,
    model1: selectedRows[0].model,
    price1: selectedRows[0].price,
  }
  rowNode.setData(newData); // we update row node data
}

Here's the grid before Grid Before

Once we select Ford and click the Set Data On Other Columns button Grid After

Here's your reference: https://plnkr.co/edit/1TjzqGJ4zrzH6ZO5?preview

Read more on https://www.ag-grid.com/javascript-data-grid/data-update-single-row-cell/