I'm facing an issue with a table that contains buttons in one of the columns. Whenever I click on a button, all buttons in the column get enabled instead of just the clicked one. Can someone help me find a solution to this problem?
I've attempted passing the line number as a parameter but haven't been successful so far.
HTML
<div *dxTemplate="let data of 'cellTemplate'">
<button type="button" data-toggle="dropdown" class="btn ClassPlay">
<img src="./assets/play.svg" *ngIf="currentState=='pause'">
<img src="./assets/playV.svg" *ngIf="currentState=='start'">
</button>
<div class="dropdown-menu">
<a class="dropdown-item" *ngIf="currentState=='pause'" routerLinkActive="active"
(click)="currentState='start'; startTimer(data, data.rowIndex)">Start</a>
<a class="dropdown-item" *ngIf="currentState=='start'" routerLinkActive="active"
(click)="currentState='pause'; pauseTimer((data, data.rowIndex)">Pause</a>
</div>
<span class="timer">{{display}}</span>
</div>
Component.ts
startTimer(data,row) {
this.interval = setInterval(() => {
if (this.time === 0) {
this.time++;
} else {
this.time++;
}
this.display=this.transform( this.time)
}, 1000);
}
transform(value: number): string {
var sec_num = value;
var hours = Math.floor(sec_num / 3600);
var minutes = Math.floor((sec_num - (hours * 3600)) / 60);
var seconds = sec_num - (hours * 3600) - (minutes * 60);
return hours+':'+minutes+':'+seconds;
}
pauseTimer(data,row) {
clearInterval(this.interval);
}
What I Tried
<button type="button" data-toggle="dropdown" class="btn ClassPlay">
<img src="./assets/play.svg" *ngIf="currentState=='pause'">
<img src="./assets/playV.svg" *ngIf="currentState=='start' && currentRowIndex === data.rowIndex">
</button>
<div class="dropdown-menu">
<a class="dropdown-item" *ngIf="currentState=='pause'" routerLinkActive="active"
(click)="currentState='start'; startTimer(data)">Start</a>
<a class="dropdown-item" *ngIf="currentState=='start' && currentRowIndex === data.rowIndex" routerLinkActive="active"
(click)="currentState='pause'; pauseTimer(data)">Pause</a>
</div>
<span class="timer">{{currentRowIndex === data.rowIndex ? display : ''}}</span>
startTimer(data) {
this.currentRowIndex = data.rowIndex;
this.interval = setInterval(() => {
if (this.time === 0) {
this.time++;
} else {
this.time++;
}
this.display=this.transform( this.time)
}, 1000);
}
transform(value: number): string {
var sec_num = value;
var hours = Math.floor(sec_num / 3600);
var minutes = Math.floor((sec_num - (hours * 3600)) / 60);
var seconds = sec_num - (hours * 3600) - (minutes * 60);
return hours+':'+minutes+':'+seconds;
}
pauseTimer(data) {
this.currentRowIndex = data.rowIndex;
clearInterval(this.interval);
}
The challenge now is when I click the start button, all buttons on other lines disappear momentarily and only reappear on the next line. The timer also behaves incorrectly, accumulating time across lines rather than starting anew on each click.