ng2-handsontable icon indicating copy to clipboard operation
ng2-handsontable copied to clipboard

Access to ng component properties from inside renderer

Open vchuquimia opened this issue 8 years ago • 2 comments

is there any way to access to the properties defined in the host component from inside of a renderer function ? I tried to use the keyword "this" but it always is undefined.

//a random property inside an angular component
public cellStyles:array<any>() = [];

//the render funtion defined for the column  private columns: any[] = [    {
//      data: 'name',
//      renderer: this.styleRender,
// }]

  styleRender(instance, td, row, col, prop, value, cellProperties) {
    Handsontable.renderers.TextRenderer.apply(this, arguments);
    this.cellStyles// <-  "this" (which is a reference to the host component is always undefined in this context)
  }

Thanks, team!

vchuquimia avatar Sep 18 '17 15:09 vchuquimia

Hi All. Tim Here.

I was checking in to see if a solution was found for this. I'm currently working on a project and need exactly this.

"A real man doesn't give way to anger & discontent & such a person has strength, courage & endurance unlike the angry and complaining." - Marcus Aurelius

timferriss avatar Jul 06 '18 18:07 timferriss

Just define your styleRender method like this:

styleRender = (hotInstance, td, row, column, prop, value, cellProperties) => { console.log(this.yourComponentVariableName); Handsontable.renderers.TextRenderer.apply(this, [hotInstance, td, row, column, prop, value, cellProperties]); }

Best regards

gerfagerfa avatar Jul 13 '18 19:07 gerfagerfa