2

I have an ion-grid where I can have x rows with 11 columns:

<ion-grid>
    <ion-row class="row" *ngFor="let row of grid">
      <ion-col class="col" col-1 *ngFor="let file_uri of row">
         <button ion-button class='buttoncell' ion-button (click)="editEntryValue($event)">{{file_uri}}</button>
      </ion-col>
    </ion-row>
</ion-grid>

As you can see the cells of the table are buttons. In the .ts file I have the following:

editEntryValue(event: any){
    console.log(event);
}

So I get a MouseEvent object as event. But when a button is clicked, I need to know from which row (number) and which column (number) it has come from. How can I do this?

1 Answer 1

2

You could add the index to both loops, and send it when clicking the button:

<ion-grid>
    <ion-row class="row" *ngFor="let row of grid; let rowIndex=index">
      <ion-col class="col" col-1 *ngFor="let file_uri of row; let colIndex=index">
         <button ion-button class='buttoncell' ion-button (click)="editEntryValue($event, rowIndex, colIndex)">{{file_uri}}</button>
      </ion-col>
    </ion-row>
</ion-grid>

And then:

editEntryValue(event: any, rowIndex: number, colIndex: number): void {
    console.log(`Row: ${rowIndex}`);
    console.log(`Col: ${colIndex}`);
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.