How to sort a group of tiddlers based on Field value

676 views
Skip to first unread message

Shash

unread,
Sep 20, 2015, 12:32:12 PM9/20/15
to TiddlyWiki
Hi,

I have a group of tiddlers and I want to sort them based on a field value which is numeric. 

I tried using sort and nsort but I think I am missing something in there. Requesting help for this.

Thanks!
Shash

Tobias Beer

unread,
Sep 20, 2015, 1:26:10 PM9/20/15
to TiddlyWiki
Hi Shash,

Any chance you can upload a minimal testcase?

Best wishes,

— tb

Shash

unread,
Sep 20, 2015, 2:20:33 PM9/20/15
to TiddlyWiki
Hi,

Let us say, I have around 10 tiddlers for each individual topic of a chapter. Now instead of listing using makedoc plugin (as suggested in your makedoc plugin) I want to add a field named 'topic_number' where I can add a number and later list it in the chapter tiddler. I tried using your makedoc plugin but (sorry to say), it did not suffice my needs. Any suggestions is greatly appreciated.

Thanks!
Shash

Tobias Beer

unread,
Sep 20, 2015, 2:43:37 PM9/20/15
to tiddl...@googlegroups.com
Hi Shash,

Haven't looked at "makedoc" in forever. ^_^
I believe there is no way for makedoc to have a chapter count right now.
I once proposed iterator variables but they have unfortunately been removed again,
because they would not auto-refresh when the order of the tiddlers
composing the document would have been changed while looking at the document. :-(
...and essentially because the story river itself (where the tiddlers are displayed)
also is rendered by the same list-widget that was to provide iterator variables.

~

Is it safe to assume that — instead of numbering — 
you rather want to define an order
and have any numbers calculated automatically?

So the numbers really are just
so that the outline is in the right order?

What if you needed to insert something somewhere?
Would you have / want to touch a bunch of numbers?

~

Jeremy has been working on something called the "text-slicer"

http://tiddlywiki.com/prerelease/editions/text-slicer

...and — if I understand right — also on something
that does the opposite of that.

Not sure if that will go in the direction you desire
...and when.

Best wishes,

— tb

Hegart Dmishiv

unread,
Sep 20, 2015, 8:14:56 PM9/20/15
to tiddl...@googlegroups.com
I don't know if this is helpful at all, I'm still very new to TiddlyWiki myself, but there is a tiddler field called list, which can be used to alter the sort order of tiddlers tagged with the title of the current tiddler. For example, to use your use-case, I have a chapter of my book, with the title of "Chapter 3", then sub-headings under those are tagged with "Chapter 3" but the titles of these sub-heading tiddlers should not be alphabetically sorted. To sort them in the order you want, simply add the list field to each of the sub-heading tiddlers and give them alphabetical values in the order of preference. Again, I may be barking up the wrong tree, but I've done this in my own TW wiki and I know it works for me. See Tagging and ListField and Order of Tagged Tiddlers for details.
150921_sorted.png

Hegart Dmishiv

unread,
Sep 20, 2015, 9:44:37 PM9/20/15
to tiddl...@googlegroups.com
Reading back through ListField and Order of Tagged Tiddlers it seems that I'm not using them in the way they were intended. My method works, but may have unintended side effects. To use the list tiddler field according to the official documentation, as far as I understand it, you shouldn't need to apply the list field to each sub-heading tiddler. Instead, you're supposed to list the titles (see Title List) of each sub-heading tiddler in the list field of the main heading tiddler (eg. the "Chapter 3" tiddler in my example above), in the order you want the titles of the sub-headings to appear.

Personally I think my way is much easier to set up initially, especially if you don't know / haven't yet created the titles of the sub-heading tiddlers. One unintended side effect of my method is that you'd need to revisit each sub-heading tiddler to change the sort order. Using the method in the official docs, you only need to revisit the main heading tiddler to change the sort order, or to add a new sub-heading tiddler in the middle of your required sort order. Even so, I think this field should be renamed to sort or order or even sort-order rather than list. However, this field is apparently used for other purposes as well, according to ListField.

Hegart Dmishiv

unread,
Sep 20, 2015, 10:44:01 PM9/20/15
to tiddl...@googlegroups.com
Further testing has revealed that my method does NOT in fact work, and it was just coincidence that they were appearing in the order that I had created them in, rather than in alphabetical order. The correct way to use the list field is as documented in the TW official docs, by adding it to the parent tiddler, not the child tiddlers. (Yes, that means I need to go back and redo my own use of list.)

Also, from looking at the example code in Example Table of Contents: Sorted Expandable it would seem that you could generate a sorted expandable list based on any field you like, by modifying the sort[] parameter of <<toc-expandable>>

NOTE: A list generated using the sort[] parameter of <<toc-expandable>> as in the Sorted Expandable code example, will not affect the underlying sort order of the child tiddlers otherwise, such as when they are displayed in the drop-down from the tag pill, which is, in fact, modified by the list tiddler field. This means you can generate an expandable list sorted by whatever field you like (as I mentioned previously) without even needing to use the list tiddler field at all, to simplify things. Hope that helps.
150921_sorted2.png

Tobias Beer

unread,
Sep 21, 2015, 4:22:50 AM9/21/15
to TiddlyWiki
Hi Hegart,
 
I think this field should be renamed to sort or order or even sort-order rather than list.

At this point, if only for backwards-compatibility,
there is no renaming that field.

I can see how the name "list" field
is not exactly self-explanatory at first.

~

Give yourself some time to digest the TW ecosystem,
there is a lot to learn.
You can trust the core design
to have been carefully crafted.

Starting that journey with TW,
focus on understanding first how things work,
and perhaps why things work the way they work.

~

I hope by now you also see how
defining numbers the way you thought
would not have been easier or better,
if only for it having constrained
any tiddler to only having one number
rather than possibly appear in a number of list fields.

If you ever needed more than one list field,
there is no stopping you from using any other custom field
as if being the list field ...with the appropriate filter.

~

Actually, thinking about all this,
I believe there is a bit of a shortcomming right now in that the fields
list-before and list-after should in fact work like list-fields,
rather than only declare a single tiddler
compared to which the current one is to be sorted
before or after.

After all, as I just said,
any tiddler can appear in a number of list fields.


Best wishes,

— tb
Reply all
Reply to author
Forward
0 new messages