6

Whenever the user edits a cell in a particular column, I want to copy their value to an adjacent cell and remove the value from the cell they edited. From the event object, I can get the newValue from the cell that was edited, but I don't know to get a reference to a different cell and set its value.

gridColumnDefinitions = [
   {
      headerName: 'Column A',
      field: 'columnA',
      editable: true,
      onCellValueChanged: (event) => {
          var newValue = event.newValue;

          //Move new value to columnB and set this value to "".
          //How??
      },
    },
    {
      headerName: 'Column B',
      field: 'columnB',
      editable: false,
    }
]

1 Answer 1

11

You can define onCellValueChanged on columnA something like this -

  onCellValueChanged : (params) => {
      if (params.oldValue !== params.newValue) {
        params.data.columnB = params.newValue; // assign to new adjacent column
        params.data.columnA = ""; // change the underlying data 
        params.api.refreshCells({columns : ["columnA","columnB"]}) ;
      }
  } 
1
  • Works, but I had to use this.agGrid.api.setColumnDefs(this.columnDefs) and this.form.updateValueAndValidity() instead of refreshCells
    – Jmainol
    Dec 22, 2023 at 14:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.