1

I want to implement a CellRenderer that can show/hide the cell it is attached to (let's call it ShowHideCellRenderer).

I want this cell renderer to take a cell renderer (innerCellRenderer) as a parameter which defines how the cell is rendered if it is visible.

In the ag-grid repository on github there is the GroupCellRenderer which also uses an inner cell renderer:

https://github.com/ag-grid/ag-grid/blob/master/packages/ag-grid/src/ts/rendering/cellRenderers/groupCellRenderer.ts#L245

let rendererPromise:Promise<ICellRendererComp>;
if (params.fullWidth == true) {
    rendererPromise = this.cellRendererService.useFullWidthGroupRowInnerCellRenderer(this.eValue, params);
} else {
    rendererPromise = this.cellRendererService.useInnerCellRenderer(this.params.colDef.cellRendererParams, columnToUse.getColDef(), this.eValue, params);
}

// retain a reference to the created renderer - we'll use this later for cleanup (in destroy)
if (rendererPromise) {
    rendererPromise.then((value:ICellRendererComp) => {
        this.innerCellRenderer = value;
    })
}

But to do the same I need to somehow inject the CellRendererService into my CellRenderer.

As I am using Angular for creation of the CellRenderer the @Autowired decorator does not seem to work.

export class ShowHideCellRendererComponent implements ICellRendererAngularComp {
    @Autowired('cellRendererService')
    private cellRendererService: CellRendererService;

    public agInit(params: any): void {
        console.log(this.cellRendererService); // undefined
    }
}

Doos somebody know how to inject the CellRendererService into my angular cell renderer? Or do you have an idea how to implement an inner cell renderer in another way?

Dennis
  • 1,027
  • 1
  • 14
  • 30
  • Is you `cellRendererService` defined as `@Injectable()`? – Paritosh Jul 03 '18 at 12:54
  • @Paritosh No it's not my own service. It is from the ag-grid source. I think they use soom kind of alternative DI system: https://github.com/ag-grid/ag-grid/blob/master/packages/ag-grid/src/ts/rendering/cellRendererService.ts – Dennis Jul 03 '18 at 12:59
  • Not clear what exactly you wanna to get? Own `cellRenderer`? Is it a trouble? `I want to implement a CellRenderer that can show/hide the cell it is attached` could you please extend your requirements. `cellRenderer` - can be used to handle UI perspective of cell – un.spike Jul 03 '18 at 17:12

0 Answers0