Got an easy one for you guys. I am creating a public dashboard of sorts and want the background color of a box to change based on the last update date for a given field in a dataset.
Essentially it would go
Data is New - Green
Data is 5 minutes old - yellow
Data is 10 minutes or older - red
No Data - Grey
I am a copy and paste coder and can’t quite find anything similar enough to execute on so any help would be appreciated.
Hi Vince,
The built-in Wix data _updatedDate field pertains to the whole record. This example uses a table, but hopefully you will get the idea of how to proceed with the dashboard that you are working with.
export function table1_rowSelect(event) {
let rowData = event.rowData;
let color = "";
wixData.get("Employees",rowData._id)
.then((result) => {
let now = new Date();
// 60k milliseconds in minute.
let timeElapsed = (now - result._updatedDate)/60000;
console.log(timeElapsed);
switch (true) {
case (timeElapsed < 5) :
color = "green";
break;
case (timeElapsed >= 5 && timeElapsed < 10) :
color = "yellow";
break;
default:
color = "red";
break;
}
$w("#box1").style.backgroundColor = color;
})
}
Sorry for the delay in response, had to edit this a touch but got it working. Thank you!