Lukas
Lukas

Reputation: 47

Pass dynamic params to cell renderer in parent component (ag grid)

How to pass dynamic params based on cell params? Like here when we adding class based on cell params

cellClassRules: {
   'error-border': (params: any) => {
      return params.error;
    },
},

I want to do the same with cellRendererParams but it not working:

cellRendererParams: {
  someProp: (params: any) => {
    return ...;
  },
},

Upvotes: 0

Views: 5779

Answers (1)

Fletch
Fletch

Reputation: 907

Say I have a custom cell renderer. It has a property called myProp that I want to set:

export class MyCellRendererComponent implements ICellRendererAngularComp {

  params: any;
  myProp = true;
}

In the component I want to use it I have to add it to the list of components:

<ag-grid [components]="components" >

components = {
    myCellRenderer: MyCellRendererComponent
  };

Then when I set up my columns I can specify the cell renderer and set the myProp property like this:

{
  field: 'myField',
  width: 150,
  cellRenderer: 'myCellRenderer',
  cellRendererParams: {
    myProp: (params) => {
      console.log(params.data.myPropValue); // <-- Can you try this?
      return params.data.myPropValue;
    }
  }
}

Is your custom component definitely being used? Can you put a console.log when you are setting your custom property?

Let me know how you get on

Upvotes: 2

Related Questions