ag-grid Angular “colDef.cellRendererFramework.comp

2019-09-14 21:03发布

问题:

Since previous version of ag-grid we could pass a Component as a dependency into our cellRendererFramework like this:

{
    headerName: "Clickable Component",
    field: "name",
    cellRendererFramework: {
        component: ClickableParentComponent,
        dependencies: [ClickableComponent]
    },
    width: 200
}

this is an example taken from this ag-grid blog.

Unfortunatelly version 9 gives me a deprecated warning about this:

colDef.cellRendererFramework.component is deprecated - please refer to https://ag-grid.com/best-angular-2-data-grid/

Is there any recommended way now to achieve this? I couldn't find anything about this in ag-grid's changelogs.

回答1:

Right, the trick to communicate with the parent component is using the context object:

this.gridOptions = <GridOptions>{
    context: {
        componentParent: this
    }
};

Taken from Simple Dynamic Component example



回答2:

did you miss this part of the blog?

instead of:

{
    headerName: "Clickable Component",
    field: "name",
    cellRendererFramework: {
        component: ClickableParentComponent,
        dependencies: [ClickableComponent]
    },
    width: 200
}

You now only need to do this:

{
    headerName: "Clickable Component",
    field: "name",
    cellRendererFramework: ClickableParentComponent,
    width: 250
}