Tinderbox Forum

Ideas on how to sort notes

I’m new to Tinderbox, about a week or two in. I’ve been going through the forum and aTBref and various video tutorials. Many, many thanks to all those who have contributed answers and tutorials.

I’m trying to sort my notes alphabetically, but as you can see from the screenshot below, the numbers aren’t in the proper order. If I understand correctly, this is expected behaviour. What I’m wondering is whether there’s a straightforward way to get the expected order where ARC r. 10.51 and ARC r. 12.40 would be below ARC 9.16. I should clarify that not every note in this container starts with “ARC r.”

The quick-and-dirty is to extract (from each Note’s $Name Attribute) the portion you’d like to sort along; create a User Attribute ($Sorter) and paste those specific values to it. Then Sort on $Sorter. You can automate this extract-and-paste-over process (to a degree) with action code.

I’ll add: The Outline View is a wonderful place; turn on Menu “View/Use Columns” and you can sort by any Attribute, all day. You can do the same in Attribute View - but with the added advantage that you can see your Notes sorted ACROSS Containers. Whee!

I’ll add further: Glancing at your example - I’d use action code to copy out sections of the Note Names. Create a $SectionNo User Attribute, and copy the “ARC r. xx.x” value to it.
One might consider an Agent that nests and sorts your Notes by $SectionNo, Outline-style; one you can view/edit quite flexibly in Outline View, say.

1 Like

The problem here is that string attributes like $Name sort lexicographically — strictly as a dictionary would sort. That’s predictable, but not always the way your library might sort.

Then again, your library and my library sort things differently. Sorting is remarkable tricky. You’ve got one example here. Another one is whether Britons typically known by their title are indexed by title or by common name; my college library made it a point of honor to choose the latter, but how is abc undergraduate to know?

One solution would be to normalize the chapter numbers, so you’d have 03.3 rather than 3.3. This could be done in a hidden attribute on which you sort, leaving there visibly name for display.

as @eastgate wrote - you want a numeric sort. A solution: add a new attribute $SortFld of type number to a prototype. Add this function to the Library of your hints container (“Built In Hints”):

function prepareSortFld(){
	var:string theOldValue;
	var:number theNumericValue;
	// retrieve the number from the $Name attribute
	theOldValue = $Name.extract(" ([0-9\.-]+)");
	// convert it to a number
	theNumericValue = theOldValue.toNumber;
	// use it in a new attribute of type number used to sort the entries
	$SortFld = theNumericValue;
}

Add prepareSortFld(); to the $Edict of your prototype. Assign the prototype to all your notes you like to sort. Now sort the container with your notes using $SortFld.

sortTest.tbx (114.7 KB)

2 Likes

Thank you so much for your responses @archurhh, @eastgate, and @webline!

Following @webline’s example, what I may need to do is extract both the section number and the name of the legislation into their own fields and then sort on the legislation name first then the section number. By just sorting by section number, I end up with something like this:

EAA s. 8 - Applying to Remove a Personal Representative
WSA s. 25 - Gifts to ex-spouse or former adult interdependent partner
EAA s. 37 - Personal Representatives Must Act Unanimously

Again, thank you all for the quick and useful feedback.