I ended up going back to the drawing board for this idea, and while it might be a little bit hack-y, I think it turned out fairly well.
In Ignition 7.8, which was one of the tags for this topic, the date range and expression functions are a little bit lacking for what I wanted to try to do.
Essentially I created a date range of my own using @dkhayes117 recommendation, but instead of using expression bindings which lacked the required functions for this purpose, I used scripting and other components.
An example of the GUI:
Effectively, each button has a fair bit of code which I’ll share here if anyone is interested.
Confirm Worker Button:
# create a dataset based on the selected user
# declare the database we'll use
db = 'database'
# create a reference to the date range label that we will be treating as our date range object.
date_range = event.source.parent.getComponent('Date Range')
# start by getting default start and stop dates
start_date = system.date.midnight(system.date.addDays(system.date.now(), -(system.date.getDayOfWeek(system.date.now()) -2)))
end_date = system.date.midnight(system.date.addDays(start_date, 6))
# assign the dates back to the date_range's custom property
date_range.start_date = start_date
date_range.end_date = end_date
# from there create a query and form the dataset
emp_id = event.source.parent.getComponent('Employee Select').selectedStringValue
user_query = 'select * FROM time_clock where date_time >= ? and date_time <= ? and emp_id = ? order by date_time asc'
user_values = [start_date, end_date, emp_id]
user_data = system.db.runPrepQuery(user_query, user_values, db)
user_dataset = system.dataset.toDataSet(user_data)
# populate the table from the dataset that has been created
event.source.parent.getComponent('Management Table').data = user_dataset
# format the dates to be readable in the application
readable_start_date = system.date.format(start_date, date_range.date_format)
readable_end_date = system.date.format(end_date, date_range.date_format)
# enable visibility of the date components
event.source.parent.getComponent('Date Range').visible = True
event.source.parent.getComponent('Date Range').text = str(readable_start_date) + ' - ' + str(readable_end_date)
event.source.parent.getComponent('Date Range Label').visible = True
event.source.parent.getComponent('Forward').visible = True
event.source.parent.getComponent('Backward').visible = True
Back Button:
# button used to navigate backwards through the date range
# declare the db that will be used
db = 'database'
# declare the date range object, (it's a label with custom properties)
date_range = event.source.parent.getComponent('Date Range')
# declare the date format that will be used (modified by changing the
# date_range label's custom property 'date_format'
date_format = date_range.date_format
# take the date_range's existing date properties, adjust them to be a week earlier
start_date = system.date.addDays(date_range.start_date, -7)
end_date = system.date.addDays(date_range.end_date, -7)
# assign the dates back to the date_range's custom property
date_range.start_date = start_date
date_range.end_date = end_date
# recreate the dataset with the new information
emp_id = event.source.parent.getComponent('Employee Select').selectedStringValue
user_query = 'select * FROM time_clock where date_time >= ? and date_time <= ? and emp_id = ? order by date_time asc'
user_values = [start_date, end_date, emp_id]
user_data = system.db.runPrepQuery(user_query, user_values, db)
user_dataset = system.dataset.toDataSet(user_data)
# populate the table from the dataset that has been created
event.source.parent.getComponent('Management Table').data = user_dataset
# update the date_range label with the changed date
readable_start_date = system.date.format(start_date, date_format)
readable_end_date = system.date.format(end_date, date_format)
# change the appearance of the date range
date_range.text = str(readable_start_date) + ' - ' + str(readable_end_date)
Forward button is the same as this code, but adding 7 days instead of subtracting them, naturally.
The one thing that is important though, is that your date_range label must have the date properties so that they can be adjusted and referenced.
Thanks very much to @dkhayes117 again because without their idea for the expression I probably wouldn’t have been able to get this far.