0
votes

I have cell render class in Angular project that generate html input templates inside ag-grid cells. After horizontal scroll, as the input cells go off-screen the ag-grid re-renders these input element and the input elements loos their values. Below is my CellRenderer class:

export class TemplateRendererComponent implements ICellRendererAngularComp {
  template: TemplateRef<any>;
  templateContext: { $implicit: any, params: any };

  refresh(params: any): boolean {
    this.templateContext = {
      $implicit: params.data,
      params,
    };
    return true;
  }

  agInit(params: ICellRendererParams): void {
    this.template = params[ 'ngTemplate' ];
    this.refresh(params);
  }
}

How to make this input elements keep their values?

2
can you cache the updated input values in your ag grid component and pass as cellRendererParams?Pratik Bhat
I think this is the last option I will have to do if can't find another way. For example, how to tell ag-grid not destroy CellRenderer component or elementover_stack_flow
intead of sending as a cellRendererParam you can cache the value in renderer's destroy method, once the cell is out of screen, cell renderer gets destroyed which makes sense. There is no way to prevent itPratik Bhat
suppressColumnVirtualisation ag-grid property set true to render all columns. Finally have found in documentation. That's solution in my case.over_stack_flow
please post this as your answerPratik Bhat

2 Answers

0
votes

As per the cellRenderer lifecycle, it gets destroyed once it is out of view.

You can implement ngOnDestroy() and access the last known value before the cell renderer gets destroyed.

  ngOnDestroy() {
    // do your stuff here
  }

You can possibly store this value in a redux store or a service.

Then this value can be accessed in agInit() while re-initializing the renderer.

0
votes

" suppressColumnVirtualisation: Set to true so that the grid doesn't virtualise the columns. For example, if you have 100 columns, but only 10 visible due to scrolling, all 100 will always be rendered. Default: false " Source: https://www.ag-grid.com/javascript-grid-properties/