How to sort a list by multiple fields (and put it in a table)?

66 views
Skip to first unread message

Harry

unread,
Apr 15, 2022, 5:09:56 PM4/15/22
to TiddlyWiki
Hi,

I have a question about sort a list by multiple fields. I have a bunch of entries of persons' bios. Each bio entry has a set of fields associated, such as birth year, death year, birth date, tenure length etc.

I want to create a list with some of those persons and sort it by multiple fields, such as first by tenure length, if same tenure, then sort by birth year, then death year etc.

What I currently have is

<$list filter="[c_status[incumbent]sort[c_rank]]">
</$list>

This gives me a list that allows me to filter all incumbents but the list can only be sorted by rank. I want to add multiple fields (e.g. V1, V2, V3) behind the rank sort but it doesn't work. I'd appreciate it if any one could share their insights on this.

My second, maybe more unrealistic goal, is to transform the list to a table. Its visual would ideally look like this (https://en.wikipedia.org/wiki/Lists_of_state_leaders_by_age#Top_ten_since_1942), i.e. I can put each field value of one entry in different cells of the same row and the table will update itself

The code I'm currently using is

<$list filter="[c_status[incumbent]sort[c_rank]]">
<$link to=<<currentTiddler>>><$view field=birth_year/><$view field=title/><$view field=birth_month/><$view field=c_rank/></$link><br>

And the layout is a list of sorted entries with field values crudely attached at the beginning and the end of each line. Basically I wonder if I can separate those values into different cells.

Many thanks!

Mark S.

unread,
Apr 16, 2022, 10:00:01 AM4/16/22
to TiddlyWiki
To sort by multiple fields, you would use the sort filter run prefix.(SFRP) Inside the SFRP, you would use a filter perhaps like:

```
:sort:string:caseinsensitive[[c_rank]addsuffix[tenure]addsuffix[birth_year]]
```

which would sort by rank, tenure, and birth year. You might need to zero-pad your fields.

To create the table, the easiest way is to use standard HTML notation. 

Harry Reid

unread,
Apr 16, 2022, 4:56:20 PM4/16/22
to tiddl...@googlegroups.com
Hi Mark,

Thanks for the help! I tried to copy your code, but it gives a syntax error notice. All my fields used for sorting are numerical values, do I still need to treat them as string in the code? (e.g. 1960.02 for birth_year, 50 for rank)

What I have now is

```
<$list filter="[c_status[incumbent]:sort:number[[rank]addsuffix[birth_year]]]">
<$link to=<<currentTiddler>>><$view field=birth_year/><$view field=title/><$view field=rank/></$link><br>
</$list>
````

or
```
<$list filter="[c_status[incumbent]:sort:string:caseinsensitive[[rank]addsuffix[birth_year]]">
<$link to=<<currentTiddler>>><$view field=birth_year/><$view field=title/><$view field=rank/></$link><br>
</$list>
```

Neither code seems to work and I'm having some difficulty in reading through the SFRP document. Would anyone mind helping me to look more into this? Many thanks!

'Mark S.' via TiddlyWiki <tiddl...@googlegroups.com> 于2022年4月16日周六 10:00写道:
--
You received this message because you are subscribed to a topic in the Google Groups "TiddlyWiki" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/tiddlywiki/3DjVJRjEvxU/unsubscribe.
To unsubscribe from this group and all its topics, send an email to tiddlywiki+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/tiddlywiki/5595838a-ac78-4702-a6ec-92222a8d4bcbn%40googlegroups.com.

Mark S.

unread,
Apr 16, 2022, 5:38:48 PM4/16/22
to TiddlyWiki
I typed too quickly. It is hard to help without access to the data in use. However, this worked in my tests:

```
<$list filter="[c_status[incumbent]]:sort:string:caseinsensitive[{!!rank}addsuffix{!!birth_year}]">

<$link to=<<currentTiddler>>> <$view field=birth_year/> <$view field=title/> <$view field=rank/></$link><br>
</$list>

```

Note the use of {!!rank} to get the rank value.

You will likely get even more answers if you use https://talk.tiddlywiki.org/ , which is now the primary forum for TiddlyWiki.

HTH
Reply all
Reply to author
Forward
0 new messages