Updated: Mar 25, 2021
When publishing something like a directory, it's often desirable to insert single-letter subheadings to separate the entries into groups with a single-letter heading.
This is easy to achieve with CatBase.
Download our free script "FirstLetter" from the Downloads page (in the Freebies section).
Install the script in your CatBase database:
Go to the Admin main tab.
Expand the Database Setup topic on the left of the window.
Select the table that you want to apply the script to.
Select the checkbox Run a script when a record is saved (underneath the list of fields).
Click the View/Modify Script button next to that checkbox.
Click Import a Script.
Locate the FirstLetter script and double-click it to select it.
Click the Save button. DO NOT attempt to modify the script! You'll break it!
With the table still selected, click the New Field button.
Enter the field name First Letter. It must be spelled exactly like that, although it isn't case-sensitive.
Select the Indexed checkbox.
Click the Save button.
Now whenever a record in that table is saved - whether it's a new or modified record - the first letter of the Key Field will be copied into the First Letter field.
Update your existing data:
Go to the table's main tab (where you see the list of records for that table).
Click the Show All button.
Click the Search & Replace button.
Set up the Search & Replace dialog like this:
NOTE! Make sure you enter something into the Change To: text box. We've used an "A" here - it doesn't matter, because the script will update it as appropriate for each record.
Click OK, then click Yes in the Confirm dialog.
All the records will be updated.
Update your Publishing Stylesheet:
Open the Publishing Stylesheet that you want to apply the single letter subheadings to (or create a new one).
Add a new Paragraph and make sure it is the first Paragraph in the list (click and drag it into position if it isn't)
Name it something creative such as "Letter subheading" and choose the Paragraph Style that you want these subheadings to be set in, then Save that Paragraph.
Add an Element to the new Paragraph.
Select the field: First Letter for that Element.
Go to the Preferences tab in the Element window.
In the Options area, select the checkbox labelled Unique Group Entry. This tells CatBase that you only want to publish this Element ONCE for each group.
Also select the first checkbox, Omit Paragraph if this Element is blank.
Save the Element.
With the Publishing Stylesheet still open, go to the Preferences tab.
You need to modify the existing Sort Order, or create a new one. You must have the First Letter field as the first item in the sort list. (For more info about Sort Formats, see the Sort Editor tutorial.)
You're done! When you publish your data using that Publishing Stylesheet, it will be sorted first by the First Letter field and then by whatever other fields you've selected (probably the Key Field).