I have a grid containing data. I utilize the loadGrid() function to preload data or conditions before the grid finishes loading.
When the active state is set to 1, my intention is to initiate a timer by calculating the difference between the current date and the object's date (date.key.date) on this line.
In other words, if the time gap is 30 minutes... I want the timer to begin counting from 00:30:00...
The issue I'm facing is that the timer isn't starting, and I'm unable to pass its value to the fetchDisplay() service function.
Could someone offer assistance?
Code:
data = [
{
id: 1,
idUser: 1,
name: "Name1",
active: 1,
date: "2020-02-01T20:00:00",
},
{
id: 2,
idUser: 2,
name: "Name2",
active: 0,
date: "2020-02-01T20:00:00",
},
{
id: 3,
idUser: 3,
name: "Name3",
active: 0,
date: "2020-02-01T20:00:00",
}
];
loadGrid(event) {
if (event != null) {
if (event.rowType !== "header") {
if (event.data.decorrer === 1){
this.interval = setInterval(() => {
this.display = +this.datePipe.transform(Date.now(), 'yyyyMMddHHmmss') - +this.datePipe.transform(event.data.date, 'yyyyMMddHHmmss');
// this.taskService.fetchDisplay() = this.display;
return this.display;
}, 1000);
}
}
}
}
startTimer(data) {
alert("start timer");
this.currentRowIndex = data.id;
let self = this;
self.taskService.startTimer(data);
self.currentState = self.taskService.getCurrentState();
}
pauseTimer(data) {
alert("pause timer");
let self = this;
this.currentRowIndex = data.id;
self.taskService.pauseTimer(data);
self.currentState = self.taskService.getCurrentState();
}