Sorting Events

How it Works

For events that are drawn on the same day on the calendar, DayBack employs a default sort that is roughly in chronological order. The default sort in DayBack renders all-day events first—for multi-day events, it starts with those with the longest duration. Then, it shows timed events, starting with the earliest.

Overriding the Sort for Similar Items: Tie-breaker

If the default sort criteria for two events are the same, you can add a tie-breaking sort of your own. Events with the same default criteria would be two all-day events with the same start date, or two multi-day events with the same duration, for example.

To add a tie-breaker sort, create an Event Action in the relevant calendar with a "Before Event Rendered" trigger and "Prevent Default Action" set 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, thus controlling if emtpy values first or last.

Note that in FileMaker you can do this with a FileMaker script instead.

Overriding the Default Sort

If you want to override the calendar's default sort, instead of just adding a tie-breaker, you can do that with the function below. You may do this if you want to sort your projects by "due date" instead of start date on horizon view, for example.

Create an an Event Action in the relevant calendar with a "Before Event Rendered" trigger and "Prevent Default Action" set to no. The text of your action will be:

const view = seedcodeCalendar.get('view');
if (view.name === 'basicHorizon') {
    dbk.setEventSortOverride(event, event['dbk-additionalField-03'])
}

The view name is used to limit this sort to a specific view, but you can dispense with that and solely use the third line of the function if you want it to run on every view. You'll find a list of view names in DayBack here.

As in the tie-breaker sort, replace "dbk-additionalField-03" with the ID of the custom field you' d like to sort by.

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 are getting unexpected results, it could be due to the under-the-hood formatting of your date field. Ideally, the date is stored YYYY-MM-DD, but other formats could case issues—like all the events in the same month sorting together regardless of which year they are in.

To correct this, you can wrap your date field in a moment function like this:

dbk.setEventSortOverride(event, moment(event['dbk-additionalField-03']).valueOf())