by mjhanna » Wed Feb 05, 2014 2:45 pm
I am not Dave, but in the Desktop HanDBase manual under the Sort Database Screen is the warning: "Certain field types are not sortable as they do not contain any sortable data. They are Link Field, Heading Field, Image Field, and the External Field." I have found this also applies to Relationship fields.
For Link and Relationship fields I believe this is because what is actually stored is the pointer to the linked record. For any actions like sorting and filtering the trick is to define an extra field in the retrieving database whose value is based on the related source database value, but which is a type of field that can be used for sort or filter. This requires defining at least one extra field in the retrieving database, and possible an extra field in the source database. What fields need to be defined depend on the nature of the data being retrieved: number, text, or date/time.
Relationship Field retrieves a number
This only requires one new field in the retrieving database. Define a Calculated field which performs a "do nothing" mathematical calculation on the Relationship field value with the appropriate numeric Output. Two obvious example calculations are simply multiply by one, or simply add a zero. Now define your sort or filter on this Calculated field instead of the Relationship field. Usually you would display the retrieved numeric Relationship field value but keep hidden the Calculated field output.
Relationship Field retrieves text
This only requires one new field in the retrieving database. Define a Conditional field which performs a "do nothing" condition on the text from the Relationship field value. An example condition is:
IF FIELD (Relationship field) IS EQUAL TO
FIELD (Relationship field)
OUTPUT IS (Relationship field)
ELSE OUTPUT IS (Relationship field)
Now define your sort or filter on this Conditional field instead of the Relationship field. Usually you would display the text Relationship field value but keep hidden the Conditional field output.
Relationship Field retrieves date or time
These are more complex, and require one extra field in both the source database and the retrieving database. First, in the source database define a Calculated field which performs a "do nothing" mathematical calculation as described above on the date or time field value with the output as Integer. Usually you would keep this field hidden. In the retrieving database define a Relationship field which retrieves this calculated Integer field value, not the actual date/time field. Finally in the retrieving database define a Calculated field which performs a "do nothing" mathematical calculation on the hidden Relationship field Integer value, but specify its Output as the appropriate date or time. Now you can define your sort or filter on this Calculated field. Usually you would keep hidden the output of the integer Relationship field but display the calculated date or time field.
As a further note, since this uses calculations based on Relationship fields, you will want to be sure to have the option "Recalculate on Relationship Lookup" turned on. I "believe" this option currently is only available on the iOS and Android versions, and not the Desktop. You also want to have the hidden field come in field order after the Relationship field since it depends upon that field.
Hope this gives you ideas,
Michael
(Only a user and not affiliated with DDH Software, but working with computer databases for over fifty years.)