Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

250
Vistas
Stop cellRenderer to apply on all the rows in angular

I am trying to make a custom component in ag-gird which consists of two radio button. I wanted to make selection for each individual row, so I have tried both cellRender and cellEditor, with cellEditor, the radio buttons are visible only after a click event is triggered.

And with cellRenderer it is applying changes to all the rows when a radio button is selected as shown in the images. I am looking for individual row edits.

Dots in coldefs are just mention the other columns,

Please check the below code aswell


  template: `
    <ag-grid-angular
      #agGrid
      style="width: 100%; height: 100%;"
      id="myGrid"
      class="ag-theme-alpine"
      [columnDefs]="columnDefs"
      [defaultColDef]="defaultColDef"
      [rowData]="rowData"
      [frameworkComponents]="frameworkComponents"
      (gridReady)="onGridReady($event)"
    ></ag-grid-angular>
  `,
})

constructor(private http: HttpClient) {
    this.columnDefs = [
      {
        field: 'athlete',
        cellRenderer: 'btnCellRenderer',
        minWidth: 150,
      }...
      },
    ];
    this.defaultColDef = {
      flex: 1,
      minWidth: 100,
    };
    this.frameworkComponents = {
      btnCellRenderer: BtnCellRenderer
    }
  }

  onGridReady(params) {
    this.gridApi = params.api;
    this.gridColumnApi = params.columnApi;

    this.http
      .get(
        'https://raw.githubusercontent.com/ag-grid/ag-grid/master/grid-packages/ag-grid-docs/src/olympicWinnersSmall.json'
      )
      .subscribe(data => {
        this.rowData = data;
      });
  }
}

Code of the custom component

@Component({
  selector: 'btn-cell-renderer',
  template: `
<input type="radio" [value]="1" [(ngModel)]="radioValue" (change)="stopEdit()">Val
<input type="radio" [value]="2" [(ngModel)]="radioValue" (change)="stopEdit()">Not-Val
  `,
})
export class BtnCellRenderer {
  private params: any;
  public radioValue: Number;

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

  stopEdit() {
    alert(`Value changed to: ${this.radioValue}`);
    this.params.api.stopEditing();
  }
}

enter image description here

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

If you add a name attribute to the radio buttons, it will group them together. So the radio buttons in the same row should have the same name. I'm simply generating a name given the row index.

@Component({
  template: `
<input type="radio" [name]="radioName" [value]="1" [(ngModel)]="radioValue">Yes
<input type="radio" [name]="radioName" [value]="2" [(ngModel)]="radioValue">No
  `,
})
export class CellComponent {
  public radioValue: Number;
  public radioName: String;

  agInit(params: any): void {
    this.radioValue = params.value;
    this.radioName = 'radio' + params.rowIndex;
  }
}

https://stackblitz.com/edit/angular-ag-grid-cell-renderer-aqqebt?embed=1&file=src/app/cell.component.ts

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda