Hello,
I have 2 buttons (next and previous) and a datepicker control.
The datepicker is defaulted to today.
I want te be able to jump to the datepickers next day by clicking next and vice versa.
How do I do this?
Solved! Go to Solution.
You can use a global variable to store the date that is bound to the Default property in the date picker, and in the prev/next buttons you'd decrement/increment the variable value.
In the app's OnStart property (you can find it on the first screen of your app), you'd need to initialize that value:
<first screen>.OnStart: Set(defaultDate, Today())
Now you can add the two buttons (prev/next) and set their properties to update the value of that property:
Button1.Text: "Previous day" Button1.OnSelect: Set(defaultDate, DateAdd(defaultDate, -1, Days)) Button2.Text: "Next day" Button2.Text: Set(defaultDate, DateAdd(defaultDate, 1, Days))
In the date picker, you then set its Default property to the "defaultDate" variable, so that when that property is changed (by clicking the previous/next buttons), then the date displayed in the picker will be changed as well.
DatePicker1.DefaultDate: defaultDate
The last thing you need to do is to update the "defaultDate" variable when the user selects a new date in the picker's calendar (so that the variable reflects what the date picker is showing, and incrementing / decrementing the date will produce the correct result):
DatePicker1.OnChange: Set(defaultDate, DatePicker1.SelectedDate)
Hope this helps!
You can use a global variable to store the date that is bound to the Default property in the date picker, and in the prev/next buttons you'd decrement/increment the variable value.
In the app's OnStart property (you can find it on the first screen of your app), you'd need to initialize that value:
<first screen>.OnStart: Set(defaultDate, Today())
Now you can add the two buttons (prev/next) and set their properties to update the value of that property:
Button1.Text: "Previous day" Button1.OnSelect: Set(defaultDate, DateAdd(defaultDate, -1, Days)) Button2.Text: "Next day" Button2.Text: Set(defaultDate, DateAdd(defaultDate, 1, Days))
In the date picker, you then set its Default property to the "defaultDate" variable, so that when that property is changed (by clicking the previous/next buttons), then the date displayed in the picker will be changed as well.
DatePicker1.DefaultDate: defaultDate
The last thing you need to do is to update the "defaultDate" variable when the user selects a new date in the picker's calendar (so that the variable reflects what the date picker is showing, and incrementing / decrementing the date will produce the correct result):
DatePicker1.OnChange: Set(defaultDate, DatePicker1.SelectedDate)
Hope this helps!
Works like a charm, it was a bit buggy at first but a clean restart fixed all settings!
Thanks a lot for the quick and helpful response!
Stay up tp date on the latest blogs and activities in the community News & Announcements.
Dive into the Power Platform stack with hands-on sessions and labs, virtually delivered to you by experts and community leaders.
User | Count |
---|---|
201 | |
176 | |
61 | |
32 | |
30 |
User | Count |
---|---|
307 | |
263 | |
105 | |
79 | |
56 |