How to conditionally enable/disable cell renderer in Ag-Grid?

Shruti

I am using ag-grid cell renderer and I have created a separate component for it. Based on some condition, I want to conditionally make the cell renderer component enable or disable.

{ headerName: 'Look up values', field: 'LOOKUP', editable: false, cellRenderer:'lookupRenderer'}

I want to enable/disable 'lookupRenderer' based on conditions.

un.spike

Inline cellRenderer should be used only for simple cases. To achieve button-click handling inside own cellRenderer you need to create component for that.

Your component would be like that:

    @Component({
        selector: 'custom-button-cell',
        template: `<button [disabled]="!params.node.data.enableButton" (click)="handleClick()">{{params.value}}</button>`,
        styles: [``]
    })

    export class ConditionalRenderer implements ICellRendererAngularComp {
        private params: any;

        agInit(params: any): void {
            this.params = params;
        }

        refresh(): boolean {
           return true;
        }

       handleClick() {
          alert(`Clicked: ${this.params.value}`);
       }
    }

Here is worked plnkr

Don't forget, that your component should be included to frameworkComponents inside gridOptions or as [frameworkComponents] html attribute.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to apply filter to a cell renderer in ag grid

how to delete ag-grid row with a button in cell renderer

Ag-grid cell renderer with slider not working

ag-grid renders on top of cell renderer

ag-grid cell renderer that shows data from multiple columns

Angular ag-grid cell renderer checkbox not refresh value

Ag Grid cell renderer not instantiated until scrolled back in view

How to make a row conditionally draggable in aAG Grid (ag-grid)?

WxGo Grid Cell renderer

How to set cell dividers on the ag grid

How to conditionally provide a style for a grid cell?

Dynamically changing Cell Renderer of ag-grid using param function in Angular 8

Angular ag-Grid: custom cell renderer that turns on edit mode over all editable cells in row

Ag-Grid : How to get the value of the cell on clicking the cell

ag-grid vue.js: How to access to the parent grid method of a renderer in typescript?

ag-grid checkbox column checked by renderer

How to Customize Number Input Type Cell ag-grid

How to align the checkbox and text in cell to center in ag grid angular

How to make cell content in ag-grid centered vertically?

How to apply custom css class in ag-grid cell in angular?

ag-grid cell editors - how to save data to backend

ag-Grid/Reactjs - How to get cell value in columnDefs

How to display enum value in ag-grid cell field value?

AG-Grid - How to insert a line break into my cell data

Ag-Grid : How to get the focused cell value

How to Render an Angular routerLink inside the cell of an ag-Grid?

Angular ag-grid : How to render HTML in cell?

How to get Ag Grid to display blank cell via cellRendererSelector

how to add border to a hovered cell in ag-grid angular?