Kinetic Dashboard Week Navigator

Hello!!

I was working on a custom dashboard in App Studio that uses a week navigator and had an issue that stumped me for a bit. So I thought I’d post the fix for anyone else who runs into it, or interested in building one! (And for me to look back at when needed :sweat_smile:)

This is what my week navigator looks like:

It uses three variables I store in TransView: WeeksOut, toSearch, and fromSearch. I have toSearch and fromSearch initialize to the start and end of the current week:

(Note: Thank you to Getting Yesterday's Date in Date Format in Application Studio - #8 by dcamlin for helping me out with this! :slight_smile: )

I use the WeeksOut variable to keep track of which week the user is looking at in relation to the current week (Ex: WeeksOut = 2 means 2 weeks in the future, WeeksOut = -2 means 2 weeks in the past). I initialize this value to be 0 since it starts at the current week.

How the buttons work:

  • If the user clicks on the ‘Previous Week’ button, WeeksOut is decremented by 1
  • If the user clicks on the ‘Next Week’ button, WeeksOut is incremented by 1
  • fromSearch is updated to the first day of the according week. I do this by using this expression:
(new Date(new Date(new Date().getFullYear(), new Date().getMonth(), new Date().getDate() - new Date().getDay()+7*{TransView.WeeksOut}))).toLocaleDateString("en-US")
  • toSearch is updated to the last day of the according week. I do this by using this expression:
(new Date(new Date(new Date().getFullYear(), new Date().getMonth(), new Date().getDate() - new Date().getDay()+7*{TransView.WeeksOut}+6))).toLocaleDateString("en-US")

(Note: These expressions are mostly built from this post Constant.Today - 1 year ? How - #8 by hmwillett :slight_smile: )

My main issue for these was that I wasn’t including “en-US” in toLocaleDateString. The formatting of the date from the buttons was not the same format as the date from the Constants, which was causing some weird behavior with which dates would be included when I was using fromSearch and toSearch as filters for my BAQs.

I’m not sure if this is an issue for those located in the US. And it’s probably obvious, but making sure your dates are formatted correctly is a good thing to check when troubleshooting date filters. :sweat_smile:

Happy Dashboarding! :partying_face:

Version: 2024.1

3 Likes