Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

241
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!