Sorting with Default Value

160 views
Skip to first unread message

Jamie Choi

unread,
Mar 28, 2019, 5:04:37 AM3/28/19
to tiddl...@googlegroups.com
It is possible to sort with a field like this:

<div class="tc-table-of-contents">
<<toc-selective-expandable "content" "sort[toc-order]">>
</div>

But is there any method to give a default value to toc-order inside the sort field, e.g. to give default value of 0 to posts without the field toc-order?

S. S.

unread,
Mar 28, 2019, 7:04:57 AM3/28/19
to tiddl...@googlegroups.com
Jamie,

I haven't understood what you mean by "sort[toc-order]"

However I will try and give you some kind of answer that may or may not be what you want.

In the tiddler that holds the toc-selective-expandable macro, if you have a field, say call it list-order, and that field is used as a ListField, and it contains a list of all your tiddlers tagged content in the order you desire for them to appear - then the below should list all your tiddlers in the same order that you have them in the list-order field.

<div class="tc-table-of-contents">
<
<toc-selective-expandable "content" "enlist{!!list-order}">>
</div>

Hope it works!

Edited post to correct code: changed Variable to content

S. S.

unread,
Mar 28, 2019, 7:25:49 AM3/28/19
to TiddlyWiki
Ha! Apologies!

You just need to make a field called list and put in the tiddler order there!

Quoting from the documentation tiddler: Table-of-Contents Macros

At each level, the tiddlers can be ordered by means of the list field of the parent tag tiddler.

Let us know if you get stuck.

Regards.

Eric Shulman

unread,
Mar 28, 2019, 9:44:45 AM3/28/19
to TiddlyWiki
On Thursday, March 28, 2019 at 4:04:57 AM UTC-7, S. S. wrote:
I haven't understood what you mean by "sort[toc-order]"

The second parameter of the toc-selective-expandable macro uses filter syntax to apply a sort order to the set of tiddler being displayed at each level of the tree.

"sort[toc-order]" means "sort the list of tiddlers by the value in the "toc-order" field of each tiddler.

Thus, if each tiddler has a "toc-order" field containing a number then when those tiddlers are shown in the tree, they will be sorted based on those numbers.

The problem is that tiddlers where the "toc-order" field is missing (or blank or non-numeric) are sorted AFTER the tiddlers that do have a defined value for "toc-order", and Jamie was asking how to get these un-numbered tiddlers to default to being placed BEFORE the sorted ones.

Note: for his purposes, Jamie should be using "nsort[toc-order]", which does a NUMERIC sort, rather than an ALPHABETIC sort.  With alpha sorting, a sequence of numbers like "1 2 3 10 11 21 22" will be sorted as "1 10 11 2 21 22 3".

However, just like the sort[...] filter, nsort[...] also puts missing/blank/non-numeric values at the end of the list.  So, although nsort[...] is correct, it still doesn't solve the original problem.

-e

S. S.

unread,
Mar 28, 2019, 10:13:23 AM3/28/19
to TiddlyWiki
Eric,

Thanks for that explanation! I had not absorbed that concept properly.

A small test shows that when using sort[toc-order] or nsort[toc-order] - the empty/non-existent toc-order values go to the top of the list, followed by those that have a value of 0, then the other numbers below.

So depending on what one wants, doing a !nsort[toc-order] might accomplish what is needed.

Otherwise, perhaps use the Tiddler Commander Plugin to add the field and the wanted values to all the tiddlers without that field quickly.

Regards

Jamie Choi

unread,
Mar 29, 2019, 7:49:01 AM3/29/19
to TiddlyWiki
Thank you for your reply. "nsort[toc-order]" is indeed the way to go. I will show an example here:
  • Post "Home" with toc-order = -1
  • Post "Book" with no toc-order
  • Post "Events" with no toc-order
  • Post "Footer" with toc-order = 1
Using "sort[title]nsort[toc-order]", the list is:
  • Home
  • Book
  • Events
  • Footer
It seems that it does have an default value of 0 if I use nsort instead of sort, which is what I should be doing. Thanks for everyone's help here!

Mohammad

unread,
Mar 29, 2019, 11:58:27 AM3/29/19
to TiddlyWiki
Added to TW-Scripts

Mohammad

unread,
Mar 29, 2019, 11:58:53 AM3/29/19
to TiddlyWiki
Added to TW-Scripts
Reply all
Reply to author
Forward
0 new messages