Sorting Events
How it Works
For events scheduled on the same day, DayBack employs a default sorting mechanism that arranges them in rough chronological order. The default sort order prioritizes all-day events first. For multi-day events, it starts with those with the longest duration. Timed events are then shown, beginning with the earliest.
Note: In FileMaker, you can achieve this with a FileMaker script instead.
Overriding the Sort for Similar Items: Tie-breaker
If two events have the same default sort criteria, you can add a tie-breaking sort of your own. For instance, this might be necessary for two all-day events with the same start date or two multi-day events with the same duration.
To add a tie-breaker sort, create an Event Action in the relevant calendar with a "Before Event Rendered" trigger and set "Prevent Default Action" to no. The text of your action will be:
dbk.setEventSortPriority(event, event['dbk-additionalField-03'])
Replace dbk-additionalField-03
with the ID of the custom field you'd like to sort by. Learn more about custom fields and how to find their IDs for custom actions here: Custom Fields.
You likely want to make your custom field a formula field or a calculation field so that you can substitute some default value for when the sort field would otherwise be empty. This allows you to control if empty values show first or last.
Overriding the Default Sort
To override the default sort order of the calendar entirely (instead of just adding a tie-breaker), you can use the following function. For example, you might want to sort your projects by "due date" instead of the start date in the horizon view.
Create an Event Action in the relevant calendar with a "Before Event Rendered" trigger and set "Prevent Default Action" to no. Use the following code for your action:
const view = seedcodeCalendar.get('view'); if (view.name === 'basicHorizon') { dbk.setEventSortOverride(event, event['dbk-additionalField-03']) }
In this function, the view name limits the sort to a specific view (e.g., "basicHorizon"). You can remove this condition if you want the sort to apply to all views by only using the third line of the function. A list of view names in DayBack can be found here.
As with the tie-breaker sort, replace dbk-additionalField-03
with the ID of the custom field you'd like to use for sorting.
Sorting By Dates
You can use any field type for your sort-by field: text, number, date, etc. If you're using a date field and encountering unexpected results, it might be due to the underlying format of your date field. Ideally, dates should be stored in the YYYY-MM-DD
format. Other formats might cause issues, such as events from the same month being grouped together regardless of the year.
To correct this, you can wrap your date field in a moment function like this:
dbk.setEventSortOverride(event, moment(event['dbk-additionalField-03']).valueOf())
Using the moment function ensures that the date is correctly formatted and sorted accurately.