angularag-gridag-grid-angular

Pass multiple values for cellRendererFramework using ag-grid?


I have only seen one SO question relating to this and there were no answers posted.

I have an angular app usnig ag-grid. It uses cellRendererFramework to render data for a column a to display in the table. I need to have data from the Date column to properly format the Data column, but cannot find any way to get that into the renderer component. Here's the basic code:

  // Columns defined inside the main component
  this.columnDefs = [
    { headerName: 'Date', field: 'timestamp'},
    { headerName: 'Data',
      field: 'type',
      cellRendererFramework: MyRendererComponent,
    },
  }


  // Inside the renderer component
  export class MyRendererComponent implements OnInit {
    myData: any;

    agInit(params: import("ag-grid-community").ICellRendererParams): void {

      // This is where I need data from the first column to 
      // properly set the return value
      this.myData = this.setUpData(params.value)
    }

  setUpData(data: any) {
    // Operate on the data here, but I need the timestamp to do it properly
  }
  ...
  }

Does anyone have a suggestion how I can get the timestamp data into MyRendererComponent?


Solution

  • Found the answer. Use the data parameter of params to access the row data and get to your field on that data:

    params.data.timestamp
    

    https://www.ag-grid.com/javascript-grid-cell-rendering-components/#cell-renderers-and-row-groups